[libclc] 59510c4 - libclc: Fix rounding during type conversion

Tom Stellard via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 19 22:24:48 PDT 2021


Author: Daniel Stone
Date: 2021-08-19T22:24:19-07:00
New Revision: 59510c421208e178de63b3640787d02ad56deb37

URL: https://github.com/llvm/llvm-project/commit/59510c421208e178de63b3640787d02ad56deb37
DIFF: https://github.com/llvm/llvm-project/commit/59510c421208e178de63b3640787d02ad56deb37.diff

LOG: libclc: Fix rounding during type conversion

The rounding during type conversion uses multiple conversions, selecting
between them to try to discover if rounding occurred. This appears to
not have been tested, since it would generate code of the form:
    float convert_float_rtp(char x)
    {
      float r = convert_float(x);
      char y = convert_char(y);
      [...]
    }

which will access uninitialised data. The idea appears to have been to
have done a char -> float -> char roundtrip in order to discover the
rounding, so do this.

Discovered by inspection.

Signed-off-by: Daniel Stone <daniels at collabora.com>

Reviewed By: jvesely

Differential Revision: https://reviews.llvm.org/D81999

Added: 
    

Modified: 
    libclc/generic/lib/gen_convert.py

Removed: 
    


################################################################################
diff  --git a/libclc/generic/lib/gen_convert.py b/libclc/generic/lib/gen_convert.py
index 7e649faa7dfcb..469244047de96 100644
--- a/libclc/generic/lib/gen_convert.py
+++ b/libclc/generic/lib/gen_convert.py
@@ -355,7 +355,7 @@ def generate_float_conversion(src, dst, size, mode, sat):
     print("  return convert_{DST}{N}(x);".format(DST=dst, N=size))
   else:
     print("  {DST}{N} r = convert_{DST}{N}(x);".format(DST=dst, N=size))
-    print("  {SRC}{N} y = convert_{SRC}{N}(y);".format(SRC=src, N=size))
+    print("  {SRC}{N} y = convert_{SRC}{N}(r);".format(SRC=src, N=size))
     if mode == '_rtz':
       if src in int_types:
         print("  {USRC}{N} abs_x = abs(x);".format(USRC=unsigned_type[src], N=size))


        


More information about the cfe-commits mailing list