This is an archive of the discontinued LLVM Phabricator instance.

[NFC][flang] Fix PushSemantics macro
ClosedPublic

Authored by luporl on Jun 21 2023, 12:58 PM.

Details

Summary

Add and use the CONCAT macro to force the expansion of LINE in
PushSemantics body.

Diff Detail

Event Timeline

luporl created this revision.Jun 21 2023, 12:58 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 21 2023, 12:58 PM
luporl requested review of this revision.Jun 21 2023, 12:58 PM

What is this trying to fix? Do you have an open issue?

luporl added a comment.EditedJun 21 2023, 3:50 PM

What is this trying to fix? Do you have an open issue?

It's trying to fix the name of the local variable used by PushSemantics macro. There is no open issue, I discovered this while debugging.

pushSemanticsLocalVariable##__LINE__ gets preprocessed to pushSemanticsLocalVariable__LINE__.
This patch fixes this, as it seems the original intent was to append the line number to the variable name.

This would also avoid compilation errors in the unlikely case that PushSemantics is used twice in the same scope.
And if PushSemantics is used in a nested way, this avoids shadowing the variables in the outer scopes, which helps when debugging.

Any way to add a test so we can make sure we have what we want?

flang/lib/Lower/ConvertExpr.cpp
3023–3024

Why do we need two macros here?

Any way to add a test so we can make sure we have what we want?

It would be possible to add a unit test that uses PushSemantics in the ways that currently cause issues, but it would have to be moved to ConvertExpr.h. Would it be ok?

flang/lib/Lower/ConvertExpr.cpp
3023–3024

It's because arguments are not expanded in concatenation. That's why we need to call CONCAT2, before doing the concatenation.
This is explained in more depth here: https://gcc.gnu.org/onlinedocs/cpp/Argument-Prescan.html.

clementval accepted this revision.Jun 23 2023, 9:47 AM

Ok thanks for the clarification. LGTM

This revision is now accepted and ready to land.Jun 23 2023, 9:47 AM
This revision was automatically updated to reflect the committed changes.