This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix inline builtin functions of an __asm__ renamed function with symbol prefixes
ClosedPublic

Authored by mstorsjo on Oct 31 2022, 4:51 AM.

Details

Summary

If a function is renamed with __asm__, the name provided is the
exact symbol name, without any extra implicit symbol prefixes.
If the target does use symbol prefixes, the IR level symbol gets
an \01 prefix to indicate that it's a literal symbol name to be
taken as is.

When a builtin function is specialized by providing an inline
version of it, that inline function is named <funcname>.inline.

When the base function has been renamed due to __asm__, the inline
function ends up named <asmname>.inline. Up to this point,
things did work as expected before.

However, for targets with symbol prefixes, one codepath that produced
the combined name <asmname>.inline used the mangled asmname with
\01 prefix, while others didn't. This patch fixes this.

This fixes the combination of asm renamed builtin function, with
inline override of the function, on any target with symbol
prefixes (such as i386 windows and any Darwin target).

Alternatively, instead of reimplementing this piece of logic
here, should it try to call MangleContext::mangleName somehow?

Diff Detail

Event Timeline

mstorsjo created this revision.Oct 31 2022, 4:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 31 2022, 4:51 AM
mstorsjo requested review of this revision.Oct 31 2022, 4:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 31 2022, 4:51 AM
rnk added inline comments.Oct 31 2022, 3:17 PM
clang/lib/CodeGen/CGExpr.cpp
5020

I think you can call CGM.getMangledName, but I might be wrong. It's worth doing if straightforward.

mstorsjo added inline comments.Nov 1 2022, 4:42 AM
clang/lib/CodeGen/CGExpr.cpp
5020

Thanks, that seems to work just great, and simplifies things nicely!

mstorsjo updated this revision to Diff 472257.Nov 1 2022, 4:42 AM

Use CGM.getMangledName(), simplifying the code instead of complicating it further.

rnk accepted this revision.Nov 1 2022, 9:52 AM

lgtm, thanks

This revision is now accepted and ready to land.Nov 1 2022, 9:52 AM