[cfe-dev] Strange character around function declared with "asm"

John McCall rjmccall at apple.com
Thu Dec 2 23:01:07 PST 2010


On Dec 2, 2010, at 10:43 PM, Eric Christopher wrote:
> On Dec 2, 2010, at 8:49 PM, Lorenzo De Carli wrote:
>> I am trying to instruct clang to generate llvm intrinsics in place of
>> certain function calls, and to do so I am using the "asm" tag. For
>> example:
>> 
>> void MyFunc(int a, int b) asm("llvm.myfunc");
>> 
>> void DoSomething() {
>> int x = 1;
>> int y = 2;
>> 
>> MyFunc(x, y);
>> }
>> 
>> However, if I try to compile the above function with "clang -emit-llvm
>> -S test.c -o test.s" I obtain:
>> 
>> define void @DoSomething() nounwind {
>> %x = alloca i32, align 4
>> %y = alloca i32, align 4
>> store i32 1, i32* %x, align 4
>> store i32 2, i32* %y, align 4
>> %1 = load i32* %x, align 4
>> %2 = load i32* %y, align 4
>> call void @"\01llvm.myfunc"(i32 %1, i32 %2)
>> ret void
>> }
>> 
>> declare void @"\01llvm.myfunc"(i32, i32)
>> 
>> Is there a reason for the quotation marks (") and the \01 before the
>> intrinsic call? I tried to get the same assembly from llvm-gcc, and in
>> that case there are no quotation marks or other artefacts.
> 
> Apparently clang is mangling it this way on purpose as far as I can
> tell... I'm not really sure why though.

"asm" means actual assembly, not IR.  That prefix is an escape which tells LLVM to emit the symbol with exactly that name.

AFAIK, there's no way to get clang to emit a user symbol with the name @llvm.myfunc.  We could probably special-case support for this if we see an asm label with a prefix of "llvm." or "clang.", but I'm not sure it's a particularly good idea.

John.



More information about the cfe-dev mailing list