diff --git a/flang/include/flang/Evaluate/integer.h b/flang/include/flang/Evaluate/integer.h --- a/flang/include/flang/Evaluate/integer.h +++ b/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; diff --git a/flang/lib/Decimal/big-radix-floating-point.h b/flang/lib/Decimal/big-radix-floating-point.h --- a/flang/lib/Decimal/big-radix-floating-point.h +++ b/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;