[PATCH] D13048: Fix for merging decls in pragma weak

Alexander Musman via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 26 01:37:30 PST 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL254143: Fix for merging decls in pragma weak (authored by amusman).

Changed prior to commit:
  http://reviews.llvm.org/D13048?vs=35348&id=41216#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D13048

Files:
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/test/CodeGen/pragma-weak.c
  cfe/trunk/test/Sema/pragma-weak.c

Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp
@@ -5435,17 +5435,22 @@
   assert(isa<FunctionDecl>(ND) || isa<VarDecl>(ND));
   NamedDecl *NewD = nullptr;
   if (FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
-    FunctionDecl *NewFD;
-    // FIXME: Missing call to CheckFunctionDeclaration().
     // FIXME: Mangling?
     // FIXME: Is the qualifier info correct?
     // FIXME: Is the DeclContext correct?
-    NewFD = FunctionDecl::Create(FD->getASTContext(), FD->getDeclContext(),
-                                 Loc, Loc, DeclarationName(II),
-                                 FD->getType(), FD->getTypeSourceInfo(),
-                                 SC_None, false/*isInlineSpecified*/,
-                                 FD->hasPrototype(),
-                                 false/*isConstexprSpecified*/);
+
+    LookupResult Previous(*this, II, Loc, LookupOrdinaryName);
+    LookupParsedName(Previous, TUScope, nullptr, true);
+
+    auto NewFD = FunctionDecl::Create(
+        FD->getASTContext(), FD->getDeclContext(), Loc, Loc,
+        DeclarationName(II), FD->getType(), FD->getTypeSourceInfo(), SC_None,
+        false /*isInlineSpecified*/, FD->hasPrototype(),
+        false /*isConstexprSpecified*/);
+
+    CheckFunctionDeclaration(TUScope, NewFD, Previous,
+                             false /*IsExplicitSpecialization*/);
+
     NewD = NewFD;
 
     if (FD->getQualifier())
Index: cfe/trunk/test/CodeGen/pragma-weak.c
===================================================================
--- cfe/trunk/test/CodeGen/pragma-weak.c
+++ cfe/trunk/test/CodeGen/pragma-weak.c
@@ -17,6 +17,7 @@
 // CHECK-DAG: @mix2 = weak alias void (), void ()* @__mix2
 // CHECK-DAG: @a1 = weak alias void (), void ()* @__a1
 // CHECK-DAG: @xxx = weak alias void (), void ()* @__xxx
+// CHECK-DAG: @weakfoo = weak alias void {{.*}} @localfoo
 
 
 
@@ -173,6 +174,14 @@
 // CHECK: declare extern_weak i32 @PR16705b()
 // CHECK: declare extern_weak i32 @PR16705c()
 
+// In this test case, we have a declaration of weakfoo before #pragma weak.
+// Test that 2 decls for the weakfoo are merged.
+extern void weakfoo();
+void localfoo() { }
+#pragma weak weakfoo=localfoo
+extern void externmain() { return weakfoo(); }
+// CHECK-LABEL: define void @externmain()
+// CHECK: call{{.*}}@weakfoo
 
 ///////////// TODO: stuff that still doesn't work
 
Index: cfe/trunk/test/Sema/pragma-weak.c
===================================================================
--- cfe/trunk/test/Sema/pragma-weak.c
+++ cfe/trunk/test/Sema/pragma-weak.c
@@ -9,3 +9,9 @@
 #pragma weak a3 = __a3 // expected-note {{previous definition}}
 void a3(void) __attribute((alias("__a3"))); // expected-error {{redefinition of 'a3'}}
 void __a3(void) {}
+
+extern void weak2foo(int); // expected-note {{previous declaration is here}} expected-note {{'weak2foo' declared here}}
+void local2foo(double d1, double d2) { }
+#pragma weak weak2foo=local2foo // expected-error {{conflicting types for 'weak2foo'}}
+extern void extern2main() { return weak2foo(); } // expected-error {{too few arguments to function call, expected 1, have 0}}
+


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13048.41216.patch
Type: text/x-patch
Size: 3247 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151126/4c21d13f/attachment-0001.bin>


More information about the cfe-commits mailing list