[clang] ebf1308 - [OpenACC] Ensure clause expressions side-effects don't happen
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 20 11:08:43 PDT 2024
Author: erichkeane
Date: 2024-09-20T11:08:38-07:00
New Revision: ebf13086740d714339b5f7a8bdadf9a5e1b754bb
URL: https://github.com/llvm/llvm-project/commit/ebf13086740d714339b5f7a8bdadf9a5e1b754bb
DIFF: https://github.com/llvm/llvm-project/commit/ebf13086740d714339b5f7a8bdadf9a5e1b754bb.diff
LOG: [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.
Added:
Modified:
clang/lib/Sema/TreeTransform.h
clang/test/SemaOpenACC/compute-construct-intexpr-clause-ast.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index c37fa2fcc94815..95ded5e59a9fa7 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -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());
@@ -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());
diff --git a/clang/test/SemaOpenACC/compute-construct-intexpr-clause-ast.cpp b/clang/test/SemaOpenACC/compute-construct-intexpr-clause-ast.cpp
index 56c3512dec3b92..2c48fc3ef7746d 100644
--- a/clang/test/SemaOpenACC/compute-construct-intexpr-clause-ast.cpp
+++ b/clang/test/SemaOpenACC/compute-construct-intexpr-clause-ast.cpp
@@ -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;
@@ -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
@@ -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
More information about the cfe-commits
mailing list