]> granicus.if.org Git - clang/commitdiff
Synthesize the default constructor which has not
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 30 Jul 2009 23:22:00 +0000 (23:22 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 30 Jul 2009 23:22:00 +0000 (23:22 +0000)
been declared as needed.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77641 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenFunction.cpp
lib/CodeGen/CodeGenModule.cpp

index bb53dcc39e3a27f20dcd74b0b41b74ec99a534f0..708100e2a05d9554befae631ef9e273100399f7a 100644 (file)
@@ -238,7 +238,17 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD,
       EmitDtorEpilogue(DD);
     FinishFunction(S->getRBracLoc());
   }
-
+  else 
+    if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD)) {
+      assert(
+             !cast<CXXRecordDecl>(CD->getDeclContext())->
+              hasUserDeclaredConstructor() &&
+             "bogus constructor is being synthesize");
+      StartFunction(FD, FD->getResultType(), Fn, Args, SourceLocation());
+      EmitCtorPrologue(CD);
+      FinishFunction();
+    }
+    
   // Destroy the 'this' declaration.
   if (CXXThisDecl)
     CXXThisDecl->Destroy(getContext());
index 2cc0aab22ab5dd59d0d216040a759fbcd2884314..bc3bd0bfa95980da0a5f1e0fe9ae25b9c409479a 100644 (file)
@@ -640,6 +640,14 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(const char *MangledName,
     // top-level declarations.
     if (FD->isThisDeclarationADefinition() && MayDeferGeneration(FD))
       DeferredDeclsToEmit.push_back(D);
+    // A called constructor which has no definition or declaration need be
+    // synthesized.
+    else if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD)) {
+      const CXXRecordDecl *ClassDecl = 
+        cast<CXXRecordDecl>(CD->getDeclContext());
+      if (!ClassDecl->hasUserDeclaredConstructor())
+        DeferredDeclsToEmit.push_back(D);
+    }
   }
   
   // This function doesn't have a complete type (for example, the return