[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
This commit is contained in:
Valentin Clement
2020-06-04 14:47:13 -04:00
parent e52a38db07
commit 3d9bb031d1
2 changed files with 7 additions and 2 deletions

View File

@@ -805,7 +805,9 @@ public:
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;

View File

@@ -179,7 +179,10 @@ private:
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;