This is an archive of the discontinued LLVM Phabricator instance.

PR44406: Follow behavior of array bound constant folding in more recent versions of GCC.
ClosedPublic

Authored by rsmith on Oct 15 2020, 7:36 PM.

Details

Summary

Old GCC used to aggressively fold VLAs to constant-bound arrays at block
scope in GNU mode. That's non-conforming, and more modern versions of
GCC only do this at file scope. Update Clang to do the same.

Also promote the warning for this from off-by-default to on-by-default
in all cases; more recent versions of GCC likewise warn on this by
default.

This is still slightly more permissive than GCC, as pointed out in
PR44406, as we still fold VLAs to constant arrays in structs, but that
seems justifiable given that we don't support VLA-in-struct (and don't
intend to ever support it), but GCC does.

Diff Detail

Event Timeline

rsmith created this revision.Oct 15 2020, 7:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 15 2020, 7:36 PM
rsmith requested review of this revision.Oct 15 2020, 7:36 PM
clang/lib/Sema/SemaDecl.cpp
5939

It's a little surprising to me that you need new code here... was this case getting picked up by the SemaType code?

clang/lib/Sema/SemaType.cpp
2278

We probably want some note to explain why OpenCL is special here... if you can't figure out easily, please leave a FIXME.

efriedma added inline comments.Oct 15 2020, 8:31 PM
clang/lib/Sema/SemaType.cpp
2278

Oh, I see you posted a separate patch for that.

rsmith marked 3 inline comments as done.Oct 15 2020, 10:17 PM
rsmith added inline comments.
clang/lib/Sema/SemaDecl.cpp
5939

Yes, and it previously didn't work outside GNU mode: https://godbolt.org/z/ncqKvo

I suppose that means that it probably isn't important to handle this, but we have a test for the multi-level VLA -> constant array case and it seemed easy enough to make it work.

clang/lib/Sema/SemaType.cpp
2278

For posterity, that's D89520.

rsmith updated this revision to Diff 298702.Oct 16 2020, 11:49 AM
rsmith marked 2 inline comments as done.
  • Update User's Manual to more accurately describe GNU mode and
rsmith updated this revision to Diff 298705.Oct 16 2020, 12:00 PM
  • Update User's Manual to more accurately describe GNU mode and
This revision is now accepted and ready to land.Oct 16 2020, 1:49 PM
This revision was landed with ongoing or failed builds.Oct 16 2020, 2:34 PM
This revision was automatically updated to reflect the committed changes.