Skip to content

Commit bd15de9

Browse files
[SYCL] Fix bug with constexpr recursion (#4257)
Commit 9a9a018 introduced a regression in following case - E.g. ``` struct ObjInit { int a; } objbar = {constexpr_recurse(1)}; ``` The assert was hit when DeclStmt contains both TypeDecl and VarDecl i.e. a CXXRecordDecl which is not constexpr and a VarDecl which is. This PR removes code added in call graph creation. This code is not technically not required since the AST visitor in SemaSYCL, will handle non-traversal of nodes representing constexpr variables. Closes: #4048 Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
1 parent 270e78d commit bd15de9

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

clang/lib/Analysis/CallGraph.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -150,24 +150,6 @@ class CGBuilder : public StmtVisitor<CGBuilder> {
150150
StmtVisitor::VisitIfStmt(If);
151151
}
152152

153-
void VisitDeclStmt(DeclStmt *DS) {
154-
if (G->shouldSkipConstantExpressions()) {
155-
auto IsConstexprVarDecl = [](Decl *D) {
156-
if (const auto *VD = dyn_cast<VarDecl>(D))
157-
return VD->isConstexpr();
158-
return false;
159-
};
160-
if (llvm::any_of(DS->decls(), IsConstexprVarDecl)) {
161-
assert(llvm::all_of(DS->decls(), IsConstexprVarDecl) &&
162-
"Situation where a decl-group would be a mix of decl types, or "
163-
"constexpr and not?");
164-
return;
165-
}
166-
}
167-
168-
StmtVisitor::VisitDeclStmt(DS);
169-
}
170-
171153
void VisitChildren(Stmt *S) {
172154
for (Stmt *SubStmt : S->children())
173155
if (SubStmt)

clang/test/SemaSYCL/allow-constexpr-recursion.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sycl::queue q;
88

99
constexpr int constexpr_recurse1(int n);
1010

11-
// expected-note@+1 5{{function implemented using recursion declared here}}
11+
// expected-note@+1 6{{function implemented using recursion declared here}}
1212
constexpr int constexpr_recurse(int n) {
1313
if (n)
1414
return constexpr_recurse1(n - 1);
@@ -87,6 +87,10 @@ void constexpr_recurse_test() {
8787
k = constexpr_recurse(1);
8888
else
8989
constexpr int l = test_constexpr_context(constexpr_recurse(1));
90+
91+
static constexpr struct ConstExprObjInit {
92+
int a;
93+
} objfoo = {constexpr_recurse(1)};
9094
}
9195

9296
void constexpr_recurse_test_err() {
@@ -114,6 +118,11 @@ void constexpr_recurse_test_err() {
114118
j = constexpr_recurse(5);
115119
break;
116120
}
121+
122+
// expected-error@+3{{SYCL kernel cannot call a recursive function}}
123+
struct ObjInit {
124+
int a;
125+
} objbar = {constexpr_recurse(1)};
117126
}
118127

119128
int main() {

0 commit comments

Comments
 (0)