awpandey updated this revision to Diff 230601. awpandey marked 3 inline comments as done. awpandey added a comment.
This revision includes 1. Added check for return type it is attached to the exact node we're expecting it to. 2. Removed unnecessary strings and checks. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D70524/new/ https://reviews.llvm.org/D70524 Files: clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CGDebugInfo.h clang/test/CodeGenCXX/debug-info-auto-return.cpp llvm/test/DebugInfo/X86/debug-info-auto-return.ll
Index: llvm/test/DebugInfo/X86/debug-info-auto-return.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/X86/debug-info-auto-return.ll @@ -0,0 +1,171 @@ +;RUN: %llc_dwarf %s -filetype=obj -o - | llvm-dwarfdump -v - | FileCheck %s + +; C++ source to regenerate: + +;class myClass { +; int low, high; +; +; public: +; myClass(int a, int b) { +; low = a; +; high = b; +; } +; auto findMax(); +;}; +; +;auto myClass::findMax() { +; if (low > high) +; return 1; +; else +; return 1; +;} +;int main() { +; myClass f(3, 5); +; return 0; +;} + +; CHECK: .debug_info contents: + +; CHECK: DW_TAG_subprogram [7] * +; CHECK-NEXT: DW_AT_linkage_name [DW_FORM_strx1] (indexed (00000007) 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" + +%class.myClass = type { i32, i32 } + +$_ZN7myClassC2Eii = comdat any + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local i32 @_ZN7myClass7findMaxEv(%class.myClass* %this) #0 align 2 !dbg !7 { +entry: + %retval = alloca i32, align 4 + %this.addr = alloca %class.myClass*, align 8 + store %class.myClass* %this, %class.myClass** %this.addr, align 8 + call void @llvm.dbg.declare(metadata %class.myClass** %this.addr, metadata !22, metadata !DIExpression()), !dbg !24 + %this1 = load %class.myClass*, %class.myClass** %this.addr, align 8 + %low = getelementptr inbounds %class.myClass, %class.myClass* %this1, i32 0, i32 0, !dbg !25 + %0 = load i32, i32* %low, align 4, !dbg !25 + %high = getelementptr inbounds %class.myClass, %class.myClass* %this1, i32 0, i32 1, !dbg !27 + %1 = load i32, i32* %high, align 4, !dbg !27 + %cmp = icmp sgt i32 %0, %1, !dbg !28 + br i1 %cmp, label %if.then, label %if.else, !dbg !29 + +if.then: ; preds = %entry + store i32 1, i32* %retval, align 4, !dbg !30 + br label %return, !dbg !30 + +if.else: ; preds = %entry + store i32 1, i32* %retval, align 4, !dbg !31 + br label %return, !dbg !31 + +return: ; preds = %if.else, %if.then + %2 = load i32, i32* %retval, align 4, !dbg !32 + ret i32 %2, !dbg !32 +} + +; Function Attrs: nounwind readnone speculatable willreturn +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +; Function Attrs: noinline norecurse optnone uwtable +define dso_local i32 @main() #2 !dbg !33 { +entry: + %retval = alloca i32, align 4 + %f = alloca %class.myClass, align 4 + store i32 0, i32* %retval, align 4 + call void @llvm.dbg.declare(metadata %class.myClass* %f, metadata !36, metadata !DIExpression()), !dbg !37 + call void @_ZN7myClassC2Eii(%class.myClass* %f, i32 3, i32 5), !dbg !37 + ret i32 0, !dbg !38 +} + +; Function Attrs: noinline nounwind optnone uwtable +define linkonce_odr dso_local void @_ZN7myClassC2Eii(%class.myClass* %this, i32 %a, i32 %b) unnamed_addr #0 comdat align 2 !dbg !39 { +entry: + %this.addr = alloca %class.myClass*, align 8 + %a.addr = alloca i32, align 4 + %b.addr = alloca i32, align 4 + store %class.myClass* %this, %class.myClass** %this.addr, align 8 + call void @llvm.dbg.declare(metadata %class.myClass** %this.addr, metadata !40, metadata !DIExpression()), !dbg !41 + store i32 %a, i32* %a.addr, align 4 + call void @llvm.dbg.declare(metadata i32* %a.addr, metadata !42, metadata !DIExpression()), !dbg !43 + store i32 %b, i32* %b.addr, align 4 + call void @llvm.dbg.declare(metadata i32* %b.addr, metadata !44, metadata !DIExpression()), !dbg !45 + %this1 = load %class.myClass*, %class.myClass** %this.addr, align 8 + %0 = load i32, i32* %a.addr, align 4, !dbg !46 + %low = getelementptr inbounds %class.myClass, %class.myClass* %this1, i32 0, i32 0, !dbg !48 + store i32 %0, i32* %low, align 4, !dbg !49 + %1 = load i32, i32* %b.addr, align 4, !dbg !50 + %high = getelementptr inbounds %class.myClass, %class.myClass* %this1, i32 0, i32 1, !dbg !51 + store i32 %1, i32* %high, align 4, !dbg !52 + ret void, !dbg !53 +} + +attributes #0 = { noinline nounwind optnone uwtable } +attributes #1 = { nounwind readnone speculatable willreturn } +attributes #2 = { noinline norecurse optnone uwtable } + +!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 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "test.cpp", directory: "/dir", checksumkind: CSK_MD5, checksum: "5dbf55384559401c20c259c1db376af2") +!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 "} +!7 = distinct !DISubprogram(name: "findMax", linkageName: "_ZN7myClass7findMaxEv", scope: !9, file: !8, line: 21, type: !18, scopeLine: 21, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !21, retainedNodes: !2) +!8 = !DIFile(filename: "test.cpp", directory: "/dir", checksumkind: CSK_MD5, checksum: "5dbf55384559401c20c259c1db376af2") +!9 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "myClass", file: !8, line: 10, size: 64, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: !10, identifier: "_ZTS7myClass") +!10 = !{!11, !13, !14} +!11 = !DIDerivedType(tag: DW_TAG_member, name: "low", scope: !9, file: !8, line: 11, baseType: !12, size: 32) +!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!13 = !DIDerivedType(tag: DW_TAG_member, name: "high", scope: !9, file: !8, line: 11, baseType: !12, size: 32, offset: 32) +!14 = !DISubprogram(name: "myClass", scope: !9, file: !8, line: 14, type: !15, scopeLine: 14, flags: DIFlagPublic | DIFlagPrototyped, spFlags: 0) +!15 = !DISubroutineType(types: !16) +!16 = !{null, !17, !12, !12} +!17 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!18 = !DISubroutineType(types: !19) +!19 = !{!20, !17} +!20 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "auto") +!21 = !DISubprogram(name: "findMax", linkageName: "_ZN7myClass7findMaxEv", scope: !9, file: !8, line: 18, type: !18, scopeLine: 18, flags: DIFlagPublic | DIFlagPrototyped, spFlags: 0) +!22 = !DILocalVariable(name: "this", arg: 1, scope: !7, type: !23, flags: DIFlagArtificial | DIFlagObjectPointer) +!23 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64) +!24 = !DILocation(line: 0, scope: !7) +!25 = !DILocation(line: 22, column: 7, scope: !26) +!26 = distinct !DILexicalBlock(scope: !7, file: !8, line: 22, column: 7) +!27 = !DILocation(line: 22, column: 13, scope: !26) +!28 = !DILocation(line: 22, column: 11, scope: !26) +!29 = !DILocation(line: 22, column: 7, scope: !7) +!30 = !DILocation(line: 23, column: 5, scope: !26) +!31 = !DILocation(line: 25, column: 5, scope: !26) +!32 = !DILocation(line: 26, column: 1, scope: !7) +!33 = distinct !DISubprogram(name: "main", scope: !8, file: !8, line: 27, type: !34, scopeLine: 27, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!34 = !DISubroutineType(types: !35) +!35 = !{!12} +!36 = !DILocalVariable(name: "f", scope: !33, file: !8, line: 28, type: !9) +!37 = !DILocation(line: 28, column: 11, scope: !33) +!38 = !DILocation(line: 29, column: 3, scope: !33) +!39 = distinct !DISubprogram(name: "myClass", linkageName: "_ZN7myClassC2Eii", scope: !9, file: !8, line: 14, type: !15, scopeLine: 14, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !14, retainedNodes: !2) +!40 = !DILocalVariable(name: "this", arg: 1, scope: !39, type: !23, flags: DIFlagArtificial | DIFlagObjectPointer) +!41 = !DILocation(line: 0, scope: !39) +!42 = !DILocalVariable(name: "a", arg: 2, scope: !39, file: !8, line: 14, type: !12) +!43 = !DILocation(line: 14, column: 15, scope: !39) +!44 = !DILocalVariable(name: "b", arg: 3, scope: !39, file: !8, line: 14, type: !12) +!45 = !DILocation(line: 14, column: 22, scope: !39) +!46 = !DILocation(line: 15, column: 11, scope: !47) +!47 = distinct !DILexicalBlock(scope: !39, file: !8, line: 14, column: 25) +!48 = !DILocation(line: 15, column: 5, scope: !47) +!49 = !DILocation(line: 15, column: 9, scope: !47) +!50 = !DILocation(line: 16, column: 12, scope: !47) +!51 = !DILocation(line: 16, column: 5, scope: !47) +!52 = !DILocation(line: 16, column: 10, scope: !47) +!53 = !DILocation(line: 17, column: 3, scope: !39) Index: clang/test/CodeGenCXX/debug-info-auto-return.cpp =================================================================== --- /dev/null +++ clang/test/CodeGenCXX/debug-info-auto-return.cpp @@ -0,0 +1,32 @@ +// 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: !18 +// CHECK: !18 = !DISubroutineType(types: !19) +// CHECK: !19 = !{!20, !17} +// CHECK: !20 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "auto") + +class myClass { + int low, high; + +public: + myClass(int a, int b) { + low = a; + high = b; + } + auto findMax(); +}; + +auto myClass::findMax() { + if (low > high) + return 1; + else + return 1; +} +int main() { + myClass f(3, 5); + return 0; +} 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 @@ -817,6 +817,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; @@ -2868,7 +2872,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(); @@ -2915,6 +2920,9 @@ T = cast<SubstTemplateTypeParmType>(T)->getReplacementType(); break; case Type::Auto: + if (dwarfVersion >= 5) { + return C.getQualifiedType(T.getTypePtr(), Quals); + } case Type::DeducedTemplateSpecialization: { QualType DT = cast<DeducedType>(T)->getDeducedType(); assert(!DT.isNull() && "Undeduced types shouldn't reach here."); @@ -2936,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()) { @@ -2977,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; @@ -3091,6 +3101,9 @@ return CreateType(cast<TemplateSpecializationType>(Ty), Unit); case Type::Auto: + if (CGM.getCodeGenOpts().DwarfVersion >= 5) { + return CreateType(cast<AutoType>(Ty)); + } case Type::Attributed: case Type::Adjusted: case Type::Decayed:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits