shafik created this revision.
shafik added reviewers: aprantl, teemperor, labath.
Herald added a subscriber: arphaman.
shafik requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

Currently when we have a member function that has an auto return type and the 
definition is out of line we generate two DWARF DIE. 
One for the declaration and a second one for the definition, the definition 
holds the deduced type but does not contain a DW_AT_name nor
a DW_AT_linkage_name so there was not way to look up the definition DIE.

This fix modifies `CGDebugInfo::CreateCXXMemberFunction` so that it now only 
emits the linkage name for the definition of a method with a
deduced return type. It also modifies the `DWARFASTParserClang` to detect we 
have a function with deduced return type and lookup the 
defintion to obtain the correct return type and adjust the `FunctionDecl` to 
reflect this.

This required modifying the various indexes to support a lookup method for this 
case similar to `FindCompleteObjCDefinitionTypeForDIE`


https://reviews.llvm.org/D105564

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
  lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
  lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
  lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
  lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
  lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/test/Shell/SymbolFile/DWARF/x86/auto_return_appleDwarfIndex.s
  lldb/test/Shell/SymbolFile/DWARF/x86/auto_return_manualDwarfIndex.s

Index: lldb/test/Shell/SymbolFile/DWARF/x86/auto_return_manualDwarfIndex.s
===================================================================
--- /dev/null
+++ lldb/test/Shell/SymbolFile/DWARF/x86/auto_return_manualDwarfIndex.s
@@ -0,0 +1,255 @@
+# This tests that lldb when using ManualDWARFIndex is able to find the definition
+# for an auto return function.
+
+# RUN: llvm-mc -triple x86_64-gnu-linux %s -filetype=obj > %t.o
+# RUN: lldb-test symbols --dump-clang-ast %t.o | FileCheck %s
+
+# CHECK: CXXMethodDecl {{.*}} <<invalid sloc>> <invalid sloc> f 'int ()'
+
+# This was compiled from the following code:
+#
+# struct A {
+#     auto f();
+# };
+#
+# auto A::f() {
+#     return 0;
+# }
+#
+# Compiled using:
+#
+#   -target x86_64-gnu-linux
+
+
+	.text
+	.globl	_ZN1A1fEv                       # -- Begin function _ZN1A1fEv
+	.p2align	4, 0x90
+	.type	_ZN1A1fEv,@function
+_ZN1A1fEv:                              # @_ZN1A1fEv
+.Lfunc_begin0:
+	.cfi_startproc
+# %bb.0:                                # %entry
+	pushq	%rbp
+	.cfi_def_cfa_offset 16
+	.cfi_offset %rbp, -16
+	movq	%rsp, %rbp
+	.cfi_def_cfa_register %rbp
+	movq	%rdi, -8(%rbp)
+.Ltmp0:
+	xorl	%eax, %eax
+	popq	%rbp
+	.cfi_def_cfa %rsp, 8
+	retq
+.Ltmp1:
+.Lfunc_end0:
+	.size	_ZN1A1fEv, .Lfunc_end0-_ZN1A1fEv
+	.cfi_endproc
+                                        # -- End function
+	.section	.debug_abbrev,"",@progbits
+	.byte	1                               # Abbreviation Code
+	.byte	17                              # DW_TAG_compile_unit
+	.byte	1                               # DW_CHILDREN_yes
+	.byte	37                              # DW_AT_producer
+	.byte	14                              # DW_FORM_strp
+	.byte	19                              # DW_AT_language
+	.byte	5                               # DW_FORM_data2
+	.byte	3                               # DW_AT_name
+	.byte	14                              # DW_FORM_strp
+	.byte	16                              # DW_AT_stmt_list
+	.byte	23                              # DW_FORM_sec_offset
+	.byte	27                              # DW_AT_comp_dir
+	.byte	14                              # DW_FORM_strp
+	.byte	17                              # DW_AT_low_pc
+	.byte	1                               # DW_FORM_addr
+	.byte	18                              # DW_AT_high_pc
+	.byte	6                               # DW_FORM_data4
+	.byte	0                               # EOM(1)
+	.byte	0                               # EOM(2)
+	.byte	2                               # Abbreviation Code
+	.byte	19                              # DW_TAG_structure_type
+	.byte	1                               # DW_CHILDREN_yes
+	.byte	54                              # DW_AT_calling_convention
+	.byte	11                              # DW_FORM_data1
+	.byte	3                               # DW_AT_name
+	.byte	14                              # DW_FORM_strp
+	.byte	11                              # DW_AT_byte_size
+	.byte	11                              # DW_FORM_data1
+	.byte	58                              # DW_AT_decl_file
+	.byte	11                              # DW_FORM_data1
+	.byte	59                              # DW_AT_decl_line
+	.byte	11                              # DW_FORM_data1
+	.byte	0                               # EOM(1)
+	.byte	0                               # EOM(2)
+	.byte	3                               # Abbreviation Code
+	.byte	46                              # DW_TAG_subprogram
+	.byte	1                               # DW_CHILDREN_yes
+	.byte	3                               # DW_AT_name
+	.byte	14                              # DW_FORM_strp
+	.byte	58                              # DW_AT_decl_file
+	.byte	11                              # DW_FORM_data1
+	.byte	59                              # DW_AT_decl_line
+	.byte	11                              # DW_FORM_data1
+	.byte	73                              # DW_AT_type
+	.byte	19                              # DW_FORM_ref4
+	.byte	60                              # DW_AT_declaration
+	.byte	25                              # DW_FORM_flag_present
+	.byte	63                              # DW_AT_external
+	.byte	25                              # DW_FORM_flag_present
+	.byte	0                               # EOM(1)
+	.byte	0                               # EOM(2)
+	.byte	4                               # Abbreviation Code
+	.byte	5                               # DW_TAG_formal_parameter
+	.byte	0                               # DW_CHILDREN_no
+	.byte	73                              # DW_AT_type
+	.byte	19                              # DW_FORM_ref4
+	.byte	52                              # DW_AT_artificial
+	.byte	25                              # DW_FORM_flag_present
+	.byte	0                               # EOM(1)
+	.byte	0                               # EOM(2)
+	.byte	5                               # Abbreviation Code
+	.byte	59                              # DW_TAG_unspecified_type
+	.byte	0                               # DW_CHILDREN_no
+	.byte	3                               # DW_AT_name
+	.byte	14                              # DW_FORM_strp
+	.byte	0                               # EOM(1)
+	.byte	0                               # EOM(2)
+	.byte	6                               # Abbreviation Code
+	.byte	15                              # DW_TAG_pointer_type
+	.byte	0                               # DW_CHILDREN_no
+	.byte	73                              # DW_AT_type
+	.byte	19                              # DW_FORM_ref4
+	.byte	0                               # EOM(1)
+	.byte	0                               # EOM(2)
+	.byte	7                               # Abbreviation Code
+	.byte	46                              # DW_TAG_subprogram
+	.byte	1                               # DW_CHILDREN_yes
+	.byte	17                              # DW_AT_low_pc
+	.byte	1                               # DW_FORM_addr
+	.byte	18                              # DW_AT_high_pc
+	.byte	6                               # DW_FORM_data4
+	.byte	64                              # DW_AT_frame_base
+	.byte	24                              # DW_FORM_exprloc
+	.byte	100                             # DW_AT_object_pointer
+	.byte	19                              # DW_FORM_ref4
+	.byte	73                              # DW_AT_type
+	.byte	19                              # DW_FORM_ref4
+	.byte	59                              # DW_AT_decl_line
+	.byte	11                              # DW_FORM_data1
+	.byte	110                             # DW_AT_linkage_name
+	.byte	14                              # DW_FORM_strp
+	.byte	71                              # DW_AT_specification
+	.byte	19                              # DW_FORM_ref4
+	.byte	0                               # EOM(1)
+	.byte	0                               # EOM(2)
+	.byte	8                               # Abbreviation Code
+	.byte	5                               # DW_TAG_formal_parameter
+	.byte	0                               # DW_CHILDREN_no
+	.byte	2                               # DW_AT_location
+	.byte	24                              # DW_FORM_exprloc
+	.byte	3                               # DW_AT_name
+	.byte	14                              # DW_FORM_strp
+	.byte	73                              # DW_AT_type
+	.byte	19                              # DW_FORM_ref4
+	.byte	52                              # DW_AT_artificial
+	.byte	25                              # DW_FORM_flag_present
+	.byte	0                               # EOM(1)
+	.byte	0                               # EOM(2)
+	.byte	9                               # Abbreviation Code
+	.byte	36                              # DW_TAG_base_type
+	.byte	0                               # DW_CHILDREN_no
+	.byte	3                               # DW_AT_name
+	.byte	14                              # DW_FORM_strp
+	.byte	62                              # DW_AT_encoding
+	.byte	11                              # DW_FORM_data1
+	.byte	11                              # DW_AT_byte_size
+	.byte	11                              # DW_FORM_data1
+	.byte	0                               # EOM(1)
+	.byte	0                               # EOM(2)
+	.byte	0                               # EOM(3)
+	.section	.debug_info,"",@progbits
+.Lcu_begin0:
+	.long	.Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
+.Ldebug_info_start0:
+	.short	4                               # DWARF version number
+	.long	.debug_abbrev                   # Offset Into Abbrev. Section
+	.byte	8                               # Address Size (in bytes)
+	.byte	1                               # Abbrev [1] 0xb:0x7e DW_TAG_compile_unit
+	.long	.Linfo_string0                  # DW_AT_producer
+	.short	33                              # DW_AT_language
+	.long	.Linfo_string1                  # DW_AT_name
+	.long	.Lline_table_start0             # DW_AT_stmt_list
+	.long	.Linfo_string2                  # DW_AT_comp_dir
+	.quad	.Lfunc_begin0                   # DW_AT_low_pc
+	.long	.Lfunc_end0-.Lfunc_begin0       # DW_AT_high_pc
+	.byte	2                               # Abbrev [2] 0x2a:0x1b DW_TAG_structure_type
+	.byte	5                               # DW_AT_calling_convention
+	.long	.Linfo_string3                  # DW_AT_name
+	.byte	1                               # DW_AT_byte_size
+	.byte	1                               # DW_AT_decl_file
+	.byte	1                               # DW_AT_decl_line
+	.byte	3                               # Abbrev [3] 0x33:0x11 DW_TAG_subprogram
+	.long	.Linfo_string4                  # DW_AT_name
+	.byte	1                               # DW_AT_decl_file
+	.byte	2                               # DW_AT_decl_line
+	.long	69                              # DW_AT_type
+                                        # DW_AT_declaration
+                                        # DW_AT_external
+	.byte	4                               # Abbrev [4] 0x3e:0x5 DW_TAG_formal_parameter
+	.long	74                              # DW_AT_type
+                                        # DW_AT_artificial
+	.byte	0                               # End Of Children Mark
+	.byte	0                               # End Of Children Mark
+	.byte	5                               # Abbrev [5] 0x45:0x5 DW_TAG_unspecified_type
+	.long	.Linfo_string5                  # DW_AT_name
+	.byte	6                               # Abbrev [6] 0x4a:0x5 DW_TAG_pointer_type
+	.long	42                              # DW_AT_type
+	.byte	7                               # Abbrev [7] 0x4f:0x2d DW_TAG_subprogram
+	.quad	.Lfunc_begin0                   # DW_AT_low_pc
+	.long	.Lfunc_end0-.Lfunc_begin0       # DW_AT_high_pc
+	.byte	1                               # DW_AT_frame_base
+	.byte	86
+	.long	111                             # DW_AT_object_pointer
+	.long	124                             # DW_AT_type
+	.byte	5                               # DW_AT_decl_line
+	.long	.Linfo_string7                  # DW_AT_linkage_name
+	.long	51                              # DW_AT_specification
+	.byte	8                               # Abbrev [8] 0x6f:0xc DW_TAG_formal_parameter
+	.byte	2                               # DW_AT_location
+	.byte	145
+	.byte	120
+	.long	.Linfo_string8                  # DW_AT_name
+	.long	131                             # DW_AT_type
+                                        # DW_AT_artificial
+	.byte	0                               # End Of Children Mark
+	.byte	9                               # Abbrev [9] 0x7c:0x7 DW_TAG_base_type
+	.long	.Linfo_string6                  # DW_AT_name
+	.byte	5                               # DW_AT_encoding
+	.byte	4                               # DW_AT_byte_size
+	.byte	6                               # Abbrev [6] 0x83:0x5 DW_TAG_pointer_type
+	.long	42                              # DW_AT_type
+	.byte	0                               # End Of Children Mark
+.Ldebug_info_end0:
+	.section	.debug_str,"MS",@progbits,1
+.Linfo_string0:
+	.asciz	"clang version 13.0.0 (https://github.com/llvm/llvm-project.git 18c3c7784975700ae463bb461487d46e74324a66)" # string offset=0
+.Linfo_string1:
+	.asciz	"auto_return_minimum.cpp"       # string offset=105
+.Linfo_string2:
+	.asciz	"/Users/shafik/code"            # string offset=129
+.Linfo_string3:
+	.asciz	"A"                             # string offset=148
+.Linfo_string4:
+	.asciz	"f"                             # string offset=150
+.Linfo_string5:
+	.asciz	"auto"                          # string offset=152
+.Linfo_string6:
+	.asciz	"int"                           # string offset=157
+.Linfo_string7:
+	.asciz	"_ZN1A1fEv"                     # string offset=161
+.Linfo_string8:
+	.asciz	"this"                          # string offset=171
+	.ident	"clang version 13.0.0 (https://github.com/llvm/llvm-project.git 18c3c7784975700ae463bb461487d46e74324a66)"
+	.section	".note.GNU-stack","",@progbits
+	.addrsig
+	.section	.debug_line,"",@progbits
+.Lline_table_start0:
Index: lldb/test/Shell/SymbolFile/DWARF/x86/auto_return_appleDwarfIndex.s
===================================================================
--- /dev/null
+++ lldb/test/Shell/SymbolFile/DWARF/x86/auto_return_appleDwarfIndex.s
@@ -0,0 +1,309 @@
+# This tests that lldb when using AppleDWARFIndex is able to find the definition
+# for an auto return function.
+
+# RUN: llvm-mc -triple x86_64-apple-macosx10.15.0 %s -filetype=obj > %t.o
+# RUN: lldb-test symbols --dump-clang-ast %t.o | FileCheck %s
+
+# CHECK: CXXMethodDecl {{.*}} <<invalid sloc>> <invalid sloc> f 'int ()'
+
+# This was compiled from the following code:
+#
+# struct A {
+#     auto f();
+# };
+#
+# auto A::f() {
+#     return 0;
+# }
+#
+# Compiled using:
+#
+#  -target x86_64-apple-macosx10.15.0
+
+
+	.section	__TEXT,__text,regular,pure_instructions
+	.globl	__ZN1A1fEv                      ## -- Begin function _ZN1A1fEv
+	.p2align	4, 0x90
+__ZN1A1fEv:                             ## @_ZN1A1fEv
+Lfunc_begin0:
+	.cfi_startproc
+## %bb.0:                               ## %entry
+	pushq	%rbp
+	.cfi_def_cfa_offset 16
+	.cfi_offset %rbp, -16
+	movq	%rsp, %rbp
+	.cfi_def_cfa_register %rbp
+	movq	%rdi, -8(%rbp)
+Ltmp0:
+	xorl	%eax, %eax
+	popq	%rbp
+	retq
+Ltmp1:
+Lfunc_end0:
+	.cfi_endproc
+                                        ## -- End function
+	.section	__DWARF,__debug_abbrev,regular,debug
+Lsection_abbrev:
+	.byte	1                               ## Abbreviation Code
+	.byte	17                              ## DW_TAG_compile_unit
+	.byte	1                               ## DW_CHILDREN_yes
+	.byte	37                              ## DW_AT_producer
+	.byte	14                              ## DW_FORM_strp
+	.byte	19                              ## DW_AT_language
+	.byte	5                               ## DW_FORM_data2
+	.byte	3                               ## DW_AT_name
+	.byte	14                              ## DW_FORM_strp
+	.ascii	"\202|"                         ## DW_AT_LLVM_sysroot
+	.byte	14                              ## DW_FORM_strp
+	.ascii	"\357\177"                      ## DW_AT_APPLE_sdk
+	.byte	14                              ## DW_FORM_strp
+	.byte	16                              ## DW_AT_stmt_list
+	.byte	23                              ## DW_FORM_sec_offset
+	.byte	27                              ## DW_AT_comp_dir
+	.byte	14                              ## DW_FORM_strp
+	.byte	17                              ## DW_AT_low_pc
+	.byte	1                               ## DW_FORM_addr
+	.byte	18                              ## DW_AT_high_pc
+	.byte	6                               ## DW_FORM_data4
+	.byte	0                               ## EOM(1)
+	.byte	0                               ## EOM(2)
+	.byte	2                               ## Abbreviation Code
+	.byte	19                              ## DW_TAG_structure_type
+	.byte	1                               ## DW_CHILDREN_yes
+	.byte	54                              ## DW_AT_calling_convention
+	.byte	11                              ## DW_FORM_data1
+	.byte	3                               ## DW_AT_name
+	.byte	14                              ## DW_FORM_strp
+	.byte	11                              ## DW_AT_byte_size
+	.byte	11                              ## DW_FORM_data1
+	.byte	58                              ## DW_AT_decl_file
+	.byte	11                              ## DW_FORM_data1
+	.byte	59                              ## DW_AT_decl_line
+	.byte	11                              ## DW_FORM_data1
+	.byte	0                               ## EOM(1)
+	.byte	0                               ## EOM(2)
+	.byte	3                               ## Abbreviation Code
+	.byte	46                              ## DW_TAG_subprogram
+	.byte	1                               ## DW_CHILDREN_yes
+	.byte	3                               ## DW_AT_name
+	.byte	14                              ## DW_FORM_strp
+	.byte	58                              ## DW_AT_decl_file
+	.byte	11                              ## DW_FORM_data1
+	.byte	59                              ## DW_AT_decl_line
+	.byte	11                              ## DW_FORM_data1
+	.byte	73                              ## DW_AT_type
+	.byte	19                              ## DW_FORM_ref4
+	.byte	60                              ## DW_AT_declaration
+	.byte	25                              ## DW_FORM_flag_present
+	.byte	63                              ## DW_AT_external
+	.byte	25                              ## DW_FORM_flag_present
+	.byte	0                               ## EOM(1)
+	.byte	0                               ## EOM(2)
+	.byte	4                               ## Abbreviation Code
+	.byte	5                               ## DW_TAG_formal_parameter
+	.byte	0                               ## DW_CHILDREN_no
+	.byte	73                              ## DW_AT_type
+	.byte	19                              ## DW_FORM_ref4
+	.byte	52                              ## DW_AT_artificial
+	.byte	25                              ## DW_FORM_flag_present
+	.byte	0                               ## EOM(1)
+	.byte	0                               ## EOM(2)
+	.byte	5                               ## Abbreviation Code
+	.byte	59                              ## DW_TAG_unspecified_type
+	.byte	0                               ## DW_CHILDREN_no
+	.byte	3                               ## DW_AT_name
+	.byte	14                              ## DW_FORM_strp
+	.byte	0                               ## EOM(1)
+	.byte	0                               ## EOM(2)
+	.byte	6                               ## Abbreviation Code
+	.byte	15                              ## DW_TAG_pointer_type
+	.byte	0                               ## DW_CHILDREN_no
+	.byte	73                              ## DW_AT_type
+	.byte	19                              ## DW_FORM_ref4
+	.byte	0                               ## EOM(1)
+	.byte	0                               ## EOM(2)
+	.byte	7                               ## Abbreviation Code
+	.byte	46                              ## DW_TAG_subprogram
+	.byte	1                               ## DW_CHILDREN_yes
+	.byte	17                              ## DW_AT_low_pc
+	.byte	1                               ## DW_FORM_addr
+	.byte	18                              ## DW_AT_high_pc
+	.byte	6                               ## DW_FORM_data4
+	.byte	64                              ## DW_AT_frame_base
+	.byte	24                              ## DW_FORM_exprloc
+	.byte	100                             ## DW_AT_object_pointer
+	.byte	19                              ## DW_FORM_ref4
+	.byte	73                              ## DW_AT_type
+	.byte	19                              ## DW_FORM_ref4
+	.byte	59                              ## DW_AT_decl_line
+	.byte	11                              ## DW_FORM_data1
+	.byte	110                             ## DW_AT_linkage_name
+	.byte	14                              ## DW_FORM_strp
+	.byte	71                              ## DW_AT_specification
+	.byte	19                              ## DW_FORM_ref4
+	.byte	0                               ## EOM(1)
+	.byte	0                               ## EOM(2)
+	.byte	8                               ## Abbreviation Code
+	.byte	5                               ## DW_TAG_formal_parameter
+	.byte	0                               ## DW_CHILDREN_no
+	.byte	2                               ## DW_AT_location
+	.byte	24                              ## DW_FORM_exprloc
+	.byte	3                               ## DW_AT_name
+	.byte	14                              ## DW_FORM_strp
+	.byte	73                              ## DW_AT_type
+	.byte	19                              ## DW_FORM_ref4
+	.byte	52                              ## DW_AT_artificial
+	.byte	25                              ## DW_FORM_flag_present
+	.byte	0                               ## EOM(1)
+	.byte	0                               ## EOM(2)
+	.byte	9                               ## Abbreviation Code
+	.byte	36                              ## DW_TAG_base_type
+	.byte	0                               ## DW_CHILDREN_no
+	.byte	3                               ## DW_AT_name
+	.byte	14                              ## DW_FORM_strp
+	.byte	62                              ## DW_AT_encoding
+	.byte	11                              ## DW_FORM_data1
+	.byte	11                              ## DW_AT_byte_size
+	.byte	11                              ## DW_FORM_data1
+	.byte	0                               ## EOM(1)
+	.byte	0                               ## EOM(2)
+	.byte	0                               ## EOM(3)
+	.section	__DWARF,__debug_info,regular,debug
+Lsection_info:
+Lcu_begin0:
+.set Lset0, Ldebug_info_end0-Ldebug_info_start0 ## Length of Unit
+	.long	Lset0
+Ldebug_info_start0:
+	.short	4                               ## DWARF version number
+.set Lset1, Lsection_abbrev-Lsection_abbrev ## Offset Into Abbrev. Section
+	.long	Lset1
+	.byte	8                               ## Address Size (in bytes)
+	.byte	1                               ## Abbrev [1] 0xb:0x86 DW_TAG_compile_unit
+	.long	0                               ## DW_AT_producer
+	.short	33                              ## DW_AT_language
+	.long	105                             ## DW_AT_name
+	.long	129                             ## DW_AT_LLVM_sysroot
+	.long	185                             ## DW_AT_APPLE_sdk
+.set Lset2, Lline_table_start0-Lsection_line ## DW_AT_stmt_list
+	.long	Lset2
+	.long	200                             ## DW_AT_comp_dir
+	.quad	Lfunc_begin0                    ## DW_AT_low_pc
+.set Lset3, Lfunc_end0-Lfunc_begin0     ## DW_AT_high_pc
+	.long	Lset3
+	.byte	2                               ## Abbrev [2] 0x32:0x1b DW_TAG_structure_type
+	.byte	5                               ## DW_AT_calling_convention
+	.long	219                             ## DW_AT_name
+	.byte	1                               ## DW_AT_byte_size
+	.byte	1                               ## DW_AT_decl_file
+	.byte	1                               ## DW_AT_decl_line
+	.byte	3                               ## Abbrev [3] 0x3b:0x11 DW_TAG_subprogram
+	.long	221                             ## DW_AT_name
+	.byte	1                               ## DW_AT_decl_file
+	.byte	2                               ## DW_AT_decl_line
+	.long	77                              ## DW_AT_type
+                                        ## DW_AT_declaration
+                                        ## DW_AT_external
+	.byte	4                               ## Abbrev [4] 0x46:0x5 DW_TAG_formal_parameter
+	.long	82                              ## DW_AT_type
+                                        ## DW_AT_artificial
+	.byte	0                               ## End Of Children Mark
+	.byte	0                               ## End Of Children Mark
+	.byte	5                               ## Abbrev [5] 0x4d:0x5 DW_TAG_unspecified_type
+	.long	223                             ## DW_AT_name
+	.byte	6                               ## Abbrev [6] 0x52:0x5 DW_TAG_pointer_type
+	.long	50                              ## DW_AT_type
+	.byte	7                               ## Abbrev [7] 0x57:0x2d DW_TAG_subprogram
+	.quad	Lfunc_begin0                    ## DW_AT_low_pc
+.set Lset4, Lfunc_end0-Lfunc_begin0     ## DW_AT_high_pc
+	.long	Lset4
+	.byte	1                               ## DW_AT_frame_base
+	.byte	86
+	.long	119                             ## DW_AT_object_pointer
+	.long	132                             ## DW_AT_type
+	.byte	5                               ## DW_AT_decl_line
+	.long	228                             ## DW_AT_linkage_name
+	.long	59                              ## DW_AT_specification
+	.byte	8                               ## Abbrev [8] 0x77:0xc DW_TAG_formal_parameter
+	.byte	2                               ## DW_AT_location
+	.byte	145
+	.byte	120
+	.long	242                             ## DW_AT_name
+	.long	139                             ## DW_AT_type
+                                        ## DW_AT_artificial
+	.byte	0                               ## End Of Children Mark
+	.byte	9                               ## Abbrev [9] 0x84:0x7 DW_TAG_base_type
+	.long	238                             ## DW_AT_name
+	.byte	5                               ## DW_AT_encoding
+	.byte	4                               ## DW_AT_byte_size
+	.byte	6                               ## Abbrev [6] 0x8b:0x5 DW_TAG_pointer_type
+	.long	50                              ## DW_AT_type
+	.byte	0                               ## End Of Children Mark
+Ldebug_info_end0:
+	.section	__DWARF,__debug_str,regular,debug
+Linfo_string:
+	.asciz	"clang version 13.0.0 (https://github.com/llvm/llvm-project.git 18c3c7784975700ae463bb461487d46e74324a66)" ## string offset=0
+	.asciz	"auto_return_minimum.cpp"       ## string offset=105
+	.asciz	"/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk" ## string offset=129
+	.asciz	"MacOSX11.3.sdk"                ## string offset=185
+	.asciz	"/Users/shafik/code"            ## string offset=200
+	.asciz	"A"                             ## string offset=219
+	.asciz	"f"                             ## string offset=221
+	.asciz	"auto"                          ## string offset=223
+	.asciz	"_ZN1A1fEv"                     ## string offset=228
+	.asciz	"int"                           ## string offset=238
+	.asciz	"this"                          ## string offset=242
+	.section	__DWARF,__apple_names,regular,debug
+Lnames_begin:
+	.long	1212240712                      ## Header Magic
+	.short	1                               ## Header Version
+	.short	0                               ## Header Hash Function
+	.long	2                               ## Header Bucket Count
+	.long	2                               ## Header Hash Count
+	.long	12                              ## Header Data Length
+	.long	0                               ## HeaderData Die Offset Base
+	.long	1                               ## HeaderData Atom Count
+	.short	1                               ## DW_ATOM_die_offset
+	.short	6                               ## DW_FORM_data4
+	.long	0                               ## Bucket 0
+	.long	1                               ## Bucket 1
+	.long	649030992                       ## Hash in Bucket 0
+	.long	177675                          ## Hash in Bucket 1
+.set Lset5, LNames1-Lnames_begin        ## Offset in Bucket 0
+	.long	Lset5
+.set Lset6, LNames0-Lnames_begin        ## Offset in Bucket 1
+	.long	Lset6
+LNames1:
+	.long	228                             ## _ZN1A1fEv
+	.long	1                               ## Num DIEs
+	.long	87
+	.long	0
+LNames0:
+	.long	221                             ## f
+	.long	1                               ## Num DIEs
+	.long	87
+	.long	0
+Ltypes0:
+	.long	219                             ## A
+	.long	1                               ## Num DIEs
+	.long	50
+	.short	19
+	.byte	0
+	.long	0
+Ltypes2:
+	.long	238                             ## int
+	.long	1                               ## Num DIEs
+	.long	132
+	.short	36
+	.byte	0
+	.long	0
+Ltypes1:
+	.long	223                             ## auto
+	.long	1                               ## Num DIEs
+	.long	77
+	.short	59
+	.byte	0
+	.long	0
+.subsections_via_symbols
+	.section	__DWARF,__debug_line,regular,debug
+Lsection_line:
+Lline_table_start0:
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -403,6 +403,10 @@
       const DWARFDIE &die, lldb_private::ConstString type_name,
       bool must_be_implementation);
 
+  virtual lldb::TypeSP
+  FindTypeForAutoReturnForDIE(const DWARFDIE &die,
+                              lldb_private::ConstString name);
+
   lldb_private::Symbol *
   GetObjCClassSymbol(lldb_private::ConstString objc_class_name);
 
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2666,6 +2666,54 @@
   return type_sp;
 }
 
+lldb::TypeSP
+SymbolFileDWARF::FindTypeForAutoReturnForDIE(const DWARFDIE &die,
+                                             lldb_private::ConstString name) {
+  TypeSP type_sp;
+
+  if (!name)
+    return type_sp;
+
+  m_index->GetAutoReturnForDIE(name, [&](DWARFDIE other_die) {
+    bool try_resolving_type = false;
+
+    // Don't try and resolve the DIE we are looking for with the DIE
+    // itself!
+    if (other_die != die) {
+      switch (other_die.Tag()) {
+      case DW_TAG_subprogram:
+        try_resolving_type = true;
+        break;
+      default:
+        break;
+      }
+    }
+
+    if (!try_resolving_type)
+      return true;
+
+    Type *resolved_type = ResolveType(other_die, false, true);
+    if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
+      return true;
+
+    ParsedDWARFTypeAttributes attrs(other_die);
+    Type *func_type = nullptr;
+
+    if (attrs.specification.IsValid())
+      if (attrs.type.IsValid()) {
+        func_type = ResolveTypeUID(attrs.type.Reference(), true);
+
+        if (!func_type || func_type == DIE_IS_BEING_PARSED)
+          return true;
+
+        type_sp = func_type->shared_from_this();
+      }
+    return false;
+  });
+
+  return type_sp;
+}
+
 // This function helps to ensure that the declaration contexts match for two
 // different DIEs. Often times debug information will refer to a forward
 // declaration of a type (the equivalent of "struct my_struct;". There will
Index: lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h
+++ lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h
@@ -40,6 +40,9 @@
   void GetCompleteObjCClass(
       ConstString class_name, bool must_be_implementation,
       llvm::function_ref<bool(DWARFDIE die)> callback) override;
+  void
+  GetAutoReturnForDIE(ConstString class_name,
+                      llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetTypes(ConstString name,
                 llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetTypes(const DWARFDeclContext &context,
Index: lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
@@ -378,6 +378,13 @@
                    DIERefCallback(callback, class_name.GetStringRef()));
 }
 
+void ManualDWARFIndex::GetAutoReturnForDIE(
+    ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) {
+  Index();
+  m_set.function_methods.Find(
+      class_name, DIERefCallback(callback, class_name.GetStringRef()));
+}
+
 void ManualDWARFIndex::GetTypes(
     ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) {
   Index();
Index: lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
@@ -40,6 +40,9 @@
   void GetCompleteObjCClass(
       ConstString class_name, bool must_be_implementation,
       llvm::function_ref<bool(DWARFDIE die)> callback) override;
+  void
+  GetAutoReturnForDIE(ConstString class_name,
+                      llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetTypes(ConstString name,
                 llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetTypes(const DWARFDeclContext &context,
Index: lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
@@ -191,6 +191,31 @@
   m_fallback.GetCompleteObjCClass(class_name, must_be_implementation, callback);
 }
 
+void DebugNamesDWARFIndex::GetAutoReturnForDIE(
+    ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) {
+  DIEArray incomplete_types;
+
+  for (const DebugNames::Entry &entry :
+       m_debug_names_up->equal_range(class_name.GetStringRef())) {
+    if (entry.tag() != DW_TAG_subprogram)
+      continue;
+
+    llvm::Optional<DIERef> ref = ToDIERef(entry);
+    if (!ref)
+      continue;
+
+    DWARFDIE die = m_debug_info.GetDIE(*ref);
+    if (!die) {
+      ReportInvalidDIERef(*ref, class_name.GetStringRef());
+      continue;
+    }
+
+    callback(die);
+  }
+
+  m_fallback.GetAutoReturnForDIE(class_name, callback);
+}
+
 void DebugNamesDWARFIndex::GetTypes(
     ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) {
   for (const DebugNames::Entry &entry :
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
@@ -43,6 +43,9 @@
   virtual void
   GetCompleteObjCClass(ConstString class_name, bool must_be_implementation,
                        llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
+  virtual void
+  GetAutoReturnForDIE(ConstString class_name,
+                      llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
   virtual void GetTypes(ConstString name,
                         llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
   virtual void GetTypes(const DWARFDeclContext &context,
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -399,7 +399,8 @@
       break;
 
     case DW_AT_type:
-      type = form_value;
+      if (!type.IsValid())
+        type = form_value;
       break;
 
     case DW_AT_virtuality:
@@ -620,6 +621,12 @@
       clang_type = m_ast.GetBasicType(eBasicTypeNullPtr);
       break;
     }
+    if (attrs.name == "auto") {
+      resolve_state = Type::ResolveState::Full;
+      clang::QualType t = m_ast.getASTContext().getAutoDeductType();
+      clang_type = m_ast.GetType(t);
+      break;
+    }
     // Fall through to base type below in case we can handle the type
     // there...
     LLVM_FALLTHROUGH;
@@ -916,7 +923,6 @@
   std::vector<clang::ParmVarDecl *> function_param_decls;
 
   // Parse the function children for the parameters
-
   DWARFDIE decl_ctx_die;
   clang::DeclContext *containing_decl_ctx =
       GetClangDeclContextContainingDIE(die, &decl_ctx_die);
@@ -1295,6 +1301,23 @@
       }
     }
   }
+
+  // If a function has an auto return type we need to find the defintion since
+  // that will have the deduced return type and adjust the FunctionDecl to
+  // reflect this.
+  if (func_type && func_type->GetName() == "auto") {
+    TypeSP ret_type = dwarf->FindTypeForAutoReturnForDIE(die, attrs.name);
+    if (ret_type) {
+      return_clang_type = ret_type->GetForwardCompilerType();
+      auto *function_decl = llvm::dyn_cast_or_null<clang::FunctionDecl>(
+          GetCachedClangDeclContextForDIE(die));
+
+      if (function_decl)
+        m_ast.getASTContext().adjustDeducedFunctionResultType(
+            function_decl, ClangUtil::GetQualType(return_clang_type));
+    }
+  }
+
   return std::make_shared<Type>(
       die.GetID(), dwarf, attrs.name, llvm::None, nullptr, LLDB_INVALID_UID,
       Type::eEncodingIsUID, &attrs.decl, clang_type, Type::ResolveState::Full);
Index: lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h
+++ lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h
@@ -46,6 +46,9 @@
   void GetCompleteObjCClass(
       ConstString class_name, bool must_be_implementation,
       llvm::function_ref<bool(DWARFDIE die)> callback) override;
+  void
+  GetAutoReturnForDIE(ConstString class_name,
+                      llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetTypes(ConstString name,
                 llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetTypes(const DWARFDeclContext &context,
Index: lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
@@ -105,6 +105,15 @@
       must_be_implementation);
 }
 
+void AppleDWARFIndex::GetAutoReturnForDIE(
+    ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) {
+  if (!m_apple_names_up)
+    return;
+  m_apple_names_up->FindByName(
+      class_name.GetStringRef(),
+      DIERefCallback(callback, class_name.GetStringRef()));
+}
+
 void AppleDWARFIndex::GetTypes(
     ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) {
   if (!m_apple_types_up)
Index: lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
@@ -325,9 +325,11 @@
     else
       ptr_qual_type = Ctx.getPointerType(expr_qual_type);
 
-    result_decl =
-        VarDecl::Create(Ctx, DC, SourceLocation(), SourceLocation(),
-                        result_ptr_id, ptr_qual_type, nullptr, SC_Static);
+    TypeSourceInfo *tsi = Ctx.getTrivialTypeSourceInfo(
+        ptr_qual_type, last_expr->getSourceRange().getBegin());
+
+    result_decl = VarDecl::Create(Ctx, DC, SourceLocation(), SourceLocation(),
+                                  result_ptr_id, ptr_qual_type, tsi, SC_Static);
 
     if (!result_decl)
       return false;
@@ -341,9 +343,10 @@
   } else {
     IdentifierInfo &result_id = Ctx.Idents.get("$__lldb_expr_result");
 
-    result_decl =
-        VarDecl::Create(Ctx, DC, SourceLocation(), SourceLocation(), &result_id,
-                        expr_qual_type, nullptr, SC_Static);
+    TypeSourceInfo *tsi = Ctx.getTrivialTypeSourceInfo(
+        expr_qual_type, last_expr->getSourceRange().getBegin());
+    result_decl = VarDecl::Create(Ctx, DC, SourceLocation(), SourceLocation(),
+                                  &result_id, expr_qual_type, tsi, SC_Static);
 
     if (!result_decl)
       return false;
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1689,7 +1689,11 @@
   // type" but misses cases of non-function-local but non-external classes such
   // as those in anonymous namespaces as well as the reverse - external types
   // that are function local, such as those in (non-local) inline functions.
-  if (!IsCtorOrDtor && !isFunctionLocalClass(Method->getParent()))
+  if (!IsCtorOrDtor && !isFunctionLocalClass(Method->getParent()) &&
+      // If the declared return type is "auto" we want the linkage name to go
+      // with the defintion. In case the definiton is out of line, it needs to
+      // have a name so we can find it via DWARF index.
+      !Method->getDeclaredReturnType()->getContainedDeducedType())
     MethodLinkageName = CGM.getMangledName(Method);
 
   // Get the location for the method.
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to