[PATCH] PR5172: Fix for a bug in pragma redefine_extname implementation.

Andrey Bokhanko andreybokhanko at gmail.com
Thu Jun 4 05:01:39 PDT 2015


Patch updated again (the only difference is that a pair of curly braces went away).

David [Chisnall], Aaron wrote (http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150601/130212.html) that:

"Changes look good... However, since I don't know about the semantics of this particular pragma, I'll let someone else give the final LGTM."

You are the original author of this pragma support; could you, please, LGTM my fix?

Andrey


http://reviews.llvm.org/D10187

Files:
  lib/Sema/SemaDecl.cpp
  test/CodeGen/redefine_extname.c

Index: test/CodeGen/redefine_extname.c
===================================================================
--- test/CodeGen/redefine_extname.c
+++ test/CodeGen/redefine_extname.c
@@ -3,6 +3,12 @@
 #pragma redefine_extname fake real
 #pragma redefine_extname name alias
 
+struct statvfs64 {
+  int f;
+};
+#pragma redefine_extname statvfs64 statvfs
+int statvfs64(struct statvfs64 *);
+
 extern int fake(void);
 
 int name;
@@ -13,3 +19,12 @@
 // CHECK:   call i32 @real()
 // Check that this also works with variables names
 // CHECK:   load i32, i32* @alias
+
+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. PR5712, Comment 11.
+// CHECK:  call i32 @statvfs(%struct.statvfs64* %st)
+}
+
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -14199,14 +14199,15 @@
                                       SourceLocation AliasNameLoc) {
   Decl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc,
                                     LookupOrdinaryName);
-  AsmLabelAttr *Attr = ::new (Context) AsmLabelAttr(AliasNameLoc, Context,
-                                                    AliasName->getName(), 0);
+  if (PrevDecl)
+    PrevDecl->addAttr(AsmLabelAttr::CreateImplicit(
+        Context, AliasName->getName(), AliasNameLoc));
 
-  if (PrevDecl) 
-    PrevDecl->addAttr(Attr);
-  else 
-    (void)ExtnameUndeclaredIdentifiers.insert(
-      std::pair<IdentifierInfo*,AsmLabelAttr*>(Name, Attr));
+  // There might be additional not yet declared identifiers with Name name.
+  // PR5172, Comment 11.
+  (void)ExtnameUndeclaredIdentifiers.insert(
+      std::make_pair(Name, AsmLabelAttr::CreateImplicit(
+                               Context, AliasName->getName(), AliasNameLoc)));
 }
 
 void Sema::ActOnPragmaWeakID(IdentifierInfo* Name,

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10187.27109.patch
Type: text/x-patch
Size: 1988 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150604/b495a319/attachment.bin>


More information about the cfe-commits mailing list