This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix crash on attempt to initialize union with flexible array member
ClosedPublic

Authored by Fznamznon on May 12 2023, 3:08 AM.

Details

Summary

Due to missing check on union, there was a null expression
added to init list that caused crash later.

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

Diff Detail

Event Timeline

Fznamznon created this revision.May 12 2023, 3:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2023, 3:08 AM
Fznamznon requested review of this revision.May 12 2023, 3:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2023, 3:08 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

The precommit CI failures seem unrelated to these changes.

clang/test/Sema/init.c
168–169 ↗(On Diff #521595)

I think we might want to move this to its own test file so we can test the various edge cases. I'd like to see a RUN line that tests explicitly in -fms-compatibility mode to demonstrate that we do not issue this diagnostic, and RUN lines for C++ mode as well.

Fznamznon updated this revision to Diff 523723.May 19 2023, 3:38 AM

Move the test to a separate file, test C++ and MSVC compatibility mode

shafik accepted this revision.May 19 2023, 12:55 PM

LGTM after addressing Aaron's comment

This revision is now accepted and ready to land.May 19 2023, 12:55 PM
aaron.ballman accepted this revision.May 22 2023, 5:48 AM

LGTM with a minor tweak to the test, thanks!

clang/test/Sema/flexible-array-in-union.c
2–17

Slight tweak to get rid of the preprocessor stuff and simplify the test a bit; NFC.

Fznamznon added inline comments.May 22 2023, 6:07 AM
clang/test/Sema/flexible-array-in-union.c
2–17

Neat! Thank you.