This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Avoid crash in CheckEnumConstant with contains-error expressions
ClosedPublic

Authored by sammccall on Aug 20 2021, 1:02 AM.

Diff Detail

Event Timeline

sammccall requested review of this revision.Aug 20 2021, 1:02 AM
sammccall created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptAug 20 2021, 1:02 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
hokein accepted this revision.Aug 20 2021, 6:37 AM

Thanks!

clang/lib/Sema/SemaDecl.cpp
17817

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.

clang/test/Sema/enum.cpp
1 ↗(On Diff #367731)

I'd put the test case in clang/test/SemaCXX/recovery-expr-type.cpp

This revision is now accepted and ready to land.Aug 20 2021, 6:37 AM

Hi, @sammccall thanks for the patch.
The precommit checks suggest that some test cases failing, could you please fix them. Thanks

aaron.ballman added inline comments.
clang/test/Sema/enum.cpp
1 ↗(On Diff #367731)

+1 -- Sema is for Cish things and SemaCXX is for C++ish things (in general).

8–9 ↗(On Diff #367731)

Should we be static asserting this? It seems like emergent behavior more than something we intentionally want anyone to rely on.

sammccall updated this revision to Diff 384084.Nov 2 2021, 7:04 AM
sammccall marked 3 inline comments as done.

address comments

Thanks, and sorry for sitting on this so long.

Addressed comments. I think the failing windows bots were implicit -fms-extensions or so that sometimes makes diagnosis more lazy. Moving the test to recovery-expr-type.cpp should take care of this as that test case specifies -triple. But waiting for the windows bot to finish before landing.

clang/test/Sema/enum.cpp
8–9 ↗(On Diff #367731)

Yeah, the thing we're testing is that we can const-evaluate these, and it neither crashes nor propagates dependence further. The static_assert checks the latter.

Replaced with a static assert that isn't sensitive tot he actual value.

This revision was landed with ongoing or failed builds.Nov 2 2021, 7:36 AM
This revision was automatically updated to reflect the committed changes.