[cfe-commits] r83035 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/DeclCXX.h include/clang/AST/Redeclarable.h lib/AST/Decl.cpp lib/CodeGen/CGCXX.cpp test/CodeGenCXX/virt.cpp

Mike Stump mrs at apple.com
Mon Sep 28 17:50:51 PDT 2009


Author: mrs
Date: Mon Sep 28 19:50:50 2009
New Revision: 83035

URL: http://llvm.org/viewvc/llvm-project?rev=83035&view=rev
Log:
Fix http://llvm.org/PR5090.

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/include/clang/AST/Redeclarable.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/test/CodeGenCXX/virt.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=83035&r1=83034&r2=83035&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Sep 28 19:50:50 2009
@@ -973,6 +973,7 @@
 
   void setPreviousDeclaration(FunctionDecl * PrevDecl);
 
+  virtual const FunctionDecl *getCanonicalDecl() const;
   virtual FunctionDecl *getCanonicalDecl();
 
   unsigned getBuiltinID() const;

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=83035&r1=83034&r2=83035&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Mon Sep 28 19:50:50 2009
@@ -785,6 +785,13 @@
     return (CD->begin_overridden_methods() != CD->end_overridden_methods());
   }
   
+  const CXXMethodDecl *getCanonicalDecl() const {
+    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
+  }
+  CXXMethodDecl *getCanonicalDecl() {
+    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
+  }
+  
   ///
   void addOverriddenMethod(const CXXMethodDecl *MD);
 

Modified: cfe/trunk/include/clang/AST/Redeclarable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Redeclarable.h?rev=83035&r1=83034&r2=83035&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Redeclarable.h (original)
+++ cfe/trunk/include/clang/AST/Redeclarable.h Mon Sep 28 19:50:50 2009
@@ -79,6 +79,15 @@
     return D;
   }
 
+  /// \brief Return the first declaration of this declaration or itself if this
+  /// is the only declaration.
+  const decl_type *getFirstDeclaration() const {
+    const decl_type *D = static_cast<const decl_type*>(this);
+    while (D->getPreviousDeclaration())
+      D = D->getPreviousDeclaration();
+    return D;
+  }
+
   /// \brief Set the previous declaration. If PrevDecl is NULL, set this as the
   /// first and only declaration.
   void setPreviousDeclaration(decl_type *PrevDecl) {

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=83035&r1=83034&r2=83035&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Mon Sep 28 19:50:50 2009
@@ -653,6 +653,10 @@
   }
 }
 
+const FunctionDecl *FunctionDecl::getCanonicalDecl() const {
+  return getFirstDeclaration();
+}
+
 FunctionDecl *FunctionDecl::getCanonicalDecl() {
   return getFirstDeclaration();
 }

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=83035&r1=83034&r2=83035&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Mon Sep 28 19:50:50 2009
@@ -221,7 +221,8 @@
   //   virtual call mechanism.
   llvm::Value *Callee;
   if (MD->isVirtual() && !ME->hasQualifier())
-    Callee = BuildVirtualCall(MD, This, Ty);
+    // FIXME: push getCanonicalDecl as a conversion using the static type system (CanCXXMethodDecl).
+    Callee = BuildVirtualCall(MD->getCanonicalDecl(), This, Ty);
   else if (const CXXDestructorDecl *Destructor
              = dyn_cast<CXXDestructorDecl>(MD))
     Callee = CGM.GetAddrOfFunction(GlobalDecl(Destructor, Dtor_Complete), Ty);

Modified: cfe/trunk/test/CodeGenCXX/virt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virt.cpp?rev=83035&r1=83034&r2=83035&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/virt.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virt.cpp Mon Sep 28 19:50:50 2009
@@ -920,6 +920,19 @@
 // CHECK-LP64-NEXT: .quad __ZN2D14bar4Ev
 // CHECK-LP64-NEXT: .quad __ZN2D14bar5Ev
 
+class test14 {
+public:
+    virtual void initWithInt(int a);
+    static test14 *withInt(int a);
+};
+
+void test14::initWithInt(int a) { }
+
+test14 *test14::withInt(int a) {
+  test14 *me = new test14;
+  me->initWithInt(a);
+  return me;
+}
 
 test11_D d11;
 test10_D d10;





More information about the cfe-commits mailing list