From: Richard Smith Date: Fri, 1 Aug 2014 01:56:39 +0000 (+0000) Subject: [modules] Remove IRGen special case for emitting implicit special members if X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5774697c0f5e2fc9ef906c3e291d76c3b32b6828;p=clang [modules] Remove IRGen special case for emitting implicit special members if they're somehow missing a body. Looks like this was left behind when the loop was generalized, and it's not been problematic before because without modules, a used, implicit special member function declaration must be a definition. This was resulting in us trying to emit a constructor declaration rather than a definition, and producing a constructor missing its member initializers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214473 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp index 9427de14d7..920a071d8c 100644 --- a/lib/CodeGen/CGClass.cpp +++ b/lib/CodeGen/CGClass.cpp @@ -711,7 +711,9 @@ void CodeGenFunction::EmitConstructorBody(FunctionArgList &Args) { return; } - Stmt *Body = Ctor->getBody(); + const FunctionDecl *Definition = 0; + Stmt *Body = Ctor->getBody(Definition); + assert(Definition == Ctor && "emitting wrong constructor body"); // Enter the function-try-block before the constructor prologue if // applicable. diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 48823befcc..a14558f975 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -1510,26 +1510,18 @@ CodeGenModule::GetOrCreateLLVMFunction(StringRef MangledName, // this will be unnecessary. // // We also don't emit a definition for a function if it's going to be an - // entry - // in a vtable, unless it's already marked as used. + // entry in a vtable, unless it's already marked as used. } else if (getLangOpts().CPlusPlus && D) { // Look for a declaration that's lexically in a record. - const auto *FD = cast(D); - FD = FD->getMostRecentDecl(); - do { + for (const auto *FD = cast(D)->getMostRecentDecl(); FD; + FD = FD->getPreviousDecl()) { if (isa(FD->getLexicalDeclContext())) { - if (FD->isImplicit() && !ForVTable) { - assert(FD->isUsed() && - "Sema didn't mark implicit function as used!"); - addDeferredDeclToEmit(F, GD.getWithDecl(FD)); - break; - } else if (FD->doesThisDeclarationHaveABody()) { + if (FD->doesThisDeclarationHaveABody()) { addDeferredDeclToEmit(F, GD.getWithDecl(FD)); break; } } - FD = FD->getPreviousDecl(); - } while (FD); + } } } diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index ea3f61fdc8..441427cc56 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -3241,6 +3241,8 @@ void ASTDeclReader::UpdateDecl(Decl *D, ModuleFile &ModuleFile, case UPD_CXX_ADDED_IMPLICIT_MEMBER: { Decl *MD = Reader.ReadDecl(ModuleFile, Record, Idx); assert(MD && "couldn't read decl from update record"); + // FIXME: We should call addHiddenDecl instead, to add the member + // to its DeclContext. cast(D)->addedMember(MD); break; } diff --git a/test/Modules/cxx-irgen.cpp b/test/Modules/cxx-irgen.cpp index eea6b316e3..9fb38cedac 100644 --- a/test/Modules/cxx-irgen.cpp +++ b/test/Modules/cxx-irgen.cpp @@ -30,7 +30,7 @@ namespace ImplicitSpecialMembers { // CHECK-LABEL: define {{.*}} @_ZN22ImplicitSpecialMembers1BC2EOS0_( // CHECK: call {{.*}} @_ZN22ImplicitSpecialMembers1AC1ERKS0_( // CHECK-LABEL: define {{.*}} @_ZN22ImplicitSpecialMembers1BC2ERKS0_( - // FIXME CHECK-NOT: call {{.*}} @_ZN22ImplicitSpecialMembers1AC1ERKS0_( + // CHECK: call {{.*}} @_ZN22ImplicitSpecialMembers1AC1ERKS0_( extern B b1; B b2(b1);