From 3f75c43bd77e063342bc888ac276daf64ba0ce07 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Wed, 4 Mar 2009 17:31:19 +0000 Subject: [PATCH] Support "asm" renaming of external symbols. - PR3698. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66038 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 6 ++++++ test/CodeGen/2008-07-31-asm-labels.c | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 558c940713..33aff2553f 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -605,6 +605,12 @@ void CodeGenModule::EmitGlobalDefinition(const ValueDecl *D) { if (D->getAttr()) GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage); + + if (const AsmLabelAttr *ALA = D->getAttr()) { + // Prefaced with special LLVM marker to indicate that the name + // should not be munged. + GV->setName("\01" + ALA->getLabel()); + } } // Make sure the result is of the correct type. diff --git a/test/CodeGen/2008-07-31-asm-labels.c b/test/CodeGen/2008-07-31-asm-labels.c index 1b5e0ca91d..8aba2d39a7 100644 --- a/test/CodeGen/2008-07-31-asm-labels.c +++ b/test/CodeGen/2008-07-31-asm-labels.c @@ -1,6 +1,8 @@ // RUN: clang -emit-llvm -o %t %s && // RUN: grep "@pipe()" %t | count 0 && // RUN: grep '_thisIsNotAPipe' %t | count 3 && +// RUN: grep 'g0' %t | count 0 && +// RUN: grep '_renamed' %t | count 2 && // RUN: clang -DUSE_DEF -emit-llvm -o %t %s && // RUN: grep "@pipe()" %t | count 0 && // RUN: grep '_thisIsNotAPipe' %t | count 3 @@ -23,3 +25,9 @@ void pipe(int arg) { int x = 10; } #endif + +// PR3698 +extern int g0 asm("_renamed"); +int f2() { + return g0; +} -- 2.40.0