Skip to content

Commit

Permalink
[OpenACC] Ensure clause expressions side-effects don't happen
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
erichkeane committed Sep 20, 2024
1 parent 65bc259 commit ebf1308
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
15 changes: 8 additions & 7 deletions clang/lib/Sema/TreeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -11859,13 +11859,14 @@ StmtResult TreeTransform<Derived>::TransformOpenACCComputeConstruct(
OpenACCComputeConstruct *C) {
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());

llvm::SmallVector<OpenACCClause *> TransformedClauses =
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
C->clauses());

if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
C->getBeginLoc()))
return StmtError();

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

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

if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
C->getBeginLoc()))
return StmtError();

llvm::SmallVector<OpenACCClause *> TransformedClauses =
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
C->clauses());

if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
C->getBeginLoc()))
return StmtError();

// Transform Loop.
SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(getSema().OpenACC(),
C->getDirectiveKind());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ void TemplUses(T t, U u) {
// CHECK-NEXT: CXXBoolLiteralExpr
// CHECK-NEXT: CompoundStmt


// CHECK-NEXT: DeclStmt
// CHECK-NEXT: VarDecl{{.*}}EndMarker
int EndMarker;
Expand Down Expand Up @@ -490,7 +489,6 @@ void TemplUses(T t, U u) {
// CHECK-NEXT: CXXFunctionalCastExpr{{.*}} 'CorrectConvert' functional cast to struct CorrectConvert <NoOp>
// CHECK-NEXT: InitListExpr{{.*}}'CorrectConvert'
// CHECK-NEXT: WhileStmt
// CHECK-NEXT: ExprWithCleanups
// CHECK-NEXT: CXXBoolLiteralExpr
// CHECK-NEXT: CompoundStmt

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

Expand Down

0 comments on commit ebf1308

Please sign in to comment.