summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-02-09 02:03:05 +0000
committerDouglas Gregor <dgregor@apple.com>2011-02-09 02:03:05 +0000
commit2575631c0f76753eb61a59461e214900de47be2a (patch)
tree48610fb93fbbbe5d7d2b3d61bea738437ab4a586
parentc8ae55050dcf5becdb8a80b065ecabdd6ae59744 (diff)
downloadbcm5719-llvm-2575631c0f76753eb61a59461e214900de47be2a.tar.gz
bcm5719-llvm-2575631c0f76753eb61a59461e214900de47be2a.zip
When IRgen refers to a function declaration that is not a definition,
and we later find the definition, make sure that we add the definition (not the declaration) to the list of deferred definitions to emit. Fixes PR8864. Thanks to Nick Lewycky for testing this patch out llvm-svn: 125157
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp4
-rw-r--r--clang/lib/CodeGen/GlobalDecl.h6
-rw-r--r--clang/test/CodeGenCXX/friend-redecl.cpp18
3 files changed, 26 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 89aeeb6fc79..56bc31a8587 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -857,10 +857,10 @@ CodeGenModule::GetOrCreateLLVMFunction(llvm::StringRef MangledName,
if (isa<CXXRecordDecl>(FD->getLexicalDeclContext())) {
if (FD->isImplicit() && !ForVTable) {
assert(FD->isUsed() && "Sema didn't mark implicit function as used!");
- DeferredDeclsToEmit.push_back(D);
+ DeferredDeclsToEmit.push_back(D.getWithDecl(FD));
break;
} else if (FD->isThisDeclarationADefinition()) {
- DeferredDeclsToEmit.push_back(D);
+ DeferredDeclsToEmit.push_back(D.getWithDecl(FD));
break;
}
}
diff --git a/clang/lib/CodeGen/GlobalDecl.h b/clang/lib/CodeGen/GlobalDecl.h
index ab3e2019a6a..c2f36d210bf 100644
--- a/clang/lib/CodeGen/GlobalDecl.h
+++ b/clang/lib/CodeGen/GlobalDecl.h
@@ -81,6 +81,12 @@ public:
GD.Value.setFromOpaqueValue(P);
return GD;
}
+
+ GlobalDecl getWithDecl(const Decl *D) {
+ GlobalDecl Result(*this);
+ Result.Value.setPointer(D);
+ return Result;
+ }
};
} // end namespace CodeGen
diff --git a/clang/test/CodeGenCXX/friend-redecl.cpp b/clang/test/CodeGenCXX/friend-redecl.cpp
new file mode 100644
index 00000000000..18292cd1710
--- /dev/null
+++ b/clang/test/CodeGenCXX/friend-redecl.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s
+// PR8864
+
+struct Foo {
+ friend bool TryFoo(Foo *f2) { return TryFoo(0, f2); }
+
+// CHECK: define{{.*}}Z6TryFooP3Foo
+// CHECK-NOT: ret
+// CHECK: call{{.*}}Z6TryFooiP3Foo
+// CHECK: ret
+
+ friend bool TryFoo(int, Foo *f3);
+};
+bool TryFoo(Foo *f5);
+int main(void) {
+ Foo f;
+ TryFoo(&f);
+}
OpenPOWER on IntegriCloud