This is an archive of the discontinued LLVM Phabricator instance.

Do not treat use of variable from attribute arguments as ODR use
Needs ReviewPublic

Authored by Fznamznon on Mar 25 2022, 11:33 AM.

Details

Summary

Attribute arguments are always compile-time expressions that need to be
evaluated. So, it is not necessary to treat attribute use as ODR use.

Treatment of use from attribute aruments as ODR use had a side
effect in incorrect processing of attributes applied to nested lambdas.
That happened because ODR use from attribute applied to a lambda forced
Sema to check if used variable is correctly captured.
For the following example:

const int I = 10;
auto OL = [=] () {
  auto IL = [&](int K) __attribute__((enable_if(I > K, "..."))) {};
};

when capture-checking function was validating use of either variable I or
parameter K the error "variable cannot be implicitly captured in a lambda with
no capture-default specified" was emitted. That happened due to the
following order of actions during lambda parsing: first, an empty lambda scope
is pushed to FunctionScopes collection in Sema, then the attributes on
lambdas are handled, and only after that the info about inner lambda capturing
style is saved to a corresponding lambda scope. So, at the point when
attributes on inner lambda are handled, capture-checking function thinks
that it is already inside the inner lambda and it doesn't have capturing
style, so the error was emitted.

This patch makes this error go away.

Diff Detail

Event Timeline

Fznamznon created this revision.Mar 25 2022, 11:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 25 2022, 11:33 AM
Fznamznon requested review of this revision.Mar 25 2022, 11:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 25 2022, 11:33 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript