Author: Haojian Wu Date: 2023-05-19T20:24:54+02:00 New Revision: a62e205254c0f482ba38bacc1f7f6927e6bc6375
URL: https://github.com/llvm/llvm-project/commit/a62e205254c0f482ba38bacc1f7f6927e6bc6375 DIFF: https://github.com/llvm/llvm-project/commit/a62e205254c0f482ba38bacc1f7f6927e6bc6375.diff LOG: [clang][RecoveryExpr] Fix a crash where a dependent type crahes on c-only code path. 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 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaDecl.cpp clang/test/AST/ast-dump-recovery.c Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9bcc17b0c5ff8..3035e23f0b45c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -410,6 +410,9 @@ Bug Fixes in This Version when it had been instantiated from a partial template specialization with diff erent 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 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index f499a8658d73a..eff5f38960f7e 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -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) diff --git a/clang/test/AST/ast-dump-recovery.c b/clang/test/AST/ast-dump-recovery.c index f7b3c7bb4f2f4..75441c1c9de0a 100644 --- a/clang/test/AST/ast-dump-recovery.c +++ b/clang/test/AST/ast-dump-recovery.c @@ -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, + }; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits