diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-11-20 21:05:04 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-11-20 21:05:04 +0000 |
commit | ddbb2b85ab12f29f4b3430ae0c63a54b20cc5885 (patch) | |
tree | 93d91a4f31048a46f490d64140cadc9932b3459e /clang | |
parent | 6ae03c33785f4381acca0408b81bae814431e77a (diff) | |
download | bcm5719-llvm-ddbb2b85ab12f29f4b3430ae0c63a54b20cc5885.tar.gz bcm5719-llvm-ddbb2b85ab12f29f4b3430ae0c63a54b20cc5885.zip |
CodeGen: allow __asm renaming on static local variables.
Fixes PR4777.
llvm-svn: 145015
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/CodeGen/CGDecl.cpp | 10 | ||||
-rw-r--r-- | clang/test/CodeGen/asm-label.c | 13 |
2 files changed, 19 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index d6858471555..3935df02dfa 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -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 = diff --git a/clang/test/CodeGen/asm-label.c b/clang/test/CodeGen/asm-label.c index 7be2ad3cc7a..c06f11fd2d2 100644 --- a/clang/test/CodeGen/asm-label.c +++ b/clang/test/CodeGen/asm-label.c @@ -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) |