[OpenMP] Allow negative lower bound in array sections based on pointers
OpenMP 4.5 removed the restriction that array section lower bound must be non negative.
This change is to allow negative values for array section based on pointers.
For array section based on array type there is still a restriction: "The array section must be a subset of the original array."
Patch by David S.
Differential Revision: https://reviews.llvm.org/D22481
llvm-svn: 276177
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index d748b3c..ac5da81 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -4304,14 +4304,13 @@
diag::err_omp_section_incomplete_type, Base))
return ExprError();
- if (LowerBound) {
+ if (LowerBound && !OriginalTy->isAnyPointerType()) {
llvm::APSInt LowerBoundValue;
if (LowerBound->EvaluateAsInt(LowerBoundValue, Context)) {
- // OpenMP 4.0, [2.4 Array Sections]
- // The lower-bound and length must evaluate to non-negative integers.
+ // OpenMP 4.5, [2.4 Array Sections]
+ // The array section must be a subset of the original array.
if (LowerBoundValue.isNegative()) {
- Diag(LowerBound->getExprLoc(), diag::err_omp_section_negative)
- << 0 << LowerBoundValue.toString(/*Radix=*/10, /*Signed=*/true)
+ Diag(LowerBound->getExprLoc(), diag::err_omp_section_not_subset_of_array)
<< LowerBound->getSourceRange();
return ExprError();
}
@@ -4321,11 +4320,11 @@
if (Length) {
llvm::APSInt LengthValue;
if (Length->EvaluateAsInt(LengthValue, Context)) {
- // OpenMP 4.0, [2.4 Array Sections]
- // The lower-bound and length must evaluate to non-negative integers.
+ // OpenMP 4.5, [2.4 Array Sections]
+ // The length must evaluate to non-negative integers.
if (LengthValue.isNegative()) {
- Diag(Length->getExprLoc(), diag::err_omp_section_negative)
- << 1 << LengthValue.toString(/*Radix=*/10, /*Signed=*/true)
+ Diag(Length->getExprLoc(), diag::err_omp_section_length_negative)
+ << LengthValue.toString(/*Radix=*/10, /*Signed=*/true)
<< Length->getSourceRange();
return ExprError();
}
@@ -4333,7 +4332,7 @@
} else if (ColonLoc.isValid() &&
(OriginalTy.isNull() || (!OriginalTy->isConstantArrayType() &&
!OriginalTy->isVariableArrayType()))) {
- // OpenMP 4.0, [2.4 Array Sections]
+ // OpenMP 4.5, [2.4 Array Sections]
// When the size of the array dimension is not known, the length must be
// specified explicitly.
Diag(ColonLoc, diag::err_omp_section_length_undefined)