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, @@ -214,10 +215,10 @@ /// not updated to include implicit \c this pointer. Use this routine /// to get a method type which includes \c this pointer. llvm::DISubroutineType *getOrCreateMethodType(const CXXMethodDecl *Method, - llvm::DIFile *F); + llvm::DIFile *F, bool decl); llvm::DISubroutineType * getOrCreateInstanceMethodType(QualType ThisPtr, const FunctionProtoType *Func, - llvm::DIFile *Unit); + llvm::DIFile *Unit, bool decl); llvm::DISubroutineType * getOrCreateFunctionType(const Decl *D, QualType FnType, llvm::DIFile *F); /// \return debug info descriptor for vtable. 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; @@ -1457,16 +1461,18 @@ llvm::DISubroutineType * CGDebugInfo::getOrCreateMethodType(const CXXMethodDecl *Method, - llvm::DIFile *Unit) { + llvm::DIFile *Unit, bool decl) { const FunctionProtoType *Func = Method->getType()->getAs(); if (Method->isStatic()) return cast_or_null( getOrCreateType(QualType(Func, 0), Unit)); - return getOrCreateInstanceMethodType(Method->getThisType(), Func, Unit); + return getOrCreateInstanceMethodType(Method->getThisType(), Func, Unit, decl); } -llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType( - QualType ThisPtr, const FunctionProtoType *Func, llvm::DIFile *Unit) { +llvm::DISubroutineType * +CGDebugInfo::getOrCreateInstanceMethodType(QualType ThisPtr, + const FunctionProtoType *Func, + llvm::DIFile *Unit, bool decl) { // Add "this" pointer. llvm::DITypeRefArray Args( cast(getOrCreateType(QualType(Func, 0), Unit)) @@ -1474,9 +1480,12 @@ assert(Args.size() && "Invalid number of arguments!"); SmallVector Elts; - // First element is always return type. For 'void' functions it is NULL. - Elts.push_back(Args[0]); + QualType temp = Func->getReturnType(); + if (temp->getTypeClass() == Type::Auto && decl) + Elts.push_back(CreateType(cast(temp))); + else + Elts.push_back(Args[0]); // "this" pointer is always first argument. const CXXRecordDecl *RD = ThisPtr->getPointeeCXXRecordDecl(); @@ -1535,7 +1544,7 @@ isa(Method) || isa(Method); StringRef MethodName = getFunctionName(Method); - llvm::DISubroutineType *MethodTy = getOrCreateMethodType(Method, Unit); + llvm::DISubroutineType *MethodTy = getOrCreateMethodType(Method, Unit, true); // Since a single ctor/dtor corresponds to multiple functions, it doesn't // make sense to give a single ctor/dtor a linkage name. @@ -2754,7 +2763,7 @@ return DBuilder.createMemberPointerType( getOrCreateInstanceMethodType( CXXMethodDecl::getThisType(FPT, Ty->getMostRecentCXXRecordDecl()), - FPT, U), + FPT, U, false), ClassType, Size, /*Align=*/0, Flags); } @@ -3529,7 +3538,7 @@ return DBuilder.createSubroutineType(DBuilder.getOrCreateTypeArray(None)); if (const auto *Method = dyn_cast(D)) - return getOrCreateMethodType(Method, F); + return getOrCreateMethodType(Method, F, false); const auto *FTy = FnType->getAs(); CallingConv CC = FTy ? FTy->getCallConv() : CallingConv::CC_C; Index: clang/test/CodeGenCXX/debug-info-auto-return.cpp =================================================================== --- /dev/null +++ clang/test/CodeGenCXX/debug-info-auto-return.cpp @@ -0,0 +1,22 @@ +// 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: ![[FUN_TYPE:[0-9]+]],{{.*}} + +// CHECK: ![[FUN_TYPE]] = !DISubroutineType(types: ![[TYPE_NODE:[0-9]+]]) +// CHECK-NEXT: ![[TYPE_NODE]] = !{![[DOUBLE_TYPE:[0-9]+]], {{.*}} +// CHECK-NEXT: ![[DOUBLE_TYPE]] = !DIBasicType(name: "double", {{.*}}) + +// CHECK: !DISubroutineType(types: ![[TYPE_DECL_NODE:[0-9]+]]) +// CHECK-NEXT: ![[TYPE_DECL_NODE]] = !{![[AUTO_TYPE:[0-9]+]], {{.*}} +// CHECK-NEXT: ![[AUTO_TYPE]] = !DIBasicType(tag: DW_TAG_unspecified_type, name: "auto") +struct myClass { + auto findMax(); +}; + +auto myClass::findMax() { + return 0.0; +} Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -1165,6 +1165,14 @@ DIE *DeclDie = nullptr; StringRef DeclLinkageName; if (auto *SPDecl = SP->getDeclaration()) { + DITypeRefArray DeclArgs, DefinationArgs; + DeclArgs = SPDecl->getType()->getTypeArray(); + DefinationArgs = SP->getType()->getTypeArray(); + + if (DeclArgs.size() && DefinationArgs.size()) + if (DeclArgs[0] != DefinationArgs[0]) + addType(SPDie, DefinationArgs[0]); + DeclDie = getDIE(SPDecl); assert(DeclDie && "This DIE should've already been constructed when the " "definition DIE was created in " Index: llvm/test/DebugInfo/X86/debug-info-auto-return.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/X86/debug-info-auto-return.ll @@ -0,0 +1,70 @@ +; RUN: llc %s -filetype=obj -o - | llvm-dwarfdump -v - | FileCheck %s + +; CHECK: .debug_info contents: + +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT_linkage_name [DW_FORM_strx1] (indexed {{.*}} string = "_ZN7myClass7findMaxEv") +; CHECK: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} "auto") +; CHECK-NEXT: DW_AT_declaration [DW_FORM_flag_present] (true) + +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} "double") +; CHECK: DW_AT_specification [DW_FORM_ref4] (cu + {{.*}} "_ZN7myClass7findMaxEv") + +; C++ source to regenerate: +; struct myClass { +; auto findMax(); +; }; +; +; auto myClass::findMax() { +; return 0.0; +; } + +; $ clang++ -O0 -g -gdwarf-5 debug-info-template-align.cpp -c + +; ModuleID = '/dir/test.cpp' +source_filename = "/dir/test.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 double @_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 !17, metadata !DIExpression()), !dbg !19 + %this1 = load %struct.myClass*, %struct.myClass** %this.addr, align 8 + ret double 0.000000e+00, !dbg !20 +} +; Function Attrs: nounwind readnone speculatable willreturn +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +attributes #0 = { noinline nounwind optnone uwtable } +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", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None) +!1 = !DIFile(filename: "/dir/test.cpp", directory: "/dir/", checksumkind: CSK_MD5, checksum: "4bed8955bd441e3129c12f557ed53962") +!2 = !{} +!3 = !{i32 7, !"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: !8, file: !1, line: 20, type: !9, scopeLine: 20, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !13, retainedNodes: !2) +!8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "myClass", file: !1, line: 16, size: 8, flags: DIFlagTypePassByValue, elements: !2, identifier: "_ZTS7myClass") +!9 = !DISubroutineType(types: !10) +!10 = !{!11, !12} +!11 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float) +!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: 17, type: !14, scopeLine: 17, flags: DIFlagPrototyped, spFlags: 0) +!14 = !DISubroutineType(types: !15) +!15 = !{!16, !12} +!16 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "auto") +!17 = !DILocalVariable(name: "this", arg: 1, scope: !7, type: !18, flags: DIFlagArtificial | DIFlagObjectPointer) +!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64) +!19 = !DILocation(line: 0, scope: !7) +!20 = !DILocation(line: 21, column: 3, scope: !7)