[cfe-commits] r125157 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp lib/CodeGen/GlobalDecl.h test/CodeGenCXX/friend-redecl.cpp

Douglas Gregor dgregor at apple.com
Tue Feb 8 18:03:05 PST 2011


Author: dgregor
Date: Tue Feb  8 20:03:05 2011
New Revision: 125157

URL: http://llvm.org/viewvc/llvm-project?rev=125157&view=rev
Log:
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


Added:
    cfe/trunk/test/CodeGenCXX/friend-redecl.cpp   (with props)
Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/GlobalDecl.h

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=125157&r1=125156&r2=125157&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Feb  8 20:03:05 2011
@@ -857,10 +857,10 @@
       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;
         }
       }

Modified: cfe/trunk/lib/CodeGen/GlobalDecl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/GlobalDecl.h?rev=125157&r1=125156&r2=125157&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/GlobalDecl.h (original)
+++ cfe/trunk/lib/CodeGen/GlobalDecl.h Tue Feb  8 20:03:05 2011
@@ -81,6 +81,12 @@
     GD.Value.setFromOpaqueValue(P);
     return GD;
   }
+  
+  GlobalDecl getWithDecl(const Decl *D) {
+    GlobalDecl Result(*this);
+    Result.Value.setPointer(D);
+    return Result;
+  }
 };
 
 } // end namespace CodeGen

Added: cfe/trunk/test/CodeGenCXX/friend-redecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/friend-redecl.cpp?rev=125157&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/friend-redecl.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/friend-redecl.cpp Tue Feb  8 20:03:05 2011
@@ -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);
+}

Propchange: cfe/trunk/test/CodeGenCXX/friend-redecl.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/CodeGenCXX/friend-redecl.cpp
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/test/CodeGenCXX/friend-redecl.cpp
------------------------------------------------------------------------------
    svn:mime-type = text/plain





More information about the cfe-commits mailing list