[cfe-commits] r131311 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/asm-label.c

Joerg Sonnenberger joerg at bec.de
Fri May 13 14:12:10 PDT 2011


Author: joerg
Date: Fri May 13 16:12:10 2011
New Revision: 131311

URL: http://llvm.org/viewvc/llvm-project?rev=131311&view=rev
Log:
Bug 8765: Honor assembler labels for builtins. Ensure that the label is
mangled to avoid doing it twice for platforms that use prefixes like
Darwin.

Added:
    cfe/trunk/test/CodeGen/asm-label.c
Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=131311&r1=131310&r2=131311&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri May 13 16:12:10 2011
@@ -1574,14 +1574,24 @@
          "isn't a lib fn");
 
   // Get the name, skip over the __builtin_ prefix (if necessary).
-  const char *Name = Context.BuiltinInfo.GetName(BuiltinID);
-  if (Context.BuiltinInfo.isLibFunction(BuiltinID))
-    Name += 10;
+  llvm::StringRef Name;
+  GlobalDecl D(FD);
+
+  // If the builtin has been declared explicitly with an assembler label,
+  // use the mangled name. This differs from the plain label on platforms
+  // that prefix labels.
+  if (const AsmLabelAttr *ALA = FD->getAttr<AsmLabelAttr>())
+    Name = getMangledName(D);
+  else if (Context.BuiltinInfo.isLibFunction(BuiltinID))
+    Name = Context.BuiltinInfo.GetName(BuiltinID) + 10;
+  else
+    Name = Context.BuiltinInfo.GetName(BuiltinID);
+
 
   const llvm::FunctionType *Ty =
     cast<llvm::FunctionType>(getTypes().ConvertType(FD->getType()));
 
-  return GetOrCreateLLVMFunction(Name, Ty, GlobalDecl(FD), /*ForVTable=*/false);
+  return GetOrCreateLLVMFunction(Name, Ty, D, /*ForVTable=*/false);
 }
 
 llvm::Function *CodeGenModule::getIntrinsic(unsigned IID,const llvm::Type **Tys,

Added: cfe/trunk/test/CodeGen/asm-label.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/asm-label.c?rev=131311&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/asm-label.c (added)
+++ cfe/trunk/test/CodeGen/asm-label.c Fri May 13 16:12:10 2011
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple=i686-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=LINUX
+// RUN: %clang_cc1 -triple=i686-apple-darwin9 -emit-llvm %s -o - | FileCheck %s --check-prefix=DARWIN
+
+char *strerror(int) asm("alias");
+
+void test(void)
+{
+	strerror(-1);
+}
+
+// LINUX: declare i8* @alias(i32)
+// DARWIN: declare i8* @"\01alias"(i32)





More information about the cfe-commits mailing list