]> granicus.if.org Git - clang/commitdiff
CodeGen: allow __asm renaming on static local variables.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 20 Nov 2011 21:05:04 +0000 (21:05 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 20 Nov 2011 21:05:04 +0000 (21:05 +0000)
Fixes PR4777.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145015 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDecl.cpp
test/CodeGen/asm-label.c

index d685847155592472b6bd1b447f950d6550b0ee32..3935df02dfadb9256fd269f03640550b6ac8b735 100644 (file)
@@ -11,6 +11,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "CGCXXABI.h"
 #include "CGDebugInfo.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
@@ -177,7 +178,14 @@ CodeGenFunction::CreateStaticVarDecl(const VarDecl &D,
   QualType Ty = D.getType();
   assert(Ty->isConstantSizeType() && "VLAs can't be static");
 
-  std::string Name = GetStaticDeclName(*this, D, Separator);
+  // Use the label if the variable is renamed with the asm-label extension.
+  std::string Name;
+  if (D.hasAttr<AsmLabelAttr>()) {
+    llvm::raw_string_ostream Out(Name);
+    CGM.getCXXABI().getMangleContext().mangleName(&D, Out);
+  } else {
+    Name = GetStaticDeclName(*this, D, Separator);
+  }
 
   llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(Ty);
   llvm::GlobalVariable *GV =
index 7be2ad3cc7a5e2d19d1a14b8ded20d5c91d95994..c06f11fd2d24d55c1fd2f800d833f38f7944267e 100644 (file)
@@ -2,11 +2,18 @@
 // RUN: %clang_cc1 -triple=i686-apple-darwin9 -emit-llvm %s -o - | FileCheck %s --check-prefix=DARWIN
 
 char *strerror(int) asm("alias");
+int x __asm("foo");
 
-void test(void)
-{
-       strerror(-1);
+int *test(void) {
+  static int y __asm("bar");
+  strerror(-1);
+  return &y;
 }
 
+// LINUX: @bar = internal global i32 0
+// LINUX: @foo = common global i32 0
 // LINUX: declare i8* @alias(i32)
+
+// DARWIN: @"\01bar" = internal global i32 0
+// DARWIN: @"\01foo" = common global i32 0
 // DARWIN: declare i8* @"\01alias"(i32)