]> granicus.if.org Git - clang/commitdiff
Pass the right type to GetAddrOfFunction when getting functions for the VTable. Fixes...
authorAnders Carlsson <andersca@mac.com>
Tue, 6 Oct 2009 17:54:23 +0000 (17:54 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 6 Oct 2009 17:54:23 +0000 (17:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83395 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCXX.cpp
test/CodeGenCXX/virtual-function-calls.cpp [new file with mode: 0644]

index 2d5c62e3e230218749ffb31fee72ba351868efea..a119c5af932e0c19ab064523b681774ea1af4ccc 100644 (file)
@@ -891,7 +891,13 @@ public:
            ++mi)
         if (mi->isVirtual()) {
           const CXXMethodDecl *MD = *mi;
-          llvm::Constant *m = wrap(CGM.GetAddrOfFunction(MD));
+          const FunctionProtoType *FPT = 
+            MD->getType()->getAs<FunctionProtoType>();
+          const llvm::Type *Ty =
+            CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(MD),
+                                           FPT->isVariadic());
+          
+          llvm::Constant *m = wrap(CGM.GetAddrOfFunction(MD, Ty));
           OverrideMethod(MD, m, MorallyVirtual, Offset);
         }
     }
@@ -901,9 +907,15 @@ public:
     llvm::Constant *m = 0;
     if (const CXXDestructorDecl *Dtor = dyn_cast<CXXDestructorDecl>(MD))
       m = wrap(CGM.GetAddrOfCXXDestructor(Dtor, Dtor_Complete));
-    else
-      m = wrap(CGM.GetAddrOfFunction(MD));
-
+    else {
+      const FunctionProtoType *FPT = MD->getType()->getAs<FunctionProtoType>();
+      const llvm::Type *Ty =
+        CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(MD),
+                                       FPT->isVariadic());
+      
+      m = wrap(CGM.GetAddrOfFunction(MD, Ty));
+    }
+    
     // If we can find a previously allocated slot for this, reuse it.
     if (OverrideMethod(MD, m, MorallyVirtual, Offset))
       return;
diff --git a/test/CodeGenCXX/virtual-function-calls.cpp b/test/CodeGenCXX/virtual-function-calls.cpp
new file mode 100644 (file)
index 0000000..4002859
--- /dev/null
@@ -0,0 +1,16 @@
+// PR5021
+struct A {
+  virtual void f(char);
+};
+
+void f(A *a) {
+  a->f('c');
+}
+// PR5021
+struct A {
+  virtual void f(char);
+};
+
+void f(A *a) {
+  a->f('c');
+}