Skip to content

Commit f97c893

Browse files
committedNov 26, 2015
Fix for merging decls in pragma weak
Calling CheckFunctionDeclaration so that 2 decls for the 'weak' are merged. Differential Revision: http://reviews.llvm.org/D13048 llvm-svn: 254143
1 parent a3ac738 commit f97c893

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed
 

‎clang/lib/Sema/SemaDeclAttr.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -5435,17 +5435,22 @@ NamedDecl * Sema::DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II,
54355435
assert(isa<FunctionDecl>(ND) || isa<VarDecl>(ND));
54365436
NamedDecl *NewD = nullptr;
54375437
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
5438-
FunctionDecl *NewFD;
5439-
// FIXME: Missing call to CheckFunctionDeclaration().
54405438
// FIXME: Mangling?
54415439
// FIXME: Is the qualifier info correct?
54425440
// FIXME: Is the DeclContext correct?
5443-
NewFD = FunctionDecl::Create(FD->getASTContext(), FD->getDeclContext(),
5444-
Loc, Loc, DeclarationName(II),
5445-
FD->getType(), FD->getTypeSourceInfo(),
5446-
SC_None, false/*isInlineSpecified*/,
5447-
FD->hasPrototype(),
5448-
false/*isConstexprSpecified*/);
5441+
5442+
LookupResult Previous(*this, II, Loc, LookupOrdinaryName);
5443+
LookupParsedName(Previous, TUScope, nullptr, true);
5444+
5445+
auto NewFD = FunctionDecl::Create(
5446+
FD->getASTContext(), FD->getDeclContext(), Loc, Loc,
5447+
DeclarationName(II), FD->getType(), FD->getTypeSourceInfo(), SC_None,
5448+
false /*isInlineSpecified*/, FD->hasPrototype(),
5449+
false /*isConstexprSpecified*/);
5450+
5451+
CheckFunctionDeclaration(TUScope, NewFD, Previous,
5452+
false /*IsExplicitSpecialization*/);
5453+
54495454
NewD = NewFD;
54505455

54515456
if (FD->getQualifier())

‎clang/test/CodeGen/pragma-weak.c

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// CHECK-DAG: @mix2 = weak alias void (), void ()* @__mix2
1818
// CHECK-DAG: @a1 = weak alias void (), void ()* @__a1
1919
// CHECK-DAG: @xxx = weak alias void (), void ()* @__xxx
20+
// CHECK-DAG: @weakfoo = weak alias void {{.*}} @localfoo
2021

2122

2223

@@ -173,6 +174,14 @@ void PR16705f(int a) {
173174
// CHECK: declare extern_weak i32 @PR16705b()
174175
// CHECK: declare extern_weak i32 @PR16705c()
175176

177+
// In this test case, we have a declaration of weakfoo before #pragma weak.
178+
// Test that 2 decls for the weakfoo are merged.
179+
extern void weakfoo();
180+
void localfoo() { }
181+
#pragma weak weakfoo=localfoo
182+
extern void externmain() { return weakfoo(); }
183+
// CHECK-LABEL: define void @externmain()
184+
// CHECK: call{{.*}}@weakfoo
176185

177186
///////////// TODO: stuff that still doesn't work
178187

‎clang/test/Sema/pragma-weak.c

+6
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ void __a3(void) __attribute((noinline));
99
#pragma weak a3 = __a3 // expected-note {{previous definition}}
1010
void a3(void) __attribute((alias("__a3"))); // expected-error {{redefinition of 'a3'}}
1111
void __a3(void) {}
12+
13+
extern void weak2foo(int); // expected-note {{previous declaration is here}} expected-note {{'weak2foo' declared here}}
14+
void local2foo(double d1, double d2) { }
15+
#pragma weak weak2foo=local2foo // expected-error {{conflicting types for 'weak2foo'}}
16+
extern void extern2main() { return weak2foo(); } // expected-error {{too few arguments to function call, expected 1, have 0}}
17+

0 commit comments

Comments
 (0)
Please sign in to comment.