-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang][OpenMP] Diagnose badly-formed collapsed imperfect loop nests (#60678) #101305
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -verify %s | ||
|
||
void func( double *A, int N, int M, int NB ) { | ||
#pragma omp parallel | ||
{ | ||
int nblks = (N-1)/NB; | ||
int lnb = ((N-1)/NB)*NB; | ||
|
||
#pragma omp for collapse(2) | ||
for (int jblk = 0 ; jblk < nblks ; jblk++ ) { | ||
int jb = (jblk == nblks - 1 ? lnb : NB); | ||
for (int jk = 0; jk < N; jk+=jb) { // expected-error{{cannot use variable 'jb' in collapsed imperfectly-nested loop increment statement}} | ||
} | ||
} | ||
|
||
#pragma omp for collapse(2) | ||
for (int a = 0; a < N; a++) { | ||
for (int b = 0; b < M; b++) { | ||
int cx = a+b < NB ? a : b; | ||
for (int c = 0; c < cx; c++) { | ||
} | ||
} | ||
} | ||
|
||
#pragma omp for collapse(3) | ||
for (int a = 0; a < N; a++) { | ||
for (int b = 0; b < M; b++) { | ||
int cx = a+b < NB ? a : b; | ||
for (int c = 0; c < cx; c++) { // expected-error{{cannot use variable 'cx' in collapsed imperfectly-nested loop condition statement}} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
int main(void) { | ||
double arr[256]; | ||
func (arr, 16, 16, 16); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -verify %s | ||
|
||
// We just want to try out a range for statement... this seems a bit OTT. | ||
template<typename T> | ||
class fakevector { | ||
T *contents; | ||
long size; | ||
public: | ||
fakevector(long sz) : size(sz) { | ||
contents = new T[sz]; | ||
} | ||
~fakevector() { | ||
delete[] contents; | ||
} | ||
T& operator[](long x) { return contents[x]; } | ||
typedef T *iterator; | ||
fakevector<T>::iterator begin() { | ||
return &contents[0]; | ||
} | ||
fakevector<T>::iterator end() { | ||
return &contents[size]; | ||
} | ||
}; | ||
|
||
void func( double *A, int N, int M, int NB ) { | ||
#pragma omp parallel | ||
{ | ||
int nblks = (N-1)/NB; | ||
int lnb = ((N-1)/NB)*NB; | ||
#pragma omp for collapse(2) | ||
for (int jblk = 0 ; jblk < nblks ; jblk++ ) { | ||
int jb = (jblk == nblks - 1 ? lnb : NB); | ||
for (int jk = 0; jk < N; jk+=jb) { // expected-error{{cannot use variable 'jb' in collapsed imperfectly-nested loop increment statement}} | ||
} | ||
} | ||
|
||
#pragma omp for collapse(2) | ||
for (int a = 0; a < N; a++) { | ||
for (int b = 0; b < M; b++) { | ||
int cx = a+b < NB ? a : b; | ||
for (int c = 0; c < cx; c++) { | ||
} | ||
} | ||
} | ||
|
||
fakevector<float> myvec{N}; | ||
#pragma omp for collapse(2) | ||
for (auto &a : myvec) { | ||
fakevector<float> myvec3{M}; | ||
for (auto &b : myvec3) { // expected-error{{cannot use variable 'myvec3' in collapsed imperfectly-nested loop init statement}} | ||
} | ||
} | ||
|
||
fakevector<float> myvec2{M}; | ||
|
||
#pragma omp for collapse(3) | ||
for (auto &a : myvec) { | ||
for (auto &b : myvec2) { | ||
int cx = a < b ? N : M; | ||
for (int c = 0; c < cx; c++) { // expected-error {{cannot use variable 'cx' in collapsed imperfectly-nested loop condition statement}} | ||
} | ||
} | ||
} | ||
|
||
#pragma omp for collapse(3) | ||
for (auto &a : myvec) { | ||
int cx = a < 5 ? M : N; | ||
for (auto &b : myvec2) { | ||
for (int c = 0; c < cx; c++) { // expected-error{{cannot use variable 'cx' in collapsed imperfectly-nested loop condition statement}} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
int main(void) { | ||
double arr[256]; | ||
func (arr, 16, 16, 16); | ||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused? Drop then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which bit do you think is unused? The next revision includes a comment on the shouldVisitImplicitCode definition (which is needed).