Index: clang/lib/CodeGen/CGDebugInfo.h =================================================================== --- clang/lib/CodeGen/CGDebugInfo.h +++ clang/lib/CodeGen/CGDebugInfo.h @@ -164,6 +164,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 @@ -816,6 +816,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; @@ -2867,7 +2871,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(); @@ -2914,6 +2919,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."); @@ -2935,7 +2944,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()) { @@ -2976,7 +2986,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; @@ -3090,6 +3101,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() { +} Index: llvm/test/DebugInfo/X86/debug-info-auto-return.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/X86/debug-info-auto-return.ll @@ -0,0 +1,66 @@ +;RUN: %llc_dwarf %s -filetype=obj -o - | llvm-dwarfdump -v - | FileCheck %s + +; C++ source to regenerate: + +;struct myClass { +; auto findMax(); +;}; + +;auto myClass::findMax() { +;} + +; CHECK: .debug_info contents: + +; CHECK: DW_TAG_subprogram [3] * +; CHECK-NEXT: DW_AT_linkage_name {{.*}} string = "_ZN7myClass7findMaxEv") +; CHECK: DW_AT_type [DW_FORM_ref4] {{.*}} "auto" +; CHECK-NEXT: DW_AT_declaration {{.*}} (true) + +; CHECK: DW_TAG_unspecified_type +; CHECK-NEXT: DW_AT_name [DW_FORM_strx1] {{.*}} "auto" + +; ModuleID = 'debug-info-auto-return.cpp' +source_filename = "debug-info-auto-return.cpp" +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +%struct.myClass = type { i8 } + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local void @_ZN7myClass7findMaxEv(%struct.myClass* %this) #0 align 2 !dbg !7 { +entry: + %this.addr = alloca %struct.myClass*, align 8 + store %struct.myClass* %this, %struct.myClass** %this.addr, align 8 + call void @llvm.dbg.declare(metadata %struct.myClass** %this.addr, metadata !14, metadata !DIExpression()), !dbg !16 + %this1 = load %struct.myClass*, %struct.myClass** %this.addr, align 8 + ret void, !dbg !17 +} + +; Function Attrs: nounwind readnone speculatable willreturn +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind readnone speculatable willreturn } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 10.0.0 (https://github.com/llvm/llvm-project.git 31848e839e485b9a295a2aa86fc7bac3e8403a94)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "debug-info-auto-return.cpp", directory: "/home/awpandey/tools/upstream/llvm-project/clang/test/CodeGenCXX", checksumkind: CSK_MD5, checksum: "00e6551e106a871d393b61752d94cc0c") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 5} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 4} +!6 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git 31848e839e485b9a295a2aa86fc7bac3e8403a94)"} +!7 = distinct !DISubprogram(name: "findMax", linkageName: "_ZN7myClass7findMaxEv", scope: !8, file: !1, line: 16, type: !9, scopeLine: 16, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !13, retainedNodes: !2) +!8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "myClass", file: !1, line: 12, size: 8, flags: DIFlagTypePassByValue, elements: !2, identifier: "_ZTS7myClass") +!9 = !DISubroutineType(types: !10) +!10 = !{!11, !12} +!11 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "auto") +!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!13 = !DISubprogram(name: "findMax", linkageName: "_ZN7myClass7findMaxEv", scope: !8, file: !1, line: 13, type: !9, scopeLine: 13, flags: DIFlagPrototyped, spFlags: 0) +!14 = !DILocalVariable(name: "this", arg: 1, scope: !7, type: !15, flags: DIFlagArtificial | DIFlagObjectPointer) +!15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64) +!16 = !DILocation(line: 0, scope: !7) +!17 = !DILocation(line: 17, column: 1, scope: !7)