diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -2296,12 +2296,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(RD)) diff --git a/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp --- a/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp +++ b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp @@ -24,3 +24,10 @@ struct E { constexpr E(){}; } TestE; + +// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "F"{{.*}}DIFlagTypePassByValue +struct F { + F() = default; + F(int) {} + int i; +} TestF;