[PATCH] D108451: [Sema] Avoid crash in CheckEnumConstant with contains-error expressions

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 20 01:02:48 PDT 2021


sammccall created this revision.
sammccall added reviewers: hokein, guopeilin.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes https://bugs.llvm.org/show_bug.cgi?id=51554


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108451

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/enum.cpp


Index: clang/test/Sema/enum.cpp
===================================================================
--- /dev/null
+++ clang/test/Sema/enum.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+enum Circular { // expected-note 2 {{not complete until the closing '}'}}
+  Circular_A = Circular(1), // expected-error {{'Circular' is an incomplete type}}
+  Circular_B = Circular(1)  // expected-error {{'Circular' is an incomplete type}}
+};
+// When initializers contain errors, enumerators are non-type-dependent zeros.
+static_assert(Circular_A != 0, ""); // expected-error {{static_assert failed}}
+static_assert(Circular_B != 0, ""); // expected-error {{static_assert failed}}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -17748,7 +17748,8 @@
     Val = DefaultLvalueConversion(Val).get();
 
   if (Val) {
-    if (Enum->isDependentType() || Val->isTypeDependent())
+    if (Enum->isDependentType() || Val->isTypeDependent() ||
+        Val->containsErrors())
       EltTy = Context.DependentTy;
     else {
       // FIXME: We don't allow folding in C++11 mode for an enum with a fixed


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108451.367731.patch
Type: text/x-patch
Size: 1228 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210820/a2e860fe/attachment.bin>


More information about the cfe-commits mailing list