akhuang created this revision. akhuang added a reviewer: dblaikie. Herald added subscribers: cfe-commits, aprantl. Herald added a project: clang. akhuang requested review of this revision.
Previously ctor homing was omitting debug info for classes if they have both trival and nontrivial constructors, but we should only omit debug info if the class doesn't have any trivial constructors. Also change to use completeUnusedClass so the debug info is added to the retained types list. bug: https://bugs.llvm.org/show_bug.cgi?id=46537 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D84870 Files: clang/lib/CodeGen/CGDebugInfo.cpp clang/test/CodeGenCXX/debug-info-limited-ctor.cpp Index: clang/test/CodeGenCXX/debug-info-limited-ctor.cpp =================================================================== --- clang/test/CodeGenCXX/debug-info-limited-ctor.cpp +++ clang/test/CodeGenCXX/debug-info-limited-ctor.cpp @@ -24,3 +24,9 @@ struct E { constexpr E(){}; } TestE; + +// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "F"{{.*}}DIFlagTypePassByValue +struct F { + F() = default; + F(int) {} +} TestF; Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -1705,14 +1705,13 @@ // info is emitted. if (DebugKind == codegenoptions::DebugInfoConstructor) if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(Method)) - completeClass(CD->getParent()); + completeUnusedClass(*CD->getParent()); llvm::DINodeArray TParamsArray = CollectFunctionTemplateParams(Method, Unit); llvm::DISubprogram *SP = DBuilder.createMethod( RecordTy, MethodName, MethodLinkageName, MethodDefUnit, MethodLine, MethodTy, VIndex, ThisAdjustment, ContainingType, Flags, SPFlags, TParamsArray.get()); - SPCache[Method->getCanonicalDecl()].reset(SP); return SP; @@ -2296,12 +2295,19 @@ // In constructor debug mode, only emit debug info for a class when its // constructor is emitted. Skip this optimization if the class or any of // its methods are marked dllimport. + // + // This applies to classes that don't have any trivial constructors and have + // at least one constructor. if (DebugKind == codegenoptions::DebugInfoConstructor && !CXXDecl->isLambda() && !CXXDecl->hasConstexprNonCopyMoveConstructor() && - !isClassOrMethodDLLImport(CXXDecl)) + !isClassOrMethodDLLImport(CXXDecl)) { + if (CXXDecl->ctors().empty()) + return false; for (const auto *Ctor : CXXDecl->ctors()) - if (Ctor->isUserProvided()) - return true; + if (Ctor->isTrivial() && !Ctor->isCopyOrMoveConstructor()) + return false; + return true; + } TemplateSpecializationKind Spec = TSK_Undeclared; if (const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
Index: clang/test/CodeGenCXX/debug-info-limited-ctor.cpp =================================================================== --- clang/test/CodeGenCXX/debug-info-limited-ctor.cpp +++ clang/test/CodeGenCXX/debug-info-limited-ctor.cpp @@ -24,3 +24,9 @@ struct E { constexpr E(){}; } TestE; + +// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "F"{{.*}}DIFlagTypePassByValue +struct F { + F() = default; + F(int) {} +} TestF; Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -1705,14 +1705,13 @@ // info is emitted. if (DebugKind == codegenoptions::DebugInfoConstructor) if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(Method)) - completeClass(CD->getParent()); + completeUnusedClass(*CD->getParent()); llvm::DINodeArray TParamsArray = CollectFunctionTemplateParams(Method, Unit); llvm::DISubprogram *SP = DBuilder.createMethod( RecordTy, MethodName, MethodLinkageName, MethodDefUnit, MethodLine, MethodTy, VIndex, ThisAdjustment, ContainingType, Flags, SPFlags, TParamsArray.get()); - SPCache[Method->getCanonicalDecl()].reset(SP); return SP; @@ -2296,12 +2295,19 @@ // In constructor debug mode, only emit debug info for a class when its // constructor is emitted. Skip this optimization if the class or any of // its methods are marked dllimport. + // + // This applies to classes that don't have any trivial constructors and have + // at least one constructor. if (DebugKind == codegenoptions::DebugInfoConstructor && !CXXDecl->isLambda() && !CXXDecl->hasConstexprNonCopyMoveConstructor() && - !isClassOrMethodDLLImport(CXXDecl)) + !isClassOrMethodDLLImport(CXXDecl)) { + if (CXXDecl->ctors().empty()) + return false; for (const auto *Ctor : CXXDecl->ctors()) - if (Ctor->isUserProvided()) - return true; + if (Ctor->isTrivial() && !Ctor->isCopyOrMoveConstructor()) + return false; + return true; + } TemplateSpecializationKind Spec = TSK_Undeclared; if (const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits