Skip to content

Commit 9186733

Browse files
committed
[OpenACC] Fix infinite loop bug with the device_type checking
I noticed while writing a test that we ended up infinite looping thanks to an early exit not correctly setting the next step of the loop.
1 parent abd1057 commit 9186733

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/lib/Sema/SemaOpenACCClause.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,10 @@ class SemaOpenACCClauseVisitor {
403403

404404
// There are no clauses of the current kind between these device_types, so
405405
// continue.
406-
if (CurClauseKindItr == CurDevTypeItr)
406+
if (CurClauseKindItr == CurDevTypeItr) {
407+
PrevDeviceTypeItr = CurDevTypeItr;
407408
continue;
409+
}
408410

409411
// At this point, we know that this device_type region has a collapse. So
410412
// diagnose if the two device_types have any overlap in their

clang/test/SemaOpenACC/loop-construct-collapse-clause.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,4 +572,9 @@ void no_dupes_since_last_device_type() {
572572
#pragma acc loop device_type(radeon) collapse(1) device_type(nvidia, radeon) collapse(2)
573573
for(unsigned i = 0; i < 5; ++i)
574574
for(unsigned j = 0; j < 5; ++j);
575+
576+
int NotConstexpr;
577+
// expected-error@+1 3{{OpenACC 'collapse' clause loop count must be a constant expression}}
578+
#pragma acc loop collapse(NotConstexpr) device_type(radeon, nvidia) collapse(NotConstexpr) device_type(host) collapse(NotConstexpr)
579+
for(unsigned j = 0; j < 5; ++j);
575580
}

0 commit comments

Comments
 (0)