This is an archive of the discontinued LLVM Phabricator instance.

[clang] Emit an error if variable ends up with incomplete array type
ClosedPublic

Authored by Fznamznon on Aug 23 2023, 7:04 AM.

Details

Summary

This adds an error if variable with incomplete type has initializer with
incomplete type, so it is not possible to deduce array size from
initializer.

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

Diff Detail

Event Timeline

Fznamznon created this revision.Aug 23 2023, 7:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2023, 7:04 AM
Fznamznon requested review of this revision.Aug 23 2023, 7:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2023, 7:04 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
Fznamznon added inline comments.
clang/lib/Sema/SemaDecl.cpp
13456

Not sure about the error message though, maybe it makes sense to add a message similar to err_new_array_size_unknown_from_init .

shafik accepted this revision.Aug 28 2023, 9:31 AM

I Think this change makes sense.

This revision is now accepted and ready to land.Aug 28 2023, 9:31 AM
aaron.ballman accepted this revision.Aug 28 2023, 11:52 AM

LGTM with a small nit

clang/lib/Sema/SemaDecl.cpp
13449–13462

We can cram everything into one predicate; but this is largely intended to rearrange the logic so we're checking the cheap conditions before trying to call getAsIncompleteArrayType twice.

Fznamznon updated this revision to Diff 554220.Aug 29 2023, 2:28 AM

Apply suggestion, rebase to maybe pass precommit

The failures in CI are unrelated and caused by another patch - https://reviews.llvm.org/D112921.

This revision was landed with ongoing or failed builds.Aug 29 2023, 6:56 AM
This revision was automatically updated to reflect the committed changes.