[clang][RecoveryExpr] Fix a crash where a dependent type crahes on c-only code path.
authorHaojian Wu <hokein.wu@gmail.com>
Fri, 19 May 2023 09:35:43 +0000 (11:35 +0200)
committerHaojian Wu <hokein.wu@gmail.com>
Fri, 19 May 2023 18:24:54 +0000 (20:24 +0200)
A depenent type is possible in C-only path, add a proper handling when
checking the enum constant.

Fixes https://github.com/llvm/llvm-project/issues/62446

Differential Revision: https://reviews.llvm.org/D150948

clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/AST/ast-dump-recovery.c

index 9bcc17b..3035e23 100644 (file)
@@ -410,6 +410,9 @@ Bug Fixes in This Version
   when it had been instantiated from a partial template specialization with different
   template arguments on the containing class. This fixes:
   (`#60778 <https://github.com/llvm/llvm-project/issues/60778>`_).
+- Fix a crash when an enum constant has a dependent-type recovery expression for
+  C.
+  (`#62446 <https://github.com/llvm/llvm-project/issues/62446>`_).
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
index f499a86..eff5f38 100644 (file)
@@ -19307,6 +19307,7 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum,
         if (!getLangOpts().CPlusPlus && !T.isNull())
           Diag(IdLoc, diag::warn_enum_value_overflow);
       } else if (!getLangOpts().CPlusPlus &&
+                 !EltTy->isDependentType() &&
                  !isRepresentableIntegerValue(Context, EnumVal, EltTy)) {
         // Enforce C99 6.7.2.2p2 even when we compute the next value.
         Diag(IdLoc, diag::ext_enum_value_not_int)
index f7b3c7b..75441c1 100644 (file)
@@ -98,3 +98,14 @@ void test3() {
   // CHECK-NEXT: `-RecoveryExpr {{.*}} '<dependent type>'
   ext(undef_var);
 }
+
+// Verify no crash.
+void test4() {
+  enum GH62446 {
+    // CHECK:      RecoveryExpr {{.*}} '<dependent type>' contains-errors lvalue
+    // CHECK-NEXT: |-StringLiteral {{.*}} "a"
+    // CHECK-NEXT: `-IntegerLiteral {{.*}} 2
+    invalid_enum_value = "a" * 2,
+    b,
+  };
+}