]> granicus.if.org Git - clang/commitdiff
Use the correct function info for constructors when applying function attributes...
authorAnders Carlsson <andersca@mac.com>
Sat, 6 Feb 2010 02:44:09 +0000 (02:44 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 6 Feb 2010 02:44:09 +0000 (02:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95474 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCall.cpp
lib/CodeGen/CodeGenModule.cpp
lib/CodeGen/CodeGenModule.h
lib/CodeGen/CodeGenTypes.h
lib/CodeGen/GlobalDecl.h
test/CodeGenCXX/virtual-bases.cpp

index 7a47d5bcc05db9b07104a793b67774b124347c03..707513a23db6b7723e9cd008a8c9eb4b1eba0b08 100644 (file)
@@ -167,6 +167,19 @@ const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const ObjCMethodDecl *MD) {
                          /*NoReturn*/ false);
 }
 
+const CGFunctionInfo &CodeGenTypes::getFunctionInfo(GlobalDecl GD) {
+  // FIXME: Do we need to handle ObjCMethodDecl?
+  const FunctionDecl *FD = cast<FunctionDecl>(GD.getDecl());
+                                              
+  if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD))
+    return getFunctionInfo(CD, GD.getCtorType());
+
+  if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(FD))
+    return getFunctionInfo(DD, GD.getDtorType());
+  
+  return getFunctionInfo(FD);
+}
+
 const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy,
                                                     const CallArgList &Args,
                                                     CallingConv CC,
index c3f5443c47bd7ad8c84678b32f84d698ac568998..fc5989fa9a4b965d0a19dc4e70e76ff49a8a566d 100644 (file)
@@ -409,11 +409,13 @@ void CodeGenModule::SetInternalFunctionAttributes(const Decl *D,
   SetCommonAttributes(D, F);
 }
 
-void CodeGenModule::SetFunctionAttributes(const FunctionDecl *FD,
+void CodeGenModule::SetFunctionAttributes(GlobalDecl GD,
                                           llvm::Function *F,
                                           bool IsIncompleteFunction) {
+  const FunctionDecl *FD = cast<FunctionDecl>(GD.getDecl());
+
   if (!IsIncompleteFunction)
-    SetLLVMFunctionAttributes(FD, getTypes().getFunctionInfo(FD), F);
+    SetLLVMFunctionAttributes(FD, getTypes().getFunctionInfo(GD), F);
 
   // Only a few attributes are set on declarations; these may later be
   // overridden by a definition.
@@ -732,8 +734,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(const char *MangledName,
                                              "", &getModule());
   F->setName(MangledName);
   if (D.getDecl())
-    SetFunctionAttributes(cast<FunctionDecl>(D.getDecl()), F,
-                          IsIncompleteFunction);
+    SetFunctionAttributes(D, F, IsIncompleteFunction);
   Entry = F;
 
   // This is the first use or definition of a mangled name.  If there is a
index 71ae01211618a2e5e4a424b820332c0805babfef..8280766c7035366750380e095fb124b80da2623a 100644 (file)
@@ -451,7 +451,7 @@ private:
 
   /// SetFunctionAttributes - Set function attributes for a function
   /// declaration.
-  void SetFunctionAttributes(const FunctionDecl *FD,
+  void SetFunctionAttributes(GlobalDecl GD,
                              llvm::Function *F,
                              bool IsIncompleteFunction);
 
index 49da15de23891831e6a0033c6541816cf637f2f9..87ba0bcfba1d00271fd2b895f5c916f0f3b36aea 100644 (file)
@@ -20,7 +20,7 @@
 #include <vector>
 
 #include "CGCall.h"
-#include "CGCXX.h"
+#include "GlobalDecl.h"
 
 namespace llvm {
   class FunctionType;
@@ -190,6 +190,8 @@ private:
 
 public:
   /// getFunctionInfo - Get the function info for the specified function decl.
+  const CGFunctionInfo &getFunctionInfo(GlobalDecl GD);
+  
   const CGFunctionInfo &getFunctionInfo(const FunctionDecl *FD);
   const CGFunctionInfo &getFunctionInfo(const CXXMethodDecl *MD);
   const CGFunctionInfo &getFunctionInfo(const ObjCMethodDecl *MD);
index b054312a01854e7f79be66e667d31cdab06e9547..b8a98d7c03b63bc62e67250a62e89c9180719c24 100644 (file)
 #ifndef CLANG_CODEGEN_GLOBALDECL_H
 #define CLANG_CODEGEN_GLOBALDECL_H
 
+#include "CGCXX.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclObjC.h"
+
 namespace clang {
 
 namespace CodeGen {
index 1eaef3fa3af44c119258be74011fbf47c2eae81d..200f21a5da726e23f7c0d3d553be4a092418e2a2 100644 (file)
@@ -15,3 +15,11 @@ struct B : virtual A {
 // CHECK: define void @_ZN1BC1Ev(%struct.B* %this)
 // CHECK: define void @_ZN1BC2Ev(%struct.B* %this, i8** %vtt)
 B::B() { }
+
+struct C : virtual A {
+  C(bool);
+};
+
+// CHECK: define void @_ZN1CC1Eb(%struct.B* %this, i1 zeroext)
+// CHECK: define void @_ZN1CC2Eb(%struct.B* %this, i8** %vtt, i1 zeroext)
+C::C(bool) { }