[cfe-commits] r164592 - in /cfe/trunk: lib/CodeGen/MicrosoftCXXABI.cpp test/CodeGenCXX/microsoft-abi-constructors.cpp test/CodeGenCXX/microsoft-abi-methods.cpp test/CodeGenCXX/microsoft-abi-static-initializers.cpp

John McCall rjmccall at apple.com
Tue Sep 25 01:00:39 PDT 2012


Author: rjmccall
Date: Tue Sep 25 03:00:39 2012
New Revision: 164592

URL: http://llvm.org/viewvc/llvm-project?rev=164592&view=rev
Log:
In the MS ABI, ctors return 'this'.  Patch by Dmitry Sokolov.

Modified:
    cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-constructors.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-methods.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp

Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=164592&r1=164591&r2=164592&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Tue Sep 25 03:00:39 2012
@@ -33,10 +33,7 @@
   void BuildConstructorSignature(const CXXConstructorDecl *Ctor,
                                  CXXCtorType Type,
                                  CanQualType &ResTy,
-                                 SmallVectorImpl<CanQualType> &ArgTys) {
-    // 'this' is already in place
-    // TODO: 'for base' flag
-  }  
+                                 SmallVectorImpl<CanQualType> &ArgTys);
 
   void BuildDestructorSignature(const CXXDestructorDecl *Ctor,
                                 CXXDtorType Type,
@@ -48,15 +45,9 @@
 
   void BuildInstanceFunctionParams(CodeGenFunction &CGF,
                                    QualType &ResTy,
-                                   FunctionArgList &Params) {
-    BuildThisParam(CGF, Params);
-    // TODO: 'for base' flag
-  }
+                                   FunctionArgList &Params);
 
-  void EmitInstanceFunctionProlog(CodeGenFunction &CGF) {
-    EmitThisParam(CGF);
-    // TODO: 'for base' flag
-  }
+  void EmitInstanceFunctionProlog(CodeGenFunction &CGF);
 
   void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
                        llvm::GlobalVariable *DeclPtr,
@@ -99,10 +90,42 @@
   llvm::Value *readArrayCookieImpl(CodeGenFunction &CGF,
                                    llvm::Value *allocPtr,
                                    CharUnits cookieSize);
+  static bool needThisReturn(GlobalDecl GD);
 };
 
 }
 
+bool MicrosoftCXXABI::needThisReturn(GlobalDecl GD) {
+  const CXXMethodDecl* MD = cast<CXXMethodDecl>(GD.getDecl());
+  return isa<CXXConstructorDecl>(MD);
+}
+
+void MicrosoftCXXABI::BuildConstructorSignature(const CXXConstructorDecl *Ctor,
+                                 CXXCtorType Type,
+                                 CanQualType &ResTy,
+                                 SmallVectorImpl<CanQualType> &ArgTys) {
+  // 'this' is already in place
+  // TODO: 'for base' flag
+  // Ctor returns this ptr
+  ResTy = ArgTys[0];
+}
+
+void MicrosoftCXXABI::BuildInstanceFunctionParams(CodeGenFunction &CGF,
+                                                  QualType &ResTy,
+                                                  FunctionArgList &Params) {
+  BuildThisParam(CGF, Params);
+  if (needThisReturn(CGF.CurGD)) {
+    ResTy = Params[0]->getType();
+  }
+}
+
+void MicrosoftCXXABI::EmitInstanceFunctionProlog(CodeGenFunction &CGF) {
+  EmitThisParam(CGF);
+  if (needThisReturn(CGF.CurGD)) {
+    CGF.Builder.CreateStore(getThisValue(CGF), CGF.ReturnValue);
+  }
+}
+
 bool MicrosoftCXXABI::requiresArrayCookie(const CXXDeleteExpr *expr,
                                    QualType elementType) {
   // Microsoft seems to completely ignore the possibility of a

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-constructors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-constructors.cpp?rev=164592&r1=164591&r2=164592&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-constructors.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-constructors.cpp Tue Sep 25 03:00:39 2012
@@ -9,13 +9,17 @@
 void no_contstructor_destructor_infinite_recursion() {
   A a;
 
-// Make sure that the constructor doesn't call itself:
-// CHECK: define {{.*}} @"\01??0A@@QAE at XZ"
-// CHECK-NOT: call void @"\01??0A@@QAE at XZ"
-// CHECK: ret
+// CHECK:      define linkonce_odr x86_thiscallcc %class.A* @"\01??0A@@QAE at XZ"(%class.A* %this)
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %this.addr = alloca %class.A*, align 4
+// CHECK-NEXT:   store %class.A* %this, %class.A** %this.addr, align 4
+// CHECK-NEXT:   %this1 = load %class.A** %this.addr
+// CHECK-NEXT:   ret %class.A* %this1
+// CHECK-NEXT: }
 
 // Make sure that the destructor doesn't call itself:
 // CHECK: define {{.*}} @"\01??1A@@QAE at XZ"
 // CHECK-NOT: call void @"\01??1A@@QAE at XZ"
 // CHECK: ret
 }
+

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-methods.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-methods.cpp?rev=164592&r1=164591&r2=164592&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-methods.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-methods.cpp Tue Sep 25 03:00:39 2012
@@ -71,8 +71,8 @@
   Child c;
 // Make sure that the Base constructor call in the Child constructor uses
 // the right calling convention:
-// CHECK: define linkonce_odr x86_thiscallcc void @"\01??0Child@@QAE at XZ"
-// CHECK: call x86_thiscallcc void @"\01??0Base@@QAE at XZ"
+// CHECK: define linkonce_odr x86_thiscallcc %class.Child* @"\01??0Child@@QAE at XZ"
+// CHECK: %call = call x86_thiscallcc %class.Base* @"\01??0Base@@QAE at XZ"
 // CHECK: ret
 
 // Make sure that the Base destructor call in the Child denstructor uses
@@ -85,5 +85,5 @@
 // CHECK: define linkonce_odr x86_thiscallcc void @"\01??1Base@@QAE at XZ"
 
 // Make sure that the Base constructor definition uses the right CC:
-// CHECK: define linkonce_odr x86_thiscallcc void @"\01??0Base@@QAE at XZ"
+// CHECK: define linkonce_odr x86_thiscallcc %class.Base* @"\01??0Base@@QAE at XZ"
 }

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp?rev=164592&r1=164591&r2=164592&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp Tue Sep 25 03:00:39 2012
@@ -6,7 +6,7 @@
 } s;
 
 // CHECK: define internal void [[INIT_s:@.*global_var.*]] nounwind
-// CHECK: call x86_thiscallcc void @"\01??0S@@QAE at XZ"
+// CHECK: %call = call x86_thiscallcc %struct.S* @"\01??0S@@QAE at XZ"
 // CHECK: call i32 @atexit(void ()* @"__dtor_\01?s@@3US@@A")
 // CHECK: ret void
 
@@ -34,11 +34,11 @@
 }
 
 // CHECK: define internal void [[INIT_foo:@.*global_var.*]] nounwind
-// CHECK: call x86_thiscallcc void @"\01??0A@@QAE at XZ"
+// CHECK: %call = call x86_thiscallcc %class.A* @"\01??0A@@QAE at XZ"
 // CHECK: call i32 @atexit(void ()* [[FOO_DTOR:@"__dtor_.*foo at .*]])
 // CHECK: ret void
 
-// CHECK: define linkonce_odr x86_thiscallcc void @"\01??0A@@QAE at XZ"
+// CHECK: define linkonce_odr x86_thiscallcc %class.A* @"\01??0A@@QAE at XZ"
 
 // CHECK: define linkonce_odr x86_thiscallcc void @"\01??1A@@QAE at XZ"
 





More information about the cfe-commits mailing list