diff options
author | Alexey Bataev <a.bataev@outlook.com> | 2024-03-01 15:14:21 +0000 |
---|---|---|
committer | Alexey Bataev <a.bataev@outlook.com> | 2024-03-01 15:14:21 +0000 |
commit | 87314b9bd181e57f76f7137d586ed3bef59a6c66 (patch) | |
tree | 11a7f8605375c61ffab26cb25b7ef334b4c54393 | |
parent | ab6062fae851f46e095a69c1ae5afcdc36dfb857 (diff) | |
parent | b0181be36cace3460e4ec5d0d11ecbf49484cc55 (diff) |
Rebase, address commentupstream/users/alexey-bataev/spr/slptry-to-vectorize-small-graph-with-extractelements-used-in
Created using spr 1.3.5
-rw-r--r-- | clang/include/clang/Sema/Scope.h | 19 | ||||
-rw-r--r-- | clang/lib/AST/Interp/ByteCodeExprGen.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 14 | ||||
-rw-r--r-- | clang/test/AST/Interp/functions.cpp | 10 | ||||
-rw-r--r-- | clang/test/SemaOpenACC/no-branch-in-out.c | 27 | ||||
-rw-r--r-- | clang/test/SemaOpenACC/no-branch-in-out.cpp | 30 |
6 files changed, 101 insertions, 2 deletions
diff --git a/clang/include/clang/Sema/Scope.h b/clang/include/clang/Sema/Scope.h index b6b5a1f3479a..1cb2fa83e0bb 100644 --- a/clang/include/clang/Sema/Scope.h +++ b/clang/include/clang/Sema/Scope.h @@ -534,6 +534,25 @@ public: return false; } + /// Determine if this scope (or its parents) are a compute construct inside of + /// the nearest 'switch' scope. This is needed to check whether we are inside + /// of a 'duffs' device, which is an illegal branch into a compute construct. + bool isInOpenACCComputeConstructBeforeSwitch() const { + for (const Scope *S = this; S; S = S->getParent()) { + if (S->getFlags() & Scope::OpenACCComputeConstructScope) + return true; + if (S->getFlags() & Scope::SwitchScope) + return false; + + if (S->getFlags() & + (Scope::FnScope | Scope::ClassScope | Scope::BlockScope | + Scope::TemplateParamScope | Scope::FunctionPrototypeScope | + Scope::AtCatchScope | Scope::ObjCMethodScope)) + return false; + } + return false; + } + /// Determine whether this scope is a while/do/for statement, which can have /// continue statements embedded into it. bool isContinueScope() const { diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 0185214fb455..388da0e324c7 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2842,7 +2842,8 @@ bool ByteCodeExprGen<Emitter>::VisitCallExpr(const CallExpr *E) { return false; } else if (Func->isVariadic()) { uint32_t VarArgSize = 0; - unsigned NumParams = Func->getNumWrittenParams(); + unsigned NumParams = + Func->getNumWrittenParams() + isa<CXXOperatorCallExpr>(E); for (unsigned I = NumParams, N = E->getNumArgs(); I != N; ++I) VarArgSize += align(primSize(classify(E->getArg(I)).value_or(PT_Ptr))); if (!this->emitCallVar(Func, VarArgSize, E)) diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index ca2d20675274..4a15a8f6effd 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -527,6 +527,13 @@ Sema::ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHSVal, return StmtError(); } + if (LangOpts.OpenACC && + getCurScope()->isInOpenACCComputeConstructBeforeSwitch()) { + Diag(CaseLoc, diag::err_acc_branch_in_out_compute_construct) + << /*branch*/ 0 << /*into*/ 1; + return StmtError(); + } + auto *CS = CaseStmt::Create(Context, LHSVal.get(), RHSVal.get(), CaseLoc, DotDotDotLoc, ColonLoc); getCurFunction()->SwitchStack.back().getPointer()->addSwitchCase(CS); @@ -546,6 +553,13 @@ Sema::ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, return SubStmt; } + if (LangOpts.OpenACC && + getCurScope()->isInOpenACCComputeConstructBeforeSwitch()) { + Diag(DefaultLoc, diag::err_acc_branch_in_out_compute_construct) + << /*branch*/ 0 << /*into*/ 1; + return StmtError(); + } + DefaultStmt *DS = new (Context) DefaultStmt(DefaultLoc, ColonLoc, SubStmt); getCurFunction()->SwitchStack.back().getPointer()->addSwitchCase(DS); return DS; diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index 9daf8722050f..38f761f563be 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -555,3 +555,13 @@ namespace Local { return t; } } + +namespace VariadicOperator { + struct Callable { + float& operator()(...); + }; + + void test_callable(Callable c) { + float &fr = c(10); + } +} diff --git a/clang/test/SemaOpenACC/no-branch-in-out.c b/clang/test/SemaOpenACC/no-branch-in-out.c index d070247fa65b..eccc64324500 100644 --- a/clang/test/SemaOpenACC/no-branch-in-out.c +++ b/clang/test/SemaOpenACC/no-branch-in-out.c @@ -310,3 +310,30 @@ LABEL5:// #GOTOLBL5 ptr=&&LABEL5; } + +void DuffsDevice() { + int j; + switch (j) { +#pragma acc parallel + for(int i =0; i < 5; ++i) { + case 0: // expected-error{{invalid branch into OpenACC Compute Construct}} + {} + } + } + + switch (j) { +#pragma acc parallel + for(int i =0; i < 5; ++i) { + default: // expected-error{{invalid branch into OpenACC Compute Construct}} + {} + } + } + + switch (j) { +#pragma acc parallel + for(int i =0; i < 5; ++i) { + case 'a' ... 'z': // expected-error{{invalid branch into OpenACC Compute Construct}} + {} + } + } +} diff --git a/clang/test/SemaOpenACC/no-branch-in-out.cpp b/clang/test/SemaOpenACC/no-branch-in-out.cpp index 9affdf733ace..e7d5683f9bc7 100644 --- a/clang/test/SemaOpenACC/no-branch-in-out.cpp +++ b/clang/test/SemaOpenACC/no-branch-in-out.cpp @@ -18,7 +18,6 @@ void ReturnTest() { template<typename T> void BreakContinue() { - #pragma acc parallel for(int i =0; i < 5; ++i) { switch(i) { @@ -109,6 +108,35 @@ void BreakContinue() { } while (j ); } +template<typename T> +void DuffsDevice() { + int j; + switch (j) { +#pragma acc parallel + for(int i =0; i < 5; ++i) { + case 0: // expected-error{{invalid branch into OpenACC Compute Construct}} + {} + } + } + + switch (j) { +#pragma acc parallel + for(int i =0; i < 5; ++i) { + default: // expected-error{{invalid branch into OpenACC Compute Construct}} + {} + } + } + + switch (j) { +#pragma acc parallel + for(int i =0; i < 5; ++i) { + case 'a' ... 'z': // expected-error{{invalid branch into OpenACC Compute Construct}} + {} + } + } +} + void Instantiate() { BreakContinue<int>(); + DuffsDevice<int>(); } |