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

Valentin Clement via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 4 11:33:24 PDT 2020


clementval created this revision.
clementval added reviewers: DavidTruby, sscalpone.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
clementval edited the summary of this revision.
clementval added a project: Flang.
Herald added a reviewer: jdoerfert.
DavidTruby accepted this revision.
DavidTruby added a comment.
This revision is now accepted and ready to land.

This looks good to me.

As an aside, I think this perfectly demonstrates why we should not force on Werror or have it on by default. We don't have public build bots for even the compilers we claim to support and seemingly innocent changes can cause spurious build failures for other users simply because we are forcing Werror on. And worse, at the moment we are forcing Werror on with no way to turn it off meaning these spurious errors can't even be avoided. This comment isn't intended in any way to block this patch; I just wanted to note it here.


Patch D80794 <https://reviews.llvm.org/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];
                       ~~~~~~~^


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81179

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


Index: flang/lib/Decimal/big-radix-floating-point.h
===================================================================
--- flang/lib/Decimal/big-radix-floating-point.h
+++ flang/lib/Decimal/big-radix-floating-point.h
@@ -179,7 +179,10 @@
       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;
Index: flang/include/flang/Evaluate/integer.h
===================================================================
--- flang/include/flang/Evaluate/integer.h
+++ flang/include/flang/Evaluate/integer.h
@@ -805,7 +805,9 @@
           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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81179.268539.patch
Type: text/x-patch
Size: 1343 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200604/0984a102/attachment.bin>


More information about the llvm-commits mailing list