Skip to content

[SYCL] Fix bug with constexpr recursion #4257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions clang/lib/Analysis/CallGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,6 @@ class CGBuilder : public StmtVisitor<CGBuilder> {
StmtVisitor::VisitIfStmt(If);
}

void VisitDeclStmt(DeclStmt *DS) {
if (G->shouldSkipConstantExpressions()) {
auto IsConstexprVarDecl = [](Decl *D) {
if (const auto *VD = dyn_cast<VarDecl>(D))
return VD->isConstexpr();
return false;
};
if (llvm::any_of(DS->decls(), IsConstexprVarDecl)) {
assert(llvm::all_of(DS->decls(), IsConstexprVarDecl) &&
"Situation where a decl-group would be a mix of decl types, or "
"constexpr and not?");
return;
}
}

StmtVisitor::VisitDeclStmt(DS);
}

void VisitChildren(Stmt *S) {
for (Stmt *SubStmt : S->children())
if (SubStmt)
Expand Down
11 changes: 10 additions & 1 deletion clang/test/SemaSYCL/allow-constexpr-recursion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sycl::queue q;

constexpr int constexpr_recurse1(int n);

// expected-note@+1 5{{function implemented using recursion declared here}}
// expected-note@+1 6{{function implemented using recursion declared here}}
constexpr int constexpr_recurse(int n) {
if (n)
return constexpr_recurse1(n - 1);
Expand Down Expand Up @@ -87,6 +87,10 @@ void constexpr_recurse_test() {
k = constexpr_recurse(1);
else
constexpr int l = test_constexpr_context(constexpr_recurse(1));

static constexpr struct ConstExprObjInit {
int a;
} objfoo = {constexpr_recurse(1)};
}

void constexpr_recurse_test_err() {
Expand Down Expand Up @@ -114,6 +118,11 @@ void constexpr_recurse_test_err() {
j = constexpr_recurse(5);
break;
}

// expected-error@+3{{SYCL kernel cannot call a recursive function}}
struct ObjInit {
int a;
} objbar = {constexpr_recurse(1)};
}

int main() {
Expand Down