[PATCH] D84145: [AST][RecoveryExpr] Fix a crash on opencl C++.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 20 02:40:59 PDT 2020
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84145.279157.patch
Type: text/x-patch
Size: 1327 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200720/a2194eea/attachment.bin>
More information about the cfe-commits
mailing list