Skip to content

Commit ebf1308

Browse files
committed
[OpenACC] Ensure clause expressions side-effects don't happen
The OpenACC standard says side-effects/ordering of expressions in clauses and constructs (not yet, but PR for constructs) cannot be depended on. We already had infrastructure to ensure constructs, and non-template clauses did this right, but we had the ordering of a call vs transform of the clauses happened in tree transform. This patch ensures that the evaluation context put together for the construct covers the clauses as well in tree transform.
1 parent 65bc259 commit ebf1308

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

clang/lib/Sema/TreeTransform.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11859,13 +11859,14 @@ StmtResult TreeTransform<Derived>::TransformOpenACCComputeConstruct(
1185911859
OpenACCComputeConstruct *C) {
1186011860
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
1186111861

11862+
llvm::SmallVector<OpenACCClause *> TransformedClauses =
11863+
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
11864+
C->clauses());
11865+
1186211866
if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
1186311867
C->getBeginLoc()))
1186411868
return StmtError();
1186511869

11866-
llvm::SmallVector<OpenACCClause *> TransformedClauses =
11867-
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
11868-
C->clauses());
1186911870
// Transform Structured Block.
1187011871
SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(getSema().OpenACC(),
1187111872
C->getDirectiveKind());
@@ -11884,14 +11885,14 @@ TreeTransform<Derived>::TransformOpenACCLoopConstruct(OpenACCLoopConstruct *C) {
1188411885

1188511886
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
1188611887

11887-
if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
11888-
C->getBeginLoc()))
11889-
return StmtError();
11890-
1189111888
llvm::SmallVector<OpenACCClause *> TransformedClauses =
1189211889
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
1189311890
C->clauses());
1189411891

11892+
if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
11893+
C->getBeginLoc()))
11894+
return StmtError();
11895+
1189511896
// Transform Loop.
1189611897
SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(getSema().OpenACC(),
1189711898
C->getDirectiveKind());

clang/test/SemaOpenACC/compute-construct-intexpr-clause-ast.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,6 @@ void TemplUses(T t, U u) {
435435
// CHECK-NEXT: CXXBoolLiteralExpr
436436
// CHECK-NEXT: CompoundStmt
437437

438-
439438
// CHECK-NEXT: DeclStmt
440439
// CHECK-NEXT: VarDecl{{.*}}EndMarker
441440
int EndMarker;
@@ -490,7 +489,6 @@ void TemplUses(T t, U u) {
490489
// CHECK-NEXT: CXXFunctionalCastExpr{{.*}} 'CorrectConvert' functional cast to struct CorrectConvert <NoOp>
491490
// CHECK-NEXT: InitListExpr{{.*}}'CorrectConvert'
492491
// CHECK-NEXT: WhileStmt
493-
// CHECK-NEXT: ExprWithCleanups
494492
// CHECK-NEXT: CXXBoolLiteralExpr
495493
// CHECK-NEXT: CompoundStmt
496494

@@ -503,7 +501,6 @@ void TemplUses(T t, U u) {
503501
// CHECK-NEXT: CXXFunctionalCastExpr{{.*}} 'HasInt' functional cast to struct HasInt <NoOp>
504502
// CHECK-NEXT: InitListExpr{{.*}}'HasInt'
505503
// CHECK-NEXT: WhileStmt
506-
// CHECK-NEXT: ExprWithCleanups
507504
// CHECK-NEXT: CXXBoolLiteralExpr
508505
// CHECK-NEXT: CompoundStmt
509506

0 commit comments

Comments
 (0)