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

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 20 06:37:27 PDT 2021


hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

Thanks!



================
Comment at: clang/lib/Sema/SemaDecl.cpp:17752
+    if (Enum->isDependentType() || Val->isTypeDependent() ||
+        Val->containsErrors())
       EltTy = Context.DependentTy;
----------------
What's happening during the crash:

- the EltTy is an enum type which points to an incomplete enum decl 
- the EnumDecl::getIntegerType() returns a null type
- ASTContext.getIntWidth crashes on a null type

As discussed, an alternative is to add a guard for incomplete-type EltTy (and assert that we only see this case for recovery-expr case), a disadvantage is that this might be narrow...

The current solution also seems fine to me.


================
Comment at: clang/test/Sema/enum.cpp:1
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
----------------
I'd put the test case in `clang/test/SemaCXX/recovery-expr-type.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108451



More information about the cfe-commits mailing list