[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 06:20:50 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG4b5b7c75415b: [AST][RecoveryExpr] Fix a crash on opencl C++. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84145/new/

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.279220.patch
Type: text/x-patch
Size: 1327 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200720/00548384/attachment.bin>


More information about the cfe-commits mailing list