[cfe-commits] r54388 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp lib/Sema/SemaDecl.cpp test/CodeGen/2008-07-31-asm-labels.c
Daniel Dunbar
daniel at zuster.org
Tue Aug 5 17:03:29 PDT 2008
Author: ddunbar
Date: Tue Aug 5 19:03:29 2008
New Revision: 54388
URL: http://llvm.org/viewvc/llvm-project?rev=54388&view=rev
Log:
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.
- <rdar://problem/6116729>
Added:
cfe/trunk/test/CodeGen/2008-07-31-asm-labels.c
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=54388&r1=54387&r2=54388&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Aug 5 19:03:29 2008
@@ -184,6 +184,12 @@
if (const VisibilityAttr *attr = FD->getAttr<VisibilityAttr>())
CodeGenModule::setVisibility(GV, attr->getVisibility());
// FIXME: else handle -fvisibility
+
+ if (const AsmLabelAttr *ALA = FD->getAttr<AsmLabelAttr>()) {
+ // 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 @@
// 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<FunctionDecl>(D)) {
- if (!getModule().getFunction(FD->getName()))
- continue;
- } else {
- if (!getModule().getNamedGlobal(cast<VarDecl>(D)->getName()))
- continue;
- }
+ if (!GlobalDeclMap.count(D->getName()))
+ continue;
// Emit the definition.
EmitGlobalDefinition(D);
@@ -620,6 +621,12 @@
if (const VisibilityAttr *attr = D->getAttr<VisibilityAttr>())
setVisibility(GV, attr->getVisibility());
// FIXME: else handle -fvisibility
+
+ if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
+ // 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)
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=54388&r1=54387&r2=54388&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Aug 5 19:03:29 2008
@@ -808,6 +808,14 @@
// 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<StringLiteral>(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.
Added: cfe/trunk/test/CodeGen/2008-07-31-asm-labels.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/2008-07-31-asm-labels.c?rev=54388&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/2008-07-31-asm-labels.c (added)
+++ cfe/trunk/test/CodeGen/2008-07-31-asm-labels.c Tue Aug 5 19:03:29 2008
@@ -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
+// <rdr://6116729>
+
+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
More information about the cfe-commits
mailing list