Index: clang/lib/CodeGen/CGDebugInfo.h =================================================================== --- clang/lib/CodeGen/CGDebugInfo.h +++ clang/lib/CodeGen/CGDebugInfo.h @@ -165,6 +165,7 @@ /// ivars and property accessors. llvm::DIType *CreateType(const BuiltinType *Ty); llvm::DIType *CreateType(const ComplexType *Ty); + llvm::DIType *CreateType(const AutoType *Ty); llvm::DIType *CreateQualifiedType(QualType Ty, llvm::DIFile *Fg); llvm::DIType *CreateType(const TypedefType *Ty, llvm::DIFile *Fg); llvm::DIType *CreateType(const TemplateSpecializationType *Ty, Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -810,6 +810,10 @@ return DBuilder.createBasicType(BTName, Size, Encoding); } +llvm::DIType *CGDebugInfo::CreateType(const AutoType *Ty) { + return DBuilder.createUnspecifiedType("auto"); +} + llvm::DIType *CGDebugInfo::CreateType(const ComplexType *Ty) { // Bit size and offset of the type. llvm::dwarf::TypeKind Encoding = llvm::dwarf::DW_ATE_complex_float; @@ -2860,7 +2864,8 @@ return DBuilder.createTempMacroFile(Parent, Line, FName); } -static QualType UnwrapTypeForDebugInfo(QualType T, const ASTContext &C) { +static QualType UnwrapTypeForDebugInfo(QualType T, const ASTContext &C, + int dwarfVersion) { Qualifiers Quals; do { Qualifiers InnerQuals = T.getLocalQualifiers(); @@ -2907,6 +2912,10 @@ T = cast(T)->getReplacementType(); break; case Type::Auto: + if (dwarfVersion >= 5) { + return C.getQualifiedType(T.getTypePtr(), Quals); + } + LLVM_FALLTHROUGH; case Type::DeducedTemplateSpecialization: { QualType DT = cast(T)->getDeducedType(); assert(!DT.isNull() && "Undeduced types shouldn't reach here."); @@ -2928,7 +2937,8 @@ llvm::DIType *CGDebugInfo::getTypeOrNull(QualType Ty) { // Unwrap the type as needed for debug information. - Ty = UnwrapTypeForDebugInfo(Ty, CGM.getContext()); + Ty = UnwrapTypeForDebugInfo(Ty, CGM.getContext(), + CGM.getCodeGenOpts().DwarfVersion); auto It = TypeCache.find(Ty.getAsOpaquePtr()); if (It != TypeCache.end()) { @@ -2969,7 +2979,8 @@ }); // Unwrap the type as needed for debug information. - Ty = UnwrapTypeForDebugInfo(Ty, CGM.getContext()); + Ty = UnwrapTypeForDebugInfo(Ty, CGM.getContext(), + CGM.getCodeGenOpts().DwarfVersion); if (auto *T = getTypeOrNull(Ty)) return T; @@ -3083,6 +3094,9 @@ return CreateType(cast(Ty), Unit); case Type::Auto: + if (CGM.getCodeGenOpts().DwarfVersion >= 5) + return CreateType(cast(Ty)); + case Type::Attributed: case Type::Adjusted: case Type::Decayed: Index: clang/test/CodeGenCXX/debug-info-auto-return.cpp =================================================================== --- /dev/null +++ clang/test/CodeGenCXX/debug-info-auto-return.cpp @@ -0,0 +1,18 @@ +// Test for debug info for C++11 auto return member functions +// RUN: %clang_cc1 -dwarf-version=5 -emit-llvm -triple x86_64-linux-gnu %s -o - \ +// RUN: -O0 -disable-llvm-passes \ +// RUN: -debug-info-kind=standalone \ +// RUN: | FileCheck %s + +// CHECK: !DISubprogram(name: "findMax",{{.*}}, type: ![[t:[0-9]+]],{{.*}} + +// CHECK: ![[t:[0-9]+]] = !DISubroutineType(types: ![[t1:[0-9]+]]) +// CHECK-NEXT: ![[t1:[0-9]+]] = !{![[t2:[0-9]+]], {{.*}} +// CHECK-NEXT: ![[t2:[0-9]+]] = !DIBasicType(tag: DW_TAG_unspecified_type, name: "auto") + +struct myClass { + auto findMax(); +}; + +auto myClass::findMax() { +}