Author: erichkeane Date: 2025-08-18T07:37:45-07:00 New Revision: 8fc80519cdb97c7ad762c750e3e59c622b181599
URL: https://github.com/llvm/llvm-project/commit/8fc80519cdb97c7ad762c750e3e59c622b181599 DIFF: https://github.com/llvm/llvm-project/commit/8fc80519cdb97c7ad762c750e3e59c622b181599.diff LOG: [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 Added: clang/test/SemaOpenACC/gh154008.cpp Modified: clang/lib/Sema/SemaOpenACC.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp index 3f870ba528ad0..07713992da352 100644 --- a/clang/lib/Sema/SemaOpenACC.cpp +++ b/clang/lib/Sema/SemaOpenACC.cpp @@ -1921,8 +1921,13 @@ void SemaOpenACC::ActOnVariableDeclarator(VarDecl *VD) { return; // This cast should be safe, since a static-local can only happen in a - // function declaration. - auto *ContextDecl = cast<FunctionDecl>(getCurContext()); + // function declaration. However, in error cases (or perhaps ObjC/C++?), this + // could possibly be something like a 'block' decl, so if this is NOT a + // function decl, just give up. + auto *ContextDecl = dyn_cast<FunctionDecl>(getCurContext()); + + if (!ContextDecl) + return; // OpenACC 3.3 2.15: // In C and C++, function static variables are not supported in functions to diff --git a/clang/test/SemaOpenACC/gh154008.cpp b/clang/test/SemaOpenACC/gh154008.cpp new file mode 100644 index 0000000000000..653f0f7839c02 --- /dev/null +++ b/clang/test/SemaOpenACC/gh154008.cpp @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 %s -fopenacc -verify + +void *a = ^ { static int b }; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits