[compiler-rt] 8b1e81f - [builtins] Fix -Wshift-count-overflow warnings for targets with 16-bit int

Mikael Holmen via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 16 23:58:44 PDT 2023


Author: Mikael Holmen
Date: 2023-04-17T08:48:19+02:00
New Revision: 8b1e81f03c0413ce25081dc5cd6b9e00376e7ddb

URL: https://github.com/llvm/llvm-project/commit/8b1e81f03c0413ce25081dc5cd6b9e00376e7ddb
DIFF: https://github.com/llvm/llvm-project/commit/8b1e81f03c0413ce25081dc5cd6b9e00376e7ddb.diff

LOG: [builtins] Fix -Wshift-count-overflow warnings for targets with 16-bit int

Without this fix we got warnings like
 /repo/llvm/compiler-rt/lib/builtins/floattidf.c:67:29: warning: shift count >= width of type [-Wshift-count-overflow]
                 ((e + 1023) << 20) |              // exponent
                             ^  ~~
 1 warning generated.
when compiling for a target with 16-bit int.

In floatundisf.c the type of "e" was already changed to "si_int" in
4d41df6482, now we do the same in a couple of other files where "e" is
also left shifted 20/23 steps.

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

Added: 
    

Modified: 
    compiler-rt/lib/builtins/floattidf.c
    compiler-rt/lib/builtins/floattisf.c
    compiler-rt/lib/builtins/floatuntidf.c
    compiler-rt/lib/builtins/floatuntisf.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/builtins/floattidf.c b/compiler-rt/lib/builtins/floattidf.c
index 0a1c04bec82ea..7bfe87f53aa02 100644
--- a/compiler-rt/lib/builtins/floattidf.c
+++ b/compiler-rt/lib/builtins/floattidf.c
@@ -29,7 +29,7 @@ COMPILER_RT_ABI double __floattidf(ti_int a) {
   const ti_int s = a >> (N - 1);
   a = (a ^ s) - s;
   int sd = N - __clzti2(a); // number of significant digits
-  int e = sd - 1;           // exponent
+  si_int e = sd - 1;        // exponent
   if (sd > DBL_MANT_DIG) {
     // start:  0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
     //  finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR

diff  --git a/compiler-rt/lib/builtins/floattisf.c b/compiler-rt/lib/builtins/floattisf.c
index a8fcdbe14c073..717cb361f075a 100644
--- a/compiler-rt/lib/builtins/floattisf.c
+++ b/compiler-rt/lib/builtins/floattisf.c
@@ -28,7 +28,7 @@ COMPILER_RT_ABI float __floattisf(ti_int a) {
   const ti_int s = a >> (N - 1);
   a = (a ^ s) - s;
   int sd = N - __clzti2(a); // number of significant digits
-  int e = sd - 1;           // exponent
+  si_int e = sd - 1;        // exponent
   if (sd > FLT_MANT_DIG) {
     //  start:  0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
     // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR

diff  --git a/compiler-rt/lib/builtins/floatuntidf.c b/compiler-rt/lib/builtins/floatuntidf.c
index e69e65c1ace4e..4dfca8e493098 100644
--- a/compiler-rt/lib/builtins/floatuntidf.c
+++ b/compiler-rt/lib/builtins/floatuntidf.c
@@ -27,7 +27,7 @@ COMPILER_RT_ABI double __floatuntidf(tu_int a) {
     return 0.0;
   const unsigned N = sizeof(tu_int) * CHAR_BIT;
   int sd = N - __clzti2(a); // number of significant digits
-  int e = sd - 1;           // exponent
+  si_int e = sd - 1;        // exponent
   if (sd > DBL_MANT_DIG) {
     //  start:  0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
     //  finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR

diff  --git a/compiler-rt/lib/builtins/floatuntisf.c b/compiler-rt/lib/builtins/floatuntisf.c
index 9dec0ab5c58fc..a53659cd1fcac 100644
--- a/compiler-rt/lib/builtins/floatuntisf.c
+++ b/compiler-rt/lib/builtins/floatuntisf.c
@@ -26,7 +26,7 @@ COMPILER_RT_ABI float __floatuntisf(tu_int a) {
     return 0.0F;
   const unsigned N = sizeof(tu_int) * CHAR_BIT;
   int sd = N - __clzti2(a); // number of significant digits
-  int e = sd - 1;           // exponent
+  si_int e = sd - 1;        // exponent
   if (sd > FLT_MANT_DIG) {
     //  start:  0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
     //  finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR


        


More information about the llvm-commits mailing list