[flang-commits] [flang] 3d9bb03 - [flang] avoid GCC < 8 compiler failure after D80794

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Thu Jun 4 11:48:47 PDT 2020


Author: Valentin Clement
Date: 2020-06-04T14:48:39-04:00
New Revision: 3d9bb031d13c884122a5da456659e47dd52ec1f7

URL: https://github.com/llvm/llvm-project/commit/3d9bb031d13c884122a5da456659e47dd52ec1f7
DIFF: https://github.com/llvm/llvm-project/commit/3d9bb031d13c884122a5da456659e47dd52ec1f7.diff

LOG: [flang] avoid GCC < 8 compiler failure after D80794

Summary:
Patch D80794 remove the custom flags for release build for flang.
This leads to build failure with GCC < 8. This patch add upperbound check
in order to avoid the -Werror=array-bounds to trigger a build failure.

```
/home/4vn/versioning/llvm-project/flang/lib/Decimal/big-radix-floating-point.h:183:29: error: array subscript is above array bounds [-Werror=array-bounds]
           digit_[j] = digit_[j + remove];
                       ~~~~~~^
/home/4vn/versioning/llvm-project/flang/lib/Decimal/big-radix-floating-point.h:183:29: error: array subscript is above array bounds [-Werror=array-bounds]
           digit_[j] = digit_[j + remove];
                       ~~~~~~^
/home/4vn/versioning/llvm-project/flang/lib/Decimal/big-radix-floating-point.h:183:29: error: array subscript is above array bounds [-Werror=array-bounds]
           digit_[j] = digit_[j + remove];
                       ~~~~~~^
/home/4vn/versioning/llvm-project/flang/lib/Decimal/big-radix-floating-point.h:183:29: error: array subscript is above array bounds [-Werror=array-bounds]
           digit_[j] = digit_[j + remove];
                       ~~~~~~^
/home/4vn/versioning/llvm-project/flang/lib/Decimal/big-radix-floating-point.h:183:29: error: array subscript is above array bounds [-Werror=array-bounds]
           digit_[j] = digit_[j + remove];
```

```
/home/4vn/versioning/llvm-project/flang/include/flang/Evaluate/integer.h:809:28: error: array subscript is above array bounds [-Werror=array-bounds]
               xy += product[to];
                     ~~~~~~~^
/home/4vn/versioning/llvm-project/flang/include/flang/Evaluate/integer.h:810:22: error: array subscript is above array bounds [-Werror=array-bounds]
               product[to] = xy & partMask;
               ~~~~~~~^
/home/4vn/versioning/llvm-project/flang/include/flang/Evaluate/integer.h:809:28: error: array subscript is above array bounds [-Werror=array-bounds]
               xy += product[to];
                     ~~~~~~~^
```

Reviewers: DavidTruby, sscalpone, jdoerfert

Reviewed By: DavidTruby

Subscribers: llvm-commits

Tags: #llvm, #flang

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

Added: 
    

Modified: 
    flang/include/flang/Evaluate/integer.h
    flang/lib/Decimal/big-radix-floating-point.h

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Evaluate/integer.h b/flang/include/flang/Evaluate/integer.h
index f519c2e64148..ecefbc45b2cd 100644
--- a/flang/include/flang/Evaluate/integer.h
+++ b/flang/include/flang/Evaluate/integer.h
@@ -805,7 +805,9 @@ class Integer {
           if (Part ypart{y.LEPart(k)}) {
             BigPart xy{xpart};
             xy *= ypart;
-            for (int to{j + k}; xy != 0; ++to) {
+            // && to < (2 * parts) was added to avoid GCC < 8 build failure
+            // on -Werror=array-bounds
+            for (int to{ j + k }; xy != 0 && to < (2 * parts); ++to) {
               xy += product[to];
               product[to] = xy & partMask;
               xy >>= partBits;

diff  --git a/flang/lib/Decimal/big-radix-floating-point.h b/flang/lib/Decimal/big-radix-floating-point.h
index cc203e90bc91..67f0b46ab213 100644
--- a/flang/lib/Decimal/big-radix-floating-point.h
+++ b/flang/lib/Decimal/big-radix-floating-point.h
@@ -179,7 +179,10 @@ template <int PREC, int LOG10RADIX = 16> class BigRadixFloatingPointNumber {
       if (remove >= digits_) {
         digits_ = 0;
       } else if (remove > 0) {
-        for (int j{0}; j + remove < digits_; ++j) {
+        // (&& j + remove < maxDigits) was added to avoid GCC < 8 build failure
+        // on -Werror=array-bounds
+        for (int j{ 0 }; j + remove < digits_ && (j + remove < maxDigits);
+             ++j) {
           digit_[j] = digit_[j + remove];
         }
         digits_ -= remove;


        


More information about the flang-commits mailing list