hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150948

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/AST/ast-dump-recovery.c


Index: clang/test/AST/ast-dump-recovery.c
===================================================================
--- clang/test/AST/ast-dump-recovery.c
+++ clang/test/AST/ast-dump-recovery.c
@@ -98,3 +98,14 @@
   // 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,
+  };
+}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -19307,6 +19307,7 @@
         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: clang/test/AST/ast-dump-recovery.c
===================================================================
--- clang/test/AST/ast-dump-recovery.c
+++ clang/test/AST/ast-dump-recovery.c
@@ -98,3 +98,14 @@
   // 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,
+  };
+}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -19307,6 +19307,7 @@
         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)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to