Skip to content

Commit 8fc8051

Browse files
committed
[OpenACC] Fix crash on error recovery of variable in OpenACC mode
As reported, OpenACC's variable declaration handling was assuming some semblence of legality in the example, so it didn't properly handle an error case. This patch fixes its assumptions so that we don't crash. Fixes #154008
1 parent 8f0da9b commit 8fc8051

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,8 +1921,13 @@ void SemaOpenACC::ActOnVariableDeclarator(VarDecl *VD) {
19211921
return;
19221922

19231923
// This cast should be safe, since a static-local can only happen in a
1924-
// function declaration.
1925-
auto *ContextDecl = cast<FunctionDecl>(getCurContext());
1924+
// function declaration. However, in error cases (or perhaps ObjC/C++?), this
1925+
// could possibly be something like a 'block' decl, so if this is NOT a
1926+
// function decl, just give up.
1927+
auto *ContextDecl = dyn_cast<FunctionDecl>(getCurContext());
1928+
1929+
if (!ContextDecl)
1930+
return;
19261931

19271932
// OpenACC 3.3 2.15:
19281933
// In C and C++, function static variables are not supported in functions to
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// RUN: %clang_cc1 %s -fopenacc -verify
2+
3+
void *a = ^ { static int b };

0 commit comments

Comments
 (0)