hokein created this revision. hokein added a reviewer: sammccall. Herald added subscribers: Anastasia, yaxunl. Herald added a project: clang.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D84145 Files: clang/lib/Sema/SemaDecl.cpp clang/test/SemaOpenCL/recovery-expr.cl Index: clang/test/SemaOpenCL/recovery-expr.cl =================================================================== --- /dev/null +++ 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}} +} Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -11067,8 +11067,14 @@ // 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;
Index: clang/test/SemaOpenCL/recovery-expr.cl =================================================================== --- /dev/null +++ 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}} +} Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -11067,8 +11067,14 @@ // 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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits