Skip to content

Commit 65a9a3d

Browse files
committed
[OpenACC] Fix asserts when checking clauses after invalid directive
When implementing the parsing for OpenACC I ensured that we could always continue to do diagnostics/etc. For the most part, I was consistent with that assumption throughout clause Sema, but in 3 cases I left in some unreachables for cases where this would happen. I've now properly handled all 3 in a reasonable way. Fixes: #139894
1 parent 5b92465 commit 65a9a3d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

clang/lib/Sema/SemaOpenACCClause.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,12 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitVectorClause(
13321332
break;
13331333
case OpenACCDirectiveKind::ParallelLoop:
13341334
break;
1335+
case OpenACCDirectiveKind::Invalid:
1336+
// This can happen when the directive was not recognized, but we continued
1337+
// anyway. Since there is a lot of stuff that can happen (including
1338+
// 'allow anything' in the parallel loop case), just skip all checking and
1339+
// continue.
1340+
break;
13351341
}
13361342
}
13371343

@@ -1369,6 +1375,14 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitWorkerClause(
13691375
switch (Clause.getDirectiveKind()) {
13701376
default:
13711377
llvm_unreachable("Invalid directive kind for this clause");
1378+
case OpenACCDirectiveKind::Invalid:
1379+
// This can happen in cases where the directive was not recognized but we
1380+
// continued anyway. Kernels allows kind of any integer argument, so we
1381+
// can assume it is that (rather than marking the argument invalid like
1382+
// with parallel/serial/routine), and just continue as if nothing
1383+
// happened. We'll skip the 'kernels' checking vs num-workers, since this
1384+
// MIGHT be something else.
1385+
break;
13721386
case OpenACCDirectiveKind::Loop:
13731387
switch (SemaRef.getActiveComputeConstructInfo().Kind) {
13741388
case OpenACCDirectiveKind::Invalid:
@@ -2037,6 +2051,12 @@ SemaOpenACC::CheckGangExpr(ArrayRef<const OpenACCClause *> ExistingClauses,
20372051
default:
20382052
llvm_unreachable("Non compute construct in active compute construct?");
20392053
}
2054+
case OpenACCDirectiveKind::Invalid:
2055+
// This can happen in cases where the the directive was not recognized but
2056+
// we continued anyway. Since the validity checking is all-over the place
2057+
// (it can be a star/integer, or a constant expr depending on the tag), we
2058+
// just give up and return an ExprError here.
2059+
return ExprError();
20402060
default:
20412061
llvm_unreachable("Invalid directive kind for a Gang clause");
20422062
}

clang/test/SemaOpenACC/gh139894.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 %s -fopenacc -verify
2+
3+
// Ensure that these don't assert, they previously assumed that their directive
4+
// kind would be valid, but we should make sure that we handle that gracefully
5+
// in cases where they don't.
6+
7+
// expected-error@+1{{invalid OpenACC directive 'foo'}}
8+
#pragma acc foo gang(1)
9+
10+
// expected-error@+1{{invalid OpenACC directive 'foo'}}
11+
#pragma acc foo vector(1)
12+
13+
// expected-error@+1{{invalid OpenACC directive 'foo'}}
14+
#pragma acc foo worker(1)

0 commit comments

Comments
 (0)