This is an archive of the discontinued LLVM Phabricator instance.

[clang] Apply -fmacro-prefix-map to anonymous tags in template arguments
ClosedPublic

Authored by dankm on Jun 9 2023, 11:16 AM.

Details

Summary

When expanding template arguments for pretty function printing,
such as for PRETTY_FUNCTION, make TypePrinter apply
macro-prefix-map remapping to anonymous tags such as lambdas.

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

Diff Detail

Event Timeline

dankm created this revision.Jun 9 2023, 11:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2023, 11:16 AM
dankm added a comment.Jun 9 2023, 11:23 AM

I still need to make a unit test for this. Should be more-or-less a cleaned up version of the testcase in https://github.com/llvm/llvm-project/issues/63219.

dankm updated this revision to Diff 530046.Jun 9 2023, 12:06 PM

Add release notes.

dankm published this revision for review.Jun 9 2023, 12:06 PM

Despite needing unit tests, I'd like some eyes on this change.

Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2023, 12:06 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
shafik added a subscriber: shafik.Jun 9 2023, 12:37 PM
shafik added inline comments.
clang/lib/AST/Expr.cpp
789

This looks consistent with how other places that set CallBacks but I am not familiar with this area.

791

This may not be a well known idiom but is widely used within llvm.

dankm added inline comments.Jun 9 2023, 12:47 PM
clang/lib/AST/Expr.cpp
791

Makes sense, I was going for unambiguity between the class's member name and the constructor argument name, but if it's widely used that's fine. I'll add that change when I add unit tests.

dankm updated this revision to Diff 530069.Jun 9 2023, 1:29 PM

Added unit test

dankm marked an inline comment as done.Jun 9 2023, 1:30 PM
dankm updated this revision to Diff 530070.Jun 9 2023, 1:38 PM

Fix typo in release notes

dankm retitled this revision from [clang] Fix file mapping template arguments to [clang] Fix filename remapping in template arguments.Jun 9 2023, 2:08 PM
dankm updated this revision to Diff 530563.Jun 12 2023, 9:55 AM

Rebase and hopefully fix builds.

dankm updated this revision to Diff 530638.Jun 12 2023, 12:35 PM

Fix unit tests on windows

MaskRay accepted this revision.EditedJun 12 2023, 7:31 PM

Looks great!

[clang] Fix filename remapping in template arguments

Personally I don't consider this a bug fix (AnonymousTagLocations behavior in TypePrinter; GCC doesn't print the filename), so I'd avoid "Fix", but this changes does move into a desired direction, by making -fmacro-prefix-map= add local determinism.
I wonder whether Make -fmacro-prefix-map= apply to anonymous tag in TypePrinter will be more meaningful subject without being too verbose.

clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
1 ↗(On Diff #530638)

You can use -triple x86_64 to test generic ELF behavior, if you don't want to write linux-gnu :)

For this test, perhaps -triple %itanium_abi_triple is better (coverage for non-x86 targets).

2 ↗(On Diff #530638)

For the new test file, I was thinking of https://maskray.me/blog/2021-08-08-toolchain-testing#the-test-checks-at-the-wrong-layer#i-dont-know-an-existing-test-can-be-enhanced.

The main C++ test CodeGenCXX/predefined-expr.cpp does not say about __PRETTY_FUNCTION__ in its filename, so a new file seems fine.

If we are going to retain this new test, I think macro-prefix-map- is a better prefix.
-fmacro-prefix-map= is more specific to -ffile-prefix-map=.

11 ↗(On Diff #530638)

10 should be replaced with [[#@LINE-1]] so that adding more tests will not easily make this stale.

This revision is now accepted and ready to land.Jun 12 2023, 7:31 PM
dankm added a comment.Jun 12 2023, 9:14 PM

Avoiding "Fix" in the description is a good suggestion. Whether it's a bugfix or not is a matter of perspective, and what's really happening here is I'm adjusting compliant implementation defined behavior, not really fixing it.

clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
1 ↗(On Diff #530638)

Generic ELF (or rather Itanium ABI) is probably fine, I just found Windows didn't work, so used the platform I was testing on. But I like the itanium abi triple suggestion.

2 ↗(On Diff #530638)

Yes, I was just quickly thinking of a new filename; macro-prefix-map makes more sense to me too. I'll rename the file.

11 ↗(On Diff #530638)

Thanks, I was looking for how to do that. Not too familiar with filecheck and lit.

dankm updated this revision to Diff 530763.Jun 12 2023, 9:21 PM

Renamed & cleaned up unit tests

dankm added a comment.Jun 12 2023, 9:27 PM

Maybe for the description something like:

Apply -fmacro-prefix-map to anonymous tags in template arguments

Do I need to mention TypePrinter?

dankm retitled this revision from [clang] Fix filename remapping in template arguments to [clang] Apply -fmacro-prefix-map to anonymous tags in template arguments.Jun 12 2023, 9:27 PM
dankm marked 3 inline comments as done.Jun 12 2023, 9:31 PM
dankm added a comment.Jun 13 2023, 8:22 AM

@MaskRay if this meets your approval, are you able to commit it for me?

@MaskRay if this meets your approval, are you able to commit it for me?

LG, but give @aaron.ballman and @shafik some time if they have opinions.

Maybe for the description something like:

Apply -fmacro-prefix-map to anonymous tags in template arguments

Do I need to mention TypePrinter?

I think it's fine to not mention it in the subject. You can mention TypePrinter in the description, though.

clang/docs/ReleaseNotes.rst
514

This needs adjustment as the subject has changed.

MaskRay accepted this revision.Jun 13 2023, 4:24 PM
aaron.ballman accepted this revision.Jun 14 2023, 5:41 AM

LGTM aside from the issue with the release note.

dankm added a comment.Jun 15 2023, 3:58 PM

Thanks, I'll update the release notes & description right away.

dankm updated this revision to Diff 531931.Jun 15 2023, 3:59 PM

Update release notes

dankm edited the summary of this revision. (Show Details)Jun 15 2023, 4:09 PM
MaskRay added inline comments.Jun 16 2023, 8:43 AM
clang/docs/ReleaseNotes.rst
515

I'll add a period to be consistent with other entries. Thanks!

clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp
2

I'll remove -S since -emit-llvm wins for CC1 options.

This revision was landed with ongoing or failed builds.Jun 16 2023, 8:47 AM
This revision was automatically updated to reflect the committed changes.

Hi,

clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp
11

Hi, it's weird that the align in CSKY target is not 1, instead it's 4. Anybody know the key point?

tuliom added a subscriber: tuliom.Jun 19 2023, 6:16 AM
tuliom added inline comments.
clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp
11

And on SystemZ it's 2.