From ffc29be83f336e6da110442787c8e1ff0780e0a0 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Wed, 6 Aug 2008 00:03:29 +0000 Subject: [PATCH] Implement GNU asm-label extension support in CodeGen. This fixes scimark2 on Darwin. - Added Sema support for asm-label on variables, which I forgot before. - Update CodeGen to use GlobalDeclMap to determine if static Decls require emission (instead of LLVM module name lookup). Important since the Decl name and the LLVM module name can differ. - llvm-svn: 54388 --- clang/lib/CodeGen/CodeGenModule.cpp | 21 ++++++++++++------ clang/lib/Sema/SemaDecl.cpp | 8 +++++++ clang/test/CodeGen/2008-07-31-asm-labels.c | 25 ++++++++++++++++++++++ 3 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 clang/test/CodeGen/2008-07-31-asm-labels.c diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 176576acbbc2..ebe75dd4a2b7 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -184,6 +184,12 @@ void CodeGenModule::SetGlobalValueAttributes(const FunctionDecl *FD, if (const VisibilityAttr *attr = FD->getAttr()) CodeGenModule::setVisibility(GV, attr->getVisibility()); // FIXME: else handle -fvisibility + + if (const AsmLabelAttr *ALA = FD->getAttr()) { + // Prefaced with special LLVM marker to indicate that the name + // should not be munged. + GV->setName("\01" + ALA->getLabel()); + } } void CodeGenModule::SetFunctionAttributes(const FunctionDecl *FD, @@ -400,13 +406,8 @@ void CodeGenModule::EmitStatics() { // Check if we have used a decl with the same name // FIXME: The AST should have some sort of aggregate decls or // global symbol map. - if (const FunctionDecl *FD = dyn_cast(D)) { - if (!getModule().getFunction(FD->getName())) - continue; - } else { - if (!getModule().getNamedGlobal(cast(D)->getName())) - continue; - } + if (!GlobalDeclMap.count(D->getName())) + continue; // Emit the definition. EmitGlobalDefinition(D); @@ -620,6 +621,12 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) { if (const VisibilityAttr *attr = D->getAttr()) setVisibility(GV, attr->getVisibility()); // FIXME: else handle -fvisibility + + 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()); + } // Set the llvm linkage type as appropriate. if (D->getStorageClass() == VarDecl::Static) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 19a2c28e2670..b513dde46619 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -808,6 +808,14 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) { // Handle attributes prior to checking for duplicates in MergeVarDecl ProcessDeclAttributes(NewVD, D); + // Handle GNU asm-label extension (encoded as an attribute). + if (Expr *E = (Expr*) D.getAsmLabel()) { + // The parser guarantees this is a string. + StringLiteral *SE = cast(E); + NewVD->addAttr(new AsmLabelAttr(std::string(SE->getStrData(), + SE->getByteLength()))); + } + // Emit an error if an address space was applied to decl with local storage. // This includes arrays of objects with address space qualifiers, but not // automatic variables that point to other address spaces. diff --git a/clang/test/CodeGen/2008-07-31-asm-labels.c b/clang/test/CodeGen/2008-07-31-asm-labels.c new file mode 100644 index 000000000000..1b5e0ca91da1 --- /dev/null +++ b/clang/test/CodeGen/2008-07-31-asm-labels.c @@ -0,0 +1,25 @@ +// RUN: clang -emit-llvm -o %t %s && +// RUN: grep "@pipe()" %t | count 0 && +// RUN: grep '_thisIsNotAPipe' %t | count 3 && +// RUN: clang -DUSE_DEF -emit-llvm -o %t %s && +// RUN: grep "@pipe()" %t | count 0 && +// RUN: grep '_thisIsNotAPipe' %t | count 3 +// + +void pipe() asm("_thisIsNotAPipe"); + +void f0() { + pipe(); +} + +void pipe(int); + +void f1() { + pipe(1); +} + +#ifdef USE_DEF +void pipe(int arg) { + int x = 10; +} +#endif -- GitLab