[cfe-commits] r67297 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h test/CodeGen/alias.c

Daniel Dunbar daniel at zuster.org
Thu Mar 19 01:27:28 PDT 2009


Author: ddunbar
Date: Thu Mar 19 03:27:24 2009
New Revision: 67297

URL: http://llvm.org/viewvc/llvm-project?rev=67297&view=rev
Log:
IRgen support for alias of global variable.
 - PR3818.

Added:
    cfe/trunk/test/CodeGen/alias.c
Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.h

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=67297&r1=67296&r2=67297&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Mar 19 03:27:24 2009
@@ -369,7 +369,7 @@
 
 void CodeGenModule::EmitAliases() {
   for (unsigned i = 0, e = Aliases.size(); i != e; ++i) {
-    const FunctionDecl *D = Aliases[i];
+    const ValueDecl *D = Aliases[i];
     const AliasAttr *AA = D->getAttr<AliasAttr>();
 
     // This is something of a hack, if the FunctionDecl got overridden
@@ -380,7 +380,7 @@
       continue;
 
     const std::string& aliaseeName = AA->getAliasee();
-    llvm::Function *aliasee = getModule().getFunction(aliaseeName);
+    llvm::GlobalValue *aliasee = getModule().getNamedValue(aliaseeName);
     if (!aliasee) {
       // FIXME: This isn't unsupported, this is just an error, which
       // sema should catch, but...
@@ -539,16 +539,14 @@
 }
 
 void CodeGenModule::EmitGlobal(const ValueDecl *Global) {
-  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Global)) {
-    // Aliases are deferred until code for everything else has been
-    // emitted.
-    if (FD->getAttr<AliasAttr>()) {
-      assert(!FD->isThisDeclarationADefinition() && 
-             "Function alias cannot have a definition!");
-      Aliases.push_back(FD);
-      return;
-    }
+  // Aliases are deferred until code for everything else has been
+  // emitted.
+  if (Global->getAttr<AliasAttr>()) {
+    Aliases.push_back(Global);
+    return;
+  }
 
+  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Global)) {
     // Forward declarations are emitted lazily on first use.
     if (!FD->isThisDeclarationADefinition())
       return;

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=67297&r1=67296&r2=67297&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Thu Mar 19 03:27:24 2009
@@ -109,7 +109,7 @@
   /// Aliases - List of aliases in module. These cannot be emitted until all the
   /// code has been seen, as they reference things by name instead of directly
   /// and may reference forward.
-  std::vector<const FunctionDecl*> Aliases;
+  std::vector<const ValueDecl*> Aliases;
 
   /// DeferredDecls - List of decls for which code generation has been
   /// deferred. When the translation unit has been fully processed we

Added: cfe/trunk/test/CodeGen/alias.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/alias.c?rev=67297&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/alias.c (added)
+++ cfe/trunk/test/CodeGen/alias.c Thu Mar 19 03:27:24 2009
@@ -0,0 +1,13 @@
+// RUN: clang -triple i386-pc-linux-gnu -emit-llvm -o %t %s &&
+// RUN: grep '@g0 = common global i32 0' %t &&
+// RUN: grep '@f1 = alias void ()\* @f0' %t &&
+// RUN: grep '@g1 = alias i32\* @g0' %t &&
+// RUN: grep 'define void @f0() nounwind {' %t
+
+void f0(void) { }
+extern void f1(void);
+extern void f1(void) __attribute((alias("f0")));
+
+int g0;
+extern int g1;
+extern int g1 __attribute((alias("g0")));





More information about the cfe-commits mailing list