Author: Haojian Wu Date: 2020-07-20T15:15:30+02:00 New Revision: 4b5b7c75415be0837389fe694e1843422b4cd115
URL: https://github.com/llvm/llvm-project/commit/4b5b7c75415be0837389fe694e1843422b4cd115 DIFF: https://github.com/llvm/llvm-project/commit/4b5b7c75415be0837389fe694e1843422b4cd115.diff LOG: [AST][RecoveryExpr] Fix a crash on opencl C++. Differential Revision: https://reviews.llvm.org/D84145 Added: clang/test/SemaOpenCL/recovery-expr.cl Modified: clang/lib/Sema/SemaDecl.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 3e2b61ae8cdf..3413a420430c 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -11067,8 +11067,14 @@ bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) { // except that the aforementioned are allowed in unevaluated // expressions. Everything else falls under the // "may accept other forms of constant expressions" exception. - // (We never end up here for C++, so the constant expression - // rules there don't matter.) + // + // Regular C++ code will not end up here (exceptions: language extensions, + // OpenCL C++ etc), so the constant expression rules there don't matter. + if (Init->isValueDependent()) { + assert(Init->containsErrors() && + "Dependent code should only occur in error-recovery path."); + return true; + } const Expr *Culprit; if (Init->isConstantInitializer(Context, false, &Culprit)) return false; diff --git a/clang/test/SemaOpenCL/recovery-expr.cl b/clang/test/SemaOpenCL/recovery-expr.cl new file mode 100644 index 000000000000..902b10dbb578 --- /dev/null +++ b/clang/test/SemaOpenCL/recovery-expr.cl @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++ -frecovery-ast + +void kernel nocrash() { + constant int L1 = 0; + + private int *constant L2 = L1++; // expected-error {{read-only variable is not assignable}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits