r239466 - PR5172: Fix for a bug in pragma redefine_extname implementation:

Alexander Musman alexander.musman at gmail.com
Wed Jun 10 04:20:27 PDT 2015


Author: amusman
Date: Wed Jun 10 06:20:26 2015
New Revision: 239466

URL: http://llvm.org/viewvc/llvm-project?rev=239466&view=rev
Log:
PR5172: Fix for a bug in pragma redefine_extname implementation:
it doesn't work correctly when a structure is declared before pragma
and then a function with the same name declared after pragma.

Patch by Andrey Bokhanko

Differential Revision: http://reviews.llvm.org/D10187


Added:
    cfe/trunk/test/CodeGenCXX/redefine_extname.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=239466&r1=239465&r2=239466&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jun 10 06:20:26 2015
@@ -14197,16 +14197,22 @@ void Sema::ActOnPragmaRedefineExtname(Id
                                       SourceLocation PragmaLoc,
                                       SourceLocation NameLoc,
                                       SourceLocation AliasNameLoc) {
-  Decl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc,
-                                    LookupOrdinaryName);
-  AsmLabelAttr *Attr = ::new (Context) AsmLabelAttr(AliasNameLoc, Context,
-                                                    AliasName->getName(), 0);
+  NamedDecl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc,
+                                         LookupOrdinaryName);
+  AsmLabelAttr *Attr =
+      AsmLabelAttr::CreateImplicit(Context, AliasName->getName(), AliasNameLoc);
 
-  if (PrevDecl) 
+  // If a declaration that:
+  // 1) declares a function or a variable
+  // 2) has external linkage
+  // already exists, add a label attribute to it.
+  if (PrevDecl &&
+      (isa<FunctionDecl>(PrevDecl) || isa<VarDecl>(PrevDecl)) &&
+      PrevDecl->hasExternalFormalLinkage())
     PrevDecl->addAttr(Attr);
-  else 
-    (void)ExtnameUndeclaredIdentifiers.insert(
-      std::pair<IdentifierInfo*,AsmLabelAttr*>(Name, Attr));
+  // Otherwise, add a label atttibute to ExtnameUndeclaredIdentifiers.
+  else
+    (void)ExtnameUndeclaredIdentifiers.insert(std::make_pair(Name, Attr));
 }
 
 void Sema::ActOnPragmaWeakID(IdentifierInfo* Name,

Added: cfe/trunk/test/CodeGenCXX/redefine_extname.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/redefine_extname.cpp?rev=239466&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/redefine_extname.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/redefine_extname.cpp Wed Jun 10 06:20:26 2015
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple=i386-pc-solaris2.11 -w -emit-llvm %s -o - | FileCheck %s
+
+extern "C" {
+  struct statvfs64 {
+    int f;
+  };
+#pragma redefine_extname statvfs64 statvfs
+  int statvfs64(struct statvfs64 *);
+}
+
+void foo() {
+  struct statvfs64 st;
+  statvfs64(&st);
+// Check that even if there is a structure with redefined name before the
+// pragma, subsequent function name redefined properly. PR5172, Comment 11.
+// CHECK:  call i32 @statvfs(%struct.statvfs64* %st)
+}
+





More information about the cfe-commits mailing list