This is an archive of the discontinued LLVM Phabricator instance.

[clang] Expand array expressions if the filler expression's filler is element dependent
ClosedPublic

Authored by tbaeder on Aug 4 2022, 4:00 AM.

Details

Summary

This is about the problem described in https://discourse.llvm.org/t/apvalue-lifetime-problem-when-evaluating-constant-expressions/64002/5

The (old) condition in this if statement is meant to handle initializers that depend on (other) array elements. In this case, the array needs to be expanded before the array filler is evaluated:

if (NumEltsToInit != NumElts && MaybeElementDependentArrayFiller(FillerExpr))
  NumEltsToInit = NumElts;

in the test case described on Discourse (which is attached in the patch), MaybeElementDependentArrayFiller() returns false for the outer array but true for the inner array. Since every InitListExpr can have an array filler, I believe the function should take that into account.

This fixes https://github.com/llvm/llvm-project/issues/56016

Diff Detail

Event Timeline

tbaeder created this revision.Aug 4 2022, 4:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2022, 4:00 AM
tbaeder requested review of this revision.Aug 4 2022, 4:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2022, 4:00 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tbaeder updated this revision to Diff 449932.Aug 4 2022, 4:47 AM
aaron.ballman accepted this revision.Aug 4 2022, 6:22 AM

Your logic makes sense to me and these changes look correct; good catch! Please be sure to add a release note when landing. Thanks for the fix!

This revision is now accepted and ready to land.Aug 4 2022, 6:22 AM
erichkeane accepted this revision.Aug 4 2022, 7:23 AM

This seems reasonable to me as well.

arichardson added inline comments.
clang/test/SemaCXX/constexpr-array-init.cpp
4

Nit: It might be helpful to add a comment to this test explaining what it's testing. This makes it easier to diagnose tests failures (e.g. in downstream forks) without having to rely on git blame.

tbaeder marked an inline comment as done.Aug 4 2022, 9:39 PM