setGlobalVisibility(GV, attr->getVisibility());
// FIXME: else handle -fvisibility
- // Prefaced with special LLVM marker to indicate that the name
- // should not be munged.
- if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>())
- GV->setName("\01" + ALA->getLabel());
-
if (const SectionAttr *SA = D->getAttr<SectionAttr>())
GV->setSection(SA->getName());
if (D->getAttr<WeakAttr>() || D->getAttr<WeakImportAttr>())
GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
- // FIXME: This should be handled by the mangler!
- if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
- // Prefaced with special LLVM marker to indicate that the name
- // should not be munged.
- GV->setName("\01" + ALA->getLabel());
- }
return Entry = GV;
}
setGlobalVisibility(GV, attr->getVisibility());
// FIXME: else handle -fvisibility
- // FIXME: This should be a mangling issue.
- if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
- // Prefaced with special LLVM marker to indicate that the name
- // should not be munged.
- GV->setName("\01" + ALA->getLabel());
- }
-
// Set the llvm linkage type as appropriate.
if (D->getStorageClass() == VarDecl::Static)
GV->setLinkage(llvm::Function::InternalLinkage);
bool CXXNameMangler::mangle(const NamedDecl *D) {
+ // Any decl can be declared with __asm("foo") on it, and this takes
+ // precedence over all other naming in the .o file.
+ 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;
+ }
+
// <mangled-name> ::= _Z <encoding>
// ::= <data name>
// ::= <special-name>
// Clang's "overloadable" attribute extension to C/C++ implies
// name mangling (always).
- if (FD->getAttr<OverloadableAttr>())
+ if (FD->getAttr<OverloadableAttr>()) {
; // fall into mangling code unconditionally.
- else if (// C functions are not mangled
- !Context.getLangOptions().CPlusPlus ||
- // "main" is not mangled in C++
- FD->isMain() ||
- // No mangling in an "implicit extern C" header.
- Context.getSourceManager().getFileCharacteristic(FD->getLocation())
- == SrcMgr::C_ExternCSystem)
+ } else if (// C functions are not mangled
+ !Context.getLangOptions().CPlusPlus ||
+ // "main" is not mangled in C++
+ FD->isMain() ||
+ // No mangling in an "implicit extern C" header.
+ Context.getSourceManager().getFileCharacteristic(FD->getLocation())
+ == SrcMgr::C_ExternCSystem)
return false;
else {
// No name mangling in a C linkage specification.
// http://www.codesourcery.com/public/cxx-abi/abi.html
//
//===----------------------------------------------------------------------===//
+
#ifndef LLVM_CLANG_CODEGEN_MANGLE_H
#define LLVM_CLANG_CODEGEN_MANGLE_H
// RUN: clang -arch i386 -emit-llvm -o %t %s &&
// RUN: grep '@_Z2f0i' %t &&
-// RUN: grep '@_Z2f0l' %t
+// RUN: grep '@_Z2f0l' %t &&
// Make sure we mangle overloadable, even in C system headers.
# 1 "somesystemheader.h" 1 3 4
void __attribute__((__overloadable__)) f0(int a) {}
void __attribute__((__overloadable__)) f0(long b) {}
+
+
+
+// These should get merged.
+void foo() __asm__("bar");
+void foo2() __asm__("bar");
+
+// RUN: grep '@"\\01foo"' %t &&
+// RUN: grep '@"\\01bar"' %t
+
+int nux __asm__("foo");
+extern float nux2 __asm__("foo");
+
+int test() {
+ foo();
+ foo2();
+
+ return nux + nux2;
+}