Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a4186bd

Browse filesBrowse files
authored
[clang][OpenMP] Add error for large expr in collapse clause (#138592)
Report error when OpenMP collapse clause has an expression that can't be represented in 64-bit Issue #138445
1 parent 39b0433 commit a4186bd
Copy full SHA for a4186bd
Expand file treeCollapse file tree

10 files changed

+28
-0
lines changed

‎clang/docs/ReleaseNotes.rst

Copy file name to clipboardExpand all lines: clang/docs/ReleaseNotes.rst
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,9 @@ Improvements to Clang's diagnostics
521521
- Fixed a duplicate diagnostic when performing typo correction on function template
522522
calls with explicit template arguments. (#GH139226)
523523

524+
- An error is now emitted when OpenMP ``collapse`` and ``ordered`` clauses have an
525+
argument larger than what can fit within a 64-bit integer.
526+
524527
Improvements to Clang's time-trace
525528
----------------------------------
526529

‎clang/include/clang/Basic/DiagnosticSemaKinds.td

Copy file name to clipboardExpand all lines: clang/include/clang/Basic/DiagnosticSemaKinds.td
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11526,6 +11526,8 @@ def note_omp_collapse_ordered_expr : Note<
1152611526
"as specified in %select{'collapse'|'ordered'|'collapse' and 'ordered'}0 clause%select{||s}0">;
1152711527
def err_omp_negative_expression_in_clause : Error<
1152811528
"argument to '%0' clause must be a %select{non-negative|strictly positive}1 integer value">;
11529+
def err_omp_large_expression_in_clause : Error<
11530+
"argument to '%0' clause requires a value that can be represented by a 64-bit">;
1152911531
def err_omp_not_integral : Error<
1153011532
"expression must have integral or unscoped enumeration "
1153111533
"type, not %0">;

‎clang/lib/Sema/SemaOpenMP.cpp

Copy file name to clipboardExpand all lines: clang/lib/Sema/SemaOpenMP.cpp
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15944,6 +15944,13 @@ ExprResult SemaOpenMP::VerifyPositiveIntegerConstantInClause(
1594415944
<< E->getSourceRange();
1594515945
return ExprError();
1594615946
}
15947+
15948+
if (!Result.isRepresentableByInt64()) {
15949+
Diag(E->getExprLoc(), diag::err_omp_large_expression_in_clause)
15950+
<< getOpenMPClauseNameForDiag(CKind) << E->getSourceRange();
15951+
return ExprError();
15952+
}
15953+
1594715954
if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1)
1594815955
DSAStack->setAssociatedLoops(Result.getExtValue());
1594915956
else if (CKind == OMPC_ordered)

‎clang/test/OpenMP/for_collapse_messages.cpp

Copy file name to clipboardExpand all lines: clang/test/OpenMP/for_collapse_messages.cpp
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ T tmain(T argc, S **argv) {
4949
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
5050
#pragma omp for collapse (S) // expected-error {{'S' does not refer to a value}}
5151
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
52+
#pragma omp for collapse (0xFFFFFFFFFFFFFFFF) // expected-error {{argument to 'collapse' clause requires a value that can be represented by a 64-bit}}
53+
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
5254
#if __cplusplus <= 199711L
5355
// expected-error@+4 2 {{integral constant expression}} expected-note@+4 0+{{constant expression}}
5456
#else

‎clang/test/OpenMP/for_ordered_clause.cpp

Copy file name to clipboardExpand all lines: clang/test/OpenMP/for_ordered_clause.cpp
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ T tmain(T argc, S **argv) {
5353
#pragma omp for ordered(S) // expected-error {{'S' does not refer to a value}}
5454
for (int i = ST; i < N; i++)
5555
argv[0][i] = argv[0][i] - argv[0][i - ST];
56+
#pragma omp for ordered (0xFFFFFFFFFFFFFFFF) // expected-error {{argument to 'ordered' clause requires a value that can be represented by a 64-bit}}
57+
for (int i = ST; i < N; i++)
58+
argv[0][i] = argv[0][i] - argv[0][i-ST];
5659
#if __cplusplus <= 199711L
5760
// expected-error@+4 2 {{integral constant expression}} expected-note@+4 0+{{constant expression}}
5861
#else

‎clang/test/OpenMP/for_simd_collapse_messages.cpp

Copy file name to clipboardExpand all lines: clang/test/OpenMP/for_simd_collapse_messages.cpp
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ T tmain(T argc, S **argv) {
4343
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
4444
#pragma omp for simd collapse (S) // expected-error {{'S' does not refer to a value}}
4545
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
46+
#pragma omp for simd collapse (0xFFFFFFFFFFFFFFFF) // expected-error {{argument to 'collapse' clause requires a value that can be represented by a 64-bit}}
47+
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
4648
#if __cplusplus <= 199711L
4749
// expected-error@+4 2 {{integral constant expression}} expected-note@+4 0+{{constant expression}}
4850
#else

‎clang/test/OpenMP/for_simd_loop_messages.cpp

Copy file name to clipboardExpand all lines: clang/test/OpenMP/for_simd_loop_messages.cpp
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,9 @@ void test_ordered() {
735735
#pragma omp for simd ordered(1)
736736
for (int i = 0; i < 16; ++i)
737737
;
738+
#pragma omp for simd ordered (0xFFFFFFFFFFFFFFFF) // expected-error {{argument to 'ordered' clause requires a value that can be represented by a 64-bit}}
739+
for (int i = 0; i < 10; i++)
740+
;
738741
}
739742

740743
void test_nowait() {

‎clang/test/OpenMP/masked_taskloop_collapse_messages.cpp

Copy file name to clipboardExpand all lines: clang/test/OpenMP/masked_taskloop_collapse_messages.cpp
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ T tmain(T argc, S **argv) {
4343
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
4444
#pragma omp masked taskloop collapse (S) // expected-error {{'S' does not refer to a value}}
4545
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
46+
#pragma omp masked taskloop collapse (0xFFFFFFFFFFFFFFFF) // expected-error {{argument to 'collapse' clause requires a value that can be represented by a 64-bit}}
47+
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
4648
#if __cplusplus <= 199711L
4749
// expected-error@+4 2 {{integral constant expression}} expected-note@+4 0+{{constant expression}}
4850
#else

‎clang/test/OpenMP/masked_taskloop_simd_collapse_messages.cpp

Copy file name to clipboardExpand all lines: clang/test/OpenMP/masked_taskloop_simd_collapse_messages.cpp
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ T tmain(T argc, S **argv) {
4343
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
4444
#pragma omp masked taskloop simd collapse (S) // expected-error {{'S' does not refer to a value}}
4545
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
46+
#pragma omp masked taskloop simd collapse (0xFFFFFFFFFFFFFFFF) // expected-error {{argument to 'collapse' clause requires a value that can be represented by a 64-bit}}
47+
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
4648
#if __cplusplus <= 199711L
4749
// expected-error@+4 2 {{integral constant expression}} expected-note@+4 0+{{constant expression}}
4850
#else

‎clang/test/OpenMP/simd_collapse_messages.cpp

Copy file name to clipboardExpand all lines: clang/test/OpenMP/simd_collapse_messages.cpp
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ T tmain(T argc, S **argv) {
4343
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
4444
#pragma omp simd collapse (S) // expected-error {{'S' does not refer to a value}}
4545
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
46+
#pragma omp simd collapse (0xFFFFFFFFFFFFFFFF) // expected-error {{argument to 'collapse' clause requires a value that can be represented by a 64-bit}}
47+
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
4648
#if __cplusplus <= 199711L
4749
// expected-error@+4 2 {{integral constant expression}} expected-note@+4 0+{{constant expression}}
4850
#else

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.