[cfe-dev] merging of FunctionDecl's
Roman Divacky
rdivacky at freebsd.org
Wed Oct 28 05:43:31 PDT 2009
Hi,
example code:
int func(void); (1)
extern int func (void) __asm__ ("FUNC"); (2)
int func(void) {
return 42;
}
this piece of code has two declarators (1 and 2). When clang decides
what symbol name the code goes like this:
CodeGenModule::GetAddrOfFunction
return GetOrCreateLLVMFunction(getMangledName(GD), Ty, GD);
the getMangledName() calls
if (!mangleName(getMangleContext(), ND, Out)) {
which creates CXXNameMangler and tries to mangle the name via it:
CXXNameMangler Mangler(Context, os);
if (!Mangler.mangle(cast<NamedDecl>(D->getCanonicalDecl())))
return false;
the CXXNameMangler::mangle() looks at __asm__(name) and uses it if available
if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
// If we have an asm name, then we use it as the mangling.
Out << '\01'; // LLVM IR Marker for __asm("foo")
Out << ALA->getLabel();
return true;
}
the problem is that when emitting function via CodeGenModule::EmitGlobalFunctionDefinition()
only the first FunctionDecl is used. ie. if (1) is first it will ommit
the needed __asm__ name mangling because (1) does not have any AsmLabelAttr assigned.
What is the correct solution for this? What should be done so the (2) has precedence
over (1) ?
thnx! roman
More information about the cfe-dev
mailing list