[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2022-08-15 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.
Herald added a project: All.

I've posted D131933  to revert this patch 
based on discussion in D123319 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2020-01-13 Thread Amy Huang via Phabricator via cfe-commits
akhuang added a comment.

Looks like the first commit c958639098a8 
 is also 
causing a crash in chromium code, so I will revert that as well. 
I got a reduced test case:

  typedef void voidtype;
  struct S {
voidtype a();
  };
  void S::a() {}


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2020-01-13 Thread Stella Stamenova via Phabricator via cfe-commits
stella.stamenova added a comment.

This also broke a number of the tests on the Windows LLDB bot, so when you get 
around to resubmitting the change with a fix, please make sure the bot doesn't 
get broken again: 
http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/12551


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2020-01-13 Thread Sourabh Singh Tomar via Phabricator via cfe-commits
SouraVX added a comment.

Thanks @sammccall ,  for the test case. Seems like, this implementation doesn't 
address the lambda functions returning "auto".  We're looking into this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2020-01-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D70524#1816492 , @sammccall wrote:

> Following crashes for me with `clang++ -g2`:


This crashes at 6d6a4590c5d4 
 but not 
at c958639098a8 
. Reverted 
in e45fcfc3aa57bb237fd4fd694d0c257be66d5482 
, up to 
you whether the prev patch should be reverted too.

Stack trace:

  1. parser at end of file
  2.Code generation
   #0 0x0263ea84 PrintStackTrace 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/Support/Unix/Signals.inc:564:13
   #1 0x0263ea84 PrintStackTraceSignalHandler(void*) 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/Support/Unix/Signals.inc:624:0
   #2 0x0263c61e llvm::sys::RunSignalHandlers() 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/Support/Signals.cpp:69:18
   #3 0x0263ee9c SignalHandler(int) 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/Support/Unix/Signals.inc:396:3
   #4 0x7fc9c4fad3a0 __restore_rt 
(/lib/x86_64-linux-gnu/libpthread.so.0+0x123a0)
   #5 0x7fc9c424ecfb raise (/lib/x86_64-linux-gnu/libc.so.6+0x36cfb)
   #6 0x7fc9c42398ad abort (/lib/x86_64-linux-gnu/libc.so.6+0x218ad)
   #7 0x7fc9c423977f (/lib/x86_64-linux-gnu/libc.so.6+0x2177f)
   #8 0x7fc9c4247542 (/lib/x86_64-linux-gnu/libc.so.6+0x2f542)
   #9 0x030c08a6 
(/usr/local/google/home/sammccall/llvmbuild-mono/bin/clang-10+0x30c08a6)
  #10 0x030c5b7e 
llvm::DwarfUnit::applySubprogramDefinitionAttributes(llvm::DISubprogram const*, 
llvm::DIE&) 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:1176:15
  #11 0x030c4e46 
llvm::DwarfUnit::applySubprogramAttributes(llvm::DISubprogram const*, 
llvm::DIE&, bool) 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:1221:9
  #12 0x03106a0f getOperand 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/include/llvm/IR/Metadata.h:1078:5
  #13 0x03106a0f getOperandAs 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/include/llvm/IR/DebugInfoMetadata.h:132:0
  #14 0x03106a0f getStringOperand 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/include/llvm/IR/DebugInfoMetadata.h:136:0
  #15 0x03106a0f getName 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/include/llvm/IR/DebugInfoMetadata.h:1793:0
  #16 0x03106a0f 
llvm::DwarfCompileUnit::applySubprogramAttributesToDefinition(llvm::DISubprogram
 const*, llvm::DIE&) 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp:1299:0
  #17 0x030a01d2 getSkeleton 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h:116:12
  #18 0x030a01d2 forBothCUs<(lambda at 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1090:9)>
 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:509:0
  #19 0x030a01d2 llvm::DwarfDebug::finishSubprogramDefinitions() 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1088:0
  #20 0x030a029a llvm::DwarfDebug::finalizeModuleInfo() 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1099:3
  #21 0x030a0978 llvm::DwarfDebug::endModule() 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1238:3
  #22 0x03084da3 ~TimeRegion 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/include/llvm/Support/Timer.h:152:9
  #23 0x03084da3 llvm::AsmPrinter::doFinalization(llvm::Module&) 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:1485:0
  #24 0x01fc9fa5 llvm::FPPassManager::doFinalization(llvm::Module&) 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/IR/LegacyPassManager.cpp:1535:13
  #25 0x01fca5f6 runOnModule 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/IR/LegacyPassManager.cpp:1611:41
  #26 0x01fca5f6 llvm::legacy::PassManagerImpl::run(llvm::Module&) 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/IR/LegacyPassManager.cpp:1694:0
  #27 0x02824eb9 ~TimeTraceScope 
/usr/local/google/home/sammccall/src/llvm-mono/llvm/include/llvm/Support/TimeProfiler.h:74:35
  #28 0x02824eb9 EmitAssembly 
/usr/local/google/home/sammccall/src/llvm-mono/clang/lib/CodeGen/BackendUtil.cpp:912:0
  #29 0x02824eb9 clang::EmitBackendOutput(clang::DiagnosticsEngine&, 
clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, 
clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout 
const&, llvm::Module*, clang::BackendAction, 
std::unique_ptr >) 

[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2020-01-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Following crashes for me with `clang++ -g2`:

  struct Thing {
void crash(Thing ) {
  auto Lambda = [&] {
Other.external();
  };
  Lambda();
}
void external();
  };
  
  void test(Thing , Thing ) {
A.crash(B);
  }

Haven't yet verified that it's this commit, but certainly looks related. Will 
revert once this is confirmed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2020-01-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

This seems to have introduced a crash compiling libcxx. I'm currently reducing 
the crashing code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2020-01-12 Thread Sourabh Singh Tomar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc958639098a8: [DWARF5][DebugInfo]: Added support for 
DebugInfo generation for auto return… (authored by awpandey, committed by 
SouraVX).

Changed prior to commit:
  https://reviews.llvm.org/D70524?vs=237264=237578#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.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,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.00e+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)
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]);
+

[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2020-01-10 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Looks good - thanks!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2020-01-10 Thread Awanish Pandey via Phabricator via cfe-commits
awpandey updated this revision to Diff 237264.
awpandey added a comment.

@dblaikie I have added an LLVM test case and I will commit it like a different 
patch. 
I have also updated the clang test case.


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/lib/CodeGen/AsmPrinter/DwarfUnit.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,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.00e+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)
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);
 

[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2020-01-08 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1467-1468
   if (Method->isStatic())
 return cast_or_null(
 getOrCreateType(QualType(Func, 0), Unit));
+  return getOrCreateInstanceMethodType(Method->getThisType(), Func, Unit, 
decl);

Looks like this patch probably doesn't address the case where the function is 
static. Though adding support for static should be done in a separate/next 
patch. It might turn out that handling that case motivates sinking this 
functionality further down into more shared functionality, but we can deal with 
that in the review for that separate patch.

(also, there's work being done to add various non-member function declarations 
to LLVM debug info emission (for call site debug info) - at some point (not in 
this patch) it's probably worth checking whether those non-member function 
declarations might need this sort of handling as well)



Comment at: clang/test/CodeGenCXX/debug-info-auto-return.cpp:9
+
+// CHECK: ![[t:[0-9]+]] = !DISubroutineType(types: ![[t1:[0-9]+]])
+// CHECK-NEXT: ![[t1:[0-9]+]] = !{![[t2:[0-9]+]], {{.*}}

This looks incorrect - I expect what you want here is [[t]] to match the 
previously defined t on the prior CHECK. (similarly with the other matches - 
use [[x:pattern]] to define the pattern, then [[x]] to reference the previously 
defined pattern - otherwise the two won't be associated (if you don't need any 
association between two pattern matches, you can use {{pattern}} for unnamed 
pattern matching))

Also, please use descriptive names for these matches & I /think/ the convention 
is usually upper case? I'd think "DECL_TYPE", "DEF_TYPE", "AUTO_TYPE", and 
"DOUBLE_TYPE" might be good names.



Comment at: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:1168-1175
+DITypeRefArray DeclArgs, DefinitionArgs;
+DeclArgs = SPDecl->getType()->getTypeArray();
+DefinitionArgs = SP->getType()->getTypeArray();
+
+if (DeclArgs.size() && DefinitionArgs.size())
+  if (DeclArgs[0] != DefinitionArgs[0])
+addType(SPDie, DefinitionArgs[0]);

Please split this out into a separate patch/review with its own LLVM-level test 
(& this would be committed before the clang-side)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2020-01-03 Thread Awanish Pandey via Phabricator via cfe-commits
awpandey updated this revision to Diff 235998.
awpandey added a comment.
Herald added a subscriber: hiraditya.

@dblaikie Thanks a lot for the suggestions. I have made the changes such that 
this will become consistent with your suggestions.


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/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

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, DefinitionArgs;
+DeclArgs = SPDecl->getType()->getTypeArray();
+DefinitionArgs = SP->getType()->getTypeArray();
+
+if (DeclArgs.size() && DefinitionArgs.size())
+  if (DeclArgs[0] != DefinitionArgs[0])
+addType(SPDie, DefinitionArgs[0]);
+
 DeclDie = getDIE(SPDecl);
 assert(DeclDie && "This DIE should've already been constructed when the "
   "definition DIE was created in "
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: ![[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(name: "double", {{.*}})
+
+// 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() {
+  return 0.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,
@@ -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) {

[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-17 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D70524#1787566 , @SouraVX wrote:

> > It looks like this implementation is a bit buggy in one way and incomplete 
> > in another:
> > 
> > 1. even if the auto-returning function is defined, that function definition 
> > doesn't describe the concrete return type. Compare GCC and Clang's output 
> > for your example and note that... oh.
>
> I think that's correct behavior, consider this for a moment --
>
>   struct foo {
>   auto foo_func();
>   };
>   int foo::foo_func(){return 0;}
>   clang error: ->
>   error: return type of out-of-line definition of 'foo::foo_func' differs 
> from that in the declaration
>
>
> So this seems fair to me, regardless of the concrete return type{assuming 
> this is what this patch is doing}. We should be emitting `auto` in 
> declaration. AKA in unspecified_type. GCC(trunk) also seems fair here.


Sorry, the example I had in mind was this:

  struct type {
auto func();
  };
  auto type::func() {
return 3;
  }

Which GCC produces:

  DW_TAG_structure_type
DW_AT_name ("type")
DW_TAG_subprogram
  DW_AT_name ("func")
  DW_AT_type (DW_TAG_unspecified_type "auto")
  ...
  DW_TAG_subprogram
DW_AT_specification (... ^)
DW_AT_type (DW_TAG_base_type "int")
...

(this should be the same debug info even if the function is defined inline in 
the class, rather than defined out of line (assuming the function's called - 
which produces a definition))

>> Hmm, maybe this feature/suggestion is broken or at least not exactly awesome 
>> when it comes to auto-returning functions that are eventually void-returning 
>> functions? Now the function definition has no DW_AT_type to override the 
>> unspecified_type in the declaration... :/ that's unfortunate (@probinson - 
>> thoughts?)
> 
> I'm a bit confused here, regardless of the concrete return 
> type{void/int/float} GCC(trunk) is emitting 
>  `DW_TAG_unspecified_type`
>  `DW_AT_name "auto"` 
>  Are you trying to say we should be emitting `DW_AT_type void/int/float` ?? 
> That's what functionality of clang is right now, and if we entertain that, 
> then their is no point of emitting `DW_TAG_unspecifed_type auto` at first 
> place.

As @probinson said - for the definition DIE/DISubprogram the type should be the 
concrete, deduced type. For the declaration DIE/DISubprogram, the return type 
should be "auto".


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-17 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

> "DW_TAG_unspecified_type auto" should be emitted for the function 
> declared/defined as auto returnning. Do you have other test cases in mind, 
> where above points diverges ??

The declaration would have DW_AT_type point to DW_TAG_unspecified_type, but the 
definition should have DW_AT_type use the actual type (which is now known, 
because you have the definition).  The "actual type" might be "void", in which 
case the definition would omit DW_AT_type, just like a normal (non-auto) 
function that returns void.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-17 Thread Sourabh Singh Tomar via Phabricator via cfe-commits
SouraVX added a comment.

> It looks like this implementation is a bit buggy in one way and incomplete in 
> another:
> 
> 1. even if the auto-returning function is defined, that function definition 
> doesn't describe the concrete return type. Compare GCC and Clang's output for 
> your example and note that... oh.

I think that's correct behavior, consider this for a moment --

  struct foo {
  auto foo_func();
  };
  int foo::foo_func(){return 0;}
  clang error: ->
  error: return type of out-of-line definition of 'foo::foo_func' differs from 
that in the declaration

So this seems fair to me, regardless of the concrete return type{assuming this 
is what this patch is doing}. We should be emitting `auto` in declaration. AKA 
in unspecified_type. GCC(trunk) also seems fair here.

> Hmm, maybe this feature/suggestion is broken or at least not exactly awesome 
> when it comes to auto-returning functions that are eventually void-returning 
> functions? Now the function definition has no DW_AT_type to override the 
> unspecified_type in the declaration... :/ that's unfortunate (@probinson - 
> thoughts?)

I'm a bit confused here, regardless of the concrete return type{void/int/float} 
GCC(trunk) is emitting 
`DW_TAG_unspecified_type`
`DW_AT_name "auto"` 
Are you trying to say we should be emitting `DW_AT_type void/int/float` ?? 
That's what functionality of clang is right now, and if we entertain that, then 
their is no point of emitting `DW_TAG_unspecifed_type auto` at first place.

> GCC does use the unspecified type "auto" even back in DWARFv4 and it leaves 
> the subprogram definition DIE without a DW_AT_type if the auto type ends up 
> as void (what else could it do?) so I guess we can do this for consistency & 
> consumers have to know that a definition can't really have an auto return 
> type and that it must be really void.
> 
> In any case - change the test case to use a non-void return type in the 
> definition ("return 3;" for instance, to get an int return type instead) and 
> check that the DISubprogram for the definition has a concrete return type of 
> "int" while the DISubprogram for the declaration has the "auto" 
> unspecified_type return type. (contrast/test against GCC's behavior)



> 2. Presumably in a follow-up patch, make sure that the declaration for the 
> DISubprogram declaration for an "auto" return type function appears in the 
> member list of the DICompositeType even if the function is not called (same 
> as other normal (non-implicit/non-template) functions) since that's the value 
> of being able to describe the return type as "auto" (the function can be 
> described even when the definition isn't available/emitted) - it doesn't 
> currently. (contrast/test against with GCC's behavior)

Agreed testing for this must be exhaustive, but I think for all test cases 
behavior should be same -- "DW_TAG_unspecified_type auto" should be emitted for 
the function declared/defined as auto returnning. Do you have other test cases 
in mind, where above points diverges ??


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-16 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D70524#1783363 , @probinson wrote:

> > Hmm, maybe this feature/suggestion is broken or at least not exactly 
> > awesome when it comes to auto-returning functions that are eventually 
> > void-returning functions? Now the function definition has no DW_AT_type to 
> > override the unspecified_type in the declaration... :/ that's unfortunate 
> > (@probinson - thoughts?)
>
> Normally, the DW_AT_specification on the definition would mean, look at the 
> declaration for additional attributes, such as DW_AT_type.  However, the 
> declaration's unspecified_type means, look at the definition.  The definition 
> omits DW_AT_type, therefore the return type is "void".
>  It's a wee bit circular, but I think it's not unreasonable to expect the 
> consumer to figure this out.


Fair enough. I think that's pretty awkward, but don't feel strongly enough to 
say that's bad/wrong - it's what GCC does, it's probably what GDB understands, 
etc.

Test cases/functionality need to be fixed here, because currently the deduced 
type isn't being carried on the function definition (it just "works out" for 
the limited testing provided - because the test is testing void return, but 
adding/changing the test to test non-void return should expose the bug)

Also - I think this probably should be enabled even pre-DWARFv5. GDB does that 
and unspecified_type is available pre-v5 & it saves having a divergence in the 
frontend for v5 generation which I think is probably good (I don't think we 
have that as a hard line, but I'd tend to think it's a direction we should 
generally lean in - where the DWARF version is handled by the metadata 
attribute and the backend for the most part/where possible).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-13 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

> Hmm, maybe this feature/suggestion is broken or at least not exactly awesome 
> when it comes to auto-returning functions that are eventually void-returning 
> functions? Now the function definition has no DW_AT_type to override the 
> unspecified_type in the declaration... :/ that's unfortunate (@probinson - 
> thoughts?)

Normally, the DW_AT_specification on the definition would mean, look at the 
declaration for additional attributes, such as DW_AT_type.  However, the 
declaration's unspecified_type means, look at the definition.  The definition 
omits DW_AT_type, therefore the return type is "void".
It's a wee bit circular, but I think it's not unreasonable to expect the 
consumer to figure this out.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-12 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D70524#1779179 , @awpandey wrote:

> @dblaikie . I have removed the redundant test case. What else should I do in 
> this patch?


Please address this warning before committing:

  
/usr/local/google/home/blaikie/dev/llvm/src/clang/lib/CodeGen/CGDebugInfo.cpp:3100:3:
 warning: unannotated fall-through between switch labels 
[-Wimplicit-fallthrough]
case Type::Attributed:
^
  
/usr/local/google/home/blaikie/dev/llvm/src/clang/lib/CodeGen/CGDebugInfo.cpp:3100:3:
 note: insert 'break;' to avoid fall-through
case Type::Attributed:
^
break; 
  1 warning generated.

It looks like this implementation is a bit buggy in one way and incomplete in 
another:

1. even if the auto-returning function is defined, that function definition 
doesn't describe the concrete return type. Compare GCC and Clang's output for 
your example and note that... oh.

Hmm, maybe this feature/suggestion is broken or at least not exactly awesome 
when it comes to auto-returning functions that are eventually void-returning 
functions? Now the function definition has no DW_AT_type to override the 
unspecified_type in the declaration... :/ that's unfortunate (@probinson - 
thoughts?) GCC does use the unspecified type "auto" even back in DWARFv4 and it 
leaves the subprogram definition DIE without a DW_AT_type if the auto type ends 
up as void (what else could it do?) so I guess we can do this for consistency & 
consumers have to know that a definition can't really have an auto return type 
and that it must be really void.

In any case - change the test case to use a non-void return type in the 
definition ("return 3;" for instance, to get an int return type instead) and 
check that the DISubprogram for the definition has a concrete return type of 
"int" while the DISubprogram for the declaration has the "auto" 
unspecified_type return type. (contrast/test against GCC's behavior)

2. Presumably in a follow-up patch, make sure that the declaration for the 
DISubprogram declaration for an "auto" return type function appears in the 
member list of the DICompositeType even if the function is not called (same as 
other normal (non-implicit/non-template) functions) since that's the value of 
being able to describe the return type as "auto" (the function can be described 
even when the definition isn't available/emitted) - it doesn't currently. 
(contrast/test against with GCC's behavior)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-11 Thread Awanish Pandey via Phabricator via cfe-commits
awpandey updated this revision to Diff 233289.
awpandey added a comment.

@dblaikie . I have removed the redundant test case. What else should I do in 
this patch?


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

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: 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 ) {
+static QualType UnwrapTypeForDebugInfo(QualType T, const ASTContext ,
+   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:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-06 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D70524#1772961 , @probinson wrote:

> > Perhaps we should implement this mode under -fno-standalone-debug (or 
> > something more aggressive) since "standalone" is one of the only places I 
> > can think of where having the full class definition would be handy
>
> You'd also want it for type units, so they deduplicate more reliably?  And 
> probably should be DWARF only, not CodeView?  But yeah, I'm down for it.


It'd basically remove the need for type units entirely (& the DWARF would end 
up looking quite similar to DWARF using type units, just without the type units 
(well, you'd move the member variables from the type DIE In the type unit to 
the "skeleton" type DIE in the CU - but the member function handling looks very 
similar (because the skeleton type DIE ends up needing all the declarations of 
member functions in defined in the CU anyway - so the out of line definitions 
can refer to the member function declarations, their parameters, etc (since you 
can't refer to specific DIEs other than the total type DIE in a type unit.

Yeah, only for DWARF/I have no idea what CodeView can/would do.

> This tactic would depend on the debuggers knowing they are unlikely to get a 
> full class description and shouldn't throw away any class they've "already 
> seen."  I remember that was an issue with, uh, one of those other debuggers 
> that I never use.  They might take the first one they see, and shrug off any 
> others as not contributing anything really important.  That would have to 
> change.

My understanding with GDB is that it tends to treat the types in independent 
CUs as being potentially independent - you can violate the ODR and see that 
reflected in the type descriptions depending on where you print the type from 
(eg: print the type while you're debugging one function in one TU and you get 
that TU's view of the type, then step into a function in another TU and print 
the type and you get that TU's view of the type).

Yeah, it's not high on my list & starting with the DWARF consumers would be the 
right place.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-06 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

> Perhaps we should implement this mode under -fno-standalone-debug (or 
> something more aggressive) since "standalone" is one of the only places I can 
> think of where having the full class definition would be handy

You'd also want it for type units, so they deduplicate more reliably?  And 
probably should be DWARF only, not CodeView?  But yeah, I'm down for it.

This tactic would depend on the debuggers knowing they are unlikely to get a 
full class description and shouldn't throw away any class they've "already 
seen."  I remember that was an issue with, uh, one of those other debuggers 
that I never use.  They might take the first one they see, and shrug off any 
others as not contributing anything really important.  That would have to 
change.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-06 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D70524#1772690 , @probinson wrote:

> In D70524#1772117 , @dblaikie wrote:
>
> > In D70524#1771709 , @probinson 
> > wrote:
> >
> > > In D70524#1771522 , @shafik 
> > > wrote:
> > >
> > > > @probinson I was reading the C++ "auto" return type 
> > > >  issue and I can't 
> > > > come up with a case where we don't have class descriptions across 
> > > > compilation units that are not consistent wrt to auto return type. Do 
> > > > you have a specific example?
> > >
> > >
> > > The actual return type is known in a compile_unit where the method is 
> > > defined, and not known in other compile_units.  If the non-defining 
> > > compile_units omit the return type, that means "void" not "auto".  That 
> > > is, one compile unit says it returns "void" and another compile unit says 
> > > it returns something else.  That is the inconsistency I meant.
> > >
> > > If we use unspecified_type instead of omitting the return type, then a 
> > > consumer knows that the method returns *something*, but it will have to 
> > > look elsewhere to determine what that is.
> >
> >
> > Yeah, my argument was to omit the declarations of auto-returning functions 
> > entirely except in cases where their definition is available (either only 
> > when the definition is emitted, or whenever the definition's available so 
> > the deduced return type can be provided), same as a template instantiation.
> >
> > So the class would be missing the declaration of the function in cases 
> > where the definition isn't available - same as templates and implicit 
> > special members.
>
>
> Understood.  The class descriptions are inconsistent (in that sense) across 
> CUs.  This means deduplication in the type-unit sense would be less 
> effective, but in the template-member and special-member cases there's really 
> not much to be done about it.  This argument says that auto-return methods 
> aren't fundamentally different from those.


I mean we could do something about them, to a degree - we could compute which 
special members are valid & emit them pre-emptively (though that'd be a bit 
tricky to do reliably, without unnecessarily instantiating any extra code, etc 
- but it's possible) & we could improve DWARF to have some description of 
templates. There still probably wouldn't be enough info to get overload 
resolution right, etc.

>> (yeah, you could take this to its logical extreme and say we should treat 
>> all member functions this way - never produce a whole class definition 
>> enumerating all members - Eric and I have bandied that idea about as 
>> "classes as namespaces" more or less (the members in a class definition in 
>> one CU aren't necessarily the same as those in another, and a consumer would 
>> have to consider all of them together like it would have to for namespaces))
> 
> Heh.  Implemented that locally years ago as a space-saving measure; 
> unreferenced methods are omitted.  Our debugger internally merges the 
> different descriptions that it encounters.  In the compiler, the trick is 
> that you don't actually know which methods to suppress until IRGen is 
> complete, so I had to invent a Suppressed flag on the DISubprogram, that 
> causes DwarfDebug to ignore it.

Oh, I'd just implement it like the template/implicit special member - the 
DISubprograms are built as-needed/only referenced from the llvm::Function, they 
don't appear in the "members" list of the DICompositeType at all, and then 
DwarfDebug attaches any that make it to LLVM's CodeGen/need to be emitted then.

If you comment out this call: 
https://github.com/llvm/llvm-project/blob/master/clang/lib/CodeGen/CGDebugInfo.cpp#L2296
 you can probably get the behavior you want without any other changes? (tested 
that, and it reduced the dwarfdump debug_info dumped output from 3.5k lines to 
1k lines)

Perhaps we should implement this mode under -fno-standalone-debug (or something 
more aggressive) since "standalone" is one of the only places I can think of 
where having the full class definition would be handy - it'd make it clear that 
there is a specific function overload that can be called & the debugger could 
mangle the name and find the symbol in another TU that was built without debug 
info... not sure if any implement that, though. (that wouldn't be quite 
possible with an auto-returning function - you'd need to know the return type 
to figure out the calling ABI/handle the return value)

>> & honestly it's going to be pretty uncommon that any of this comes up - 
>> people aren't likely to separate their auto-returning function declaration 
>> from its definition. It'd be awkward to read code like that.
> 
> If it's a class method, which is the only case of interest (otherwise the 
> unused declaration is suppressed 

[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-06 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

In D70524#1772117 , @dblaikie wrote:

> In D70524#1771709 , @probinson wrote:
>
> > In D70524#1771522 , @shafik wrote:
> >
> > > @probinson I was reading the C++ "auto" return type 
> > >  issue and I can't come 
> > > up with a case where we don't have class descriptions across compilation 
> > > units that are not consistent wrt to auto return type. Do you have a 
> > > specific example?
> >
> >
> > The actual return type is known in a compile_unit where the method is 
> > defined, and not known in other compile_units.  If the non-defining 
> > compile_units omit the return type, that means "void" not "auto".  That is, 
> > one compile unit says it returns "void" and another compile unit says it 
> > returns something else.  That is the inconsistency I meant.
> >
> > If we use unspecified_type instead of omitting the return type, then a 
> > consumer knows that the method returns *something*, but it will have to 
> > look elsewhere to determine what that is.
>
>
> Yeah, my argument was to omit the declarations of auto-returning functions 
> entirely except in cases where their definition is available (either only 
> when the definition is emitted, or whenever the definition's available so the 
> deduced return type can be provided), same as a template instantiation.
>
> So the class would be missing the declaration of the function in cases where 
> the definition isn't available - same as templates and implicit special 
> members.


Understood.  The class descriptions are inconsistent (in that sense) across 
CUs.  This means deduplication in the type-unit sense would be less effective, 
but in the template-member and special-member cases there's really not much to 
be done about it.  This argument says that auto-return methods aren't 
fundamentally different from those.

> (yeah, you could take this to its logical extreme and say we should treat all 
> member functions this way - never produce a whole class definition 
> enumerating all members - Eric and I have bandied that idea about as "classes 
> as namespaces" more or less (the members in a class definition in one CU 
> aren't necessarily the same as those in another, and a consumer would have to 
> consider all of them together like it would have to for namespaces))

Heh.  Implemented that locally years ago as a space-saving measure; 
unreferenced methods are omitted.  Our debugger internally merges the different 
descriptions that it encounters.  In the compiler, the trick is that you don't 
actually know which methods to suppress until IRGen is complete, so I had to 
invent a Suppressed flag on the DISubprogram, that causes DwarfDebug to ignore 
it.

> & honestly it's going to be pretty uncommon that any of this comes up - 
> people aren't likely to separate their auto-returning function declaration 
> from its definition. It'd be awkward to read code like that.

If it's a class method, which is the only case of interest (otherwise the 
unused declaration is suppressed anyway), the auto-return method is in the 
class declaration and all users of the header will have to see it.  Most likely 
it would be a private method and used only in the implementation module, but 
still.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-05 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D70524#1771709 , @probinson wrote:

> In D70524#1771522 , @shafik wrote:
>
> > @probinson I was reading the C++ "auto" return type 
> >  issue and I can't come 
> > up with a case where we don't have class descriptions across compilation 
> > units that are not consistent wrt to auto return type. Do you have a 
> > specific example?
>
>
> The actual return type is known in a compile_unit where the method is 
> defined, and not known in other compile_units.  If the non-defining 
> compile_units omit the return type, that means "void" not "auto".  That is, 
> one compile unit says it returns "void" and another compile unit says it 
> returns something else.  That is the inconsistency I meant.
>
> If we use unspecified_type instead of omitting the return type, then a 
> consumer knows that the method returns *something*, but it will have to look 
> elsewhere to determine what that is.


Yeah, my argument was to omit the declarations of auto-returning functions 
entirely except in cases where their definition is available (either only when 
the definition is emitted, or whenever the definition's available so the 
deduced return type can be provided), same as a template instantiation.

So the class would be missing the declaration of the function in cases where 
the definition isn't available - same as templates and implicit special members.

(yeah, you could take this to its logical extreme and say we should treat all 
member functions this way - never produce a whole class definition enumerating 
all members - Eric and I have bandied that idea about as "classes as 
namespaces" more or less (the members in a class definition in one CU aren't 
necessarily the same as those in another, and a consumer would have to consider 
all of them together like it would have to for namespaces))

& honestly it's going to be pretty uncommon that any of this comes up - people 
aren't likely to separate their auto-returning function declaration from its 
definition. It'd be awkward to read code like that.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-05 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

In D70524#1771522 , @shafik wrote:

> @probinson I was reading the C++ "auto" return type 
>  issue and I can't come up 
> with a case where we don't have class descriptions across compilation units 
> that are not consistent wrt to auto return type. Do you have a specific 
> example?


The actual return type is known in a compile_unit where the method is defined, 
and not known in other compile_units.  If the non-defining compile_units omit 
the return type, that means "void" not "auto".  That is, one compile unit says 
it returns "void" and another compile unit says it returns something else.  
That is the inconsistency I meant.

If we use unspecified_type instead of omitting the return type, then a consumer 
knows that the method returns *something*, but it will have to look elsewhere 
to determine what that is.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-05 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

In D70524#1767775 , @aprantl wrote:

> @shafik Can you speak about whether this feature ("auto" return type in DWARF 
> v5 section 5.2) would be useful for LLDB?


I agree with @dblaikie here, I can't come up with a scenario where this would 
be required. Unless like he mentioned we emit all the function declarations, 
which we don't.

@probinson I was reading the C++ "auto" return type 
 issue and I can't come up 
with a case where we don't have class descriptions across compilation units 
that are not consistent wrt to auto return type. Do you have a specific example?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-05 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D70524#1770330 , @awpandey wrote:

> > It looks to me like there are a few tests for unspecified_type already:
> > 
> > $ grep -r unspecified_type llvm/test
> >  llvm/test/Assembler/debug-info.ll:; CHECK-NEXT: !7 = !DIBasicType(tag: 
> > DW_TAG_unspecified_type, name: "decltype(nullptr)")
> >  llvm/test/Assembler/debug-info.ll:!8 = !DIBasicType(tag: 
> > DW_TAG_unspecified_type, name: "decltype(nullptr)")
>
> ...
>  @dblaikie, are you suggesting me to modify some of these existing test cases 
> to include  `auto return` functionality as well.


Nah - I'm suggesting that the existing coverage is sufficient and there's no 
need for an LLVM test for "auto return" - the specific string name used in a 
DW_TAG_unspecified_type is not parsed or processed in any way by LLVM - it's 
produced verbatim into the output (in the name of the unspecified_type) so 
there's no need to test with different strings (this would be akin to having a 
printf test case for "decltype(nullptr)" and then adding a different test case 
for printing "auto" - they're not meaningfully different test cases for printf 
(it's highly unlikely that a bug exists that can print one and not the other - 
and why those two strings in particular, among all the possible strings you 
could print that should be equally well handled?)).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-05 Thread Awanish Pandey via Phabricator via cfe-commits
awpandey marked an inline comment as done.
awpandey added a comment.

> It looks to me like there are a few tests for unspecified_type already:
> 
> $ grep -r unspecified_type llvm/test
>  llvm/test/Assembler/debug-info.ll:; CHECK-NEXT: !7 = !DIBasicType(tag: 
> DW_TAG_unspecified_type, name: "decltype(nullptr)")
>  llvm/test/Assembler/debug-info.ll:!8 = !DIBasicType(tag: 
> DW_TAG_unspecified_type, name: "decltype(nullptr)")

...
@dblaikie, are you suggesting me to modify some of these existing test cases to 
include  `auto return` functionality as well.




Comment at: clang/test/CodeGenCXX/debug-info-auto-return.cpp:9
+
+// CHECK: ![[t:[0-9]+]] = !DISubroutineType(types: ![[t1:[0-9]+]])
+// CHECK-NEXT: ![[t1:[0-9]+]] = !{![[t2:[0-9]+]], {{.*}}

@aprantl  I have tried to use variable as shown by you for showing links 
between the associated  nodes.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-05 Thread Awanish Pandey via Phabricator via cfe-commits
awpandey updated this revision to Diff 232281.
awpandey marked 5 inline comments as done.
awpandey added a comment.

Hi @aprantl, I used variable as shown by you for showing links between the node.

@dblaikie I have shortened the test case based on your suggestions. There were 
no test case for checking `unspecified_type(auto)` that is why I am will to add 
this.


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,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)
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 

[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-03 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

@shafik Can you speak about whether this feature ("auto" return type in DWARF 
v5 section 5.2) would be useful for LLDB?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-03 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D70524#1761514 , @awpandey wrote:

> Hi @aprantl  and @dblaikie. Currently, there is no test case for the 
> unspecified type, so I have added that in the regression test suite.


It looks to me like there are a few tests for unspecified_type already:

$ grep -r unspecified_type llvm/test
llvm/test/Assembler/debug-info.ll:; CHECK-NEXT: !7 = !DIBasicType(tag: 
DW_TAG_unspecified_type, name: "decltype(nullptr)")
llvm/test/Assembler/debug-info.ll:!8 = !DIBasicType(tag: 
DW_TAG_unspecified_type, name: "decltype(nullptr)")
llvm/test/DebugInfo/COFF/types-std-nullptr-t.ll:!6 = !DIBasicType(tag: 
DW_TAG_unspecified_type, name: "decltype(nullptr)")
llvm/test/DebugInfo/X86/template.ll:; VERIFY-NOT: error: DIE has DW_AT_type 
with incompatible tag DW_TAG_unspecified_type
llvm/test/DebugInfo/X86/template.ll:; CHECK: [[NULLPTR]]:{{ 
*}}DW_TAG_unspecified_type
llvm/test/DebugInfo/X86/template.ll:!34 = !DIBasicType(tag: 
DW_TAG_unspecified_type, name: "decltype(nullptr)")

@aprantl @probinson - I'm going to voice a little more objection to this 
feature as I think I did when it was being discussed for DWARF standardization 
- feel free to push back/veto me/etc: Describing this seems of limited value to 
consumers - the function cannot be called if the return type hasn't been 
resolved. I think modeling these sort of situations the same way member 
function templates are would be fine - omit the declaration entirely in 
translation units that have no function definition for an auto-returning 
function.

The only difference between this and templates is that we /can/ describe it & 
it can be useful for overload resolution - but the same is true of all 
functions (non-member, member, etc) & no DWARF producer I know of produces all 
function declarations into their output, so I'm not sure "make overload 
resolution work" is really a worthwhile goal. (without template descripttions 
(not the instantiations, but the templates themselves which we currently have 
no way of describing even if we wanted to) I don't think it's actually 
achievable)




Comment at: clang/test/CodeGenCXX/debug-info-auto-return.cpp:12-15
+class myClass {
+  int low, high;
+
+public:

I'd probably make this a struct, rather than a class with a public member - 
access modifiers aren't relevant to this test, so far as I can tell, so might 
as well just have everything public by using a struct.



Comment at: clang/test/CodeGenCXX/debug-info-auto-return.cpp:13
+class myClass {
+  int low, high;
+

No need for any member variables, I think?



Comment at: clang/test/CodeGenCXX/debug-info-auto-return.cpp:20-23
+  if (low > high)
+return 1;
+  else
+return 1;

Could strip out the body here - leave a single "return 0;" in there if that's 
useful/needed.



Comment at: llvm/test/DebugInfo/X86/debug-info-auto-return.ll:5-25
+;class myClass {
+;int low, high;
+;
+;  public:
+;  myClass(int a, int b) {
+;low = a;
+;high = b;

This code seems more complicated than it needs to be (it doesn't need any logic 
in the body of the functions, for instance, I think? Nor any member variables, 
nor 'main', etc) & the indentation should be fixed/made consistent.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-12-02 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:2925
+return C.getQualifiedType(T.getTypePtr(), Quals);
+  }
 case Type::DeducedTemplateSpecialization: {

aprantl wrote:
> You need to mark this `LLVM_FALLTHROUGH` now or you'll get a warning.
The FALLTHROUGH must come right before the next `case`



Comment at: clang/test/CodeGenCXX/debug-info-auto-return.cpp:7
+
+// CHECK: !DISubprogram(name: "findMax",{{.*}}, type: !18
+// CHECK: !18 =  !DISubroutineType(types: !19)

aprantl wrote:
> Please don't hardcode the MDNode numbers, they will inevitably change over 
> time. Instead use variables:
> ```
> type: ![[SUBROUTINE_TYPE:[0-9]+]]`
> // CHECK: ![[SUBROUTINE_TYPE]] =  !DISubroutineType(types: ![[ARGS:[0-9]+)
> ```
> etc
you still need to make sure that the two nodes CHECKed are being connected. 
Please use variables like in the example I posted.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-27 Thread Awanish Pandey via Phabricator via cfe-commits
awpandey updated this revision to Diff 231208.
awpandey marked 5 inline comments as done.
awpandey added a comment.

Hi @aprantl  and @dblaikie. Currently, there is no test case for the 
unspecified type, so I have added that in the regression test suite. Also, I 
have incorporated all of your suggestions.


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 {{.*}} 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

[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-22 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

In D70524#1757237 , @dblaikie wrote:

> Generally if you're not touching LLVM code, I would suggest not adding an 
> LLVM test - unless this is new or surprising usage of existing LLVM 
> functionality (or the functionality was otherwise undertested in LLVM 
> previously). But I'm guessing that's not the case here?


The rephrase the question David is asking: Do we already have an LLVM test for 
a named unspecified type?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-22 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Generally if you're not touching LLVM code, I would suggest not adding an LLVM 
test - unless this is new or surprising usage of existing LLVM functionality 
(or the functionality was otherwise undertested in LLVM previously). But I'm 
guessing that's not the case here?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-22 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: llvm/test/DebugInfo/X86/debug-info-auto-return.ll:1
+;RUN: %llc_dwarf %s -filetype=obj -o - | llvm-dwarfdump -v - | FileCheck %s
+

I don't think the FORMs are relevant for this test, so we can do without the 
`-v`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-22 Thread Paul Robinson via Phabricator via cfe-commits
probinson added inline comments.



Comment at: llvm/test/DebugInfo/X86/debug-info-auto-return.ll:30
+; CHECK:  DW_TAG_subprogram [7] *
+; CHECK-NEXT: DW_AT_linkage_name [DW_FORM_strx1](indexed (0007) string 
= "_ZN7myClass7findMaxEv")
+; CHECK: DW_AT_type [DW_FORM_ref4] {{.*}} "auto"

No need to over-specify this (form/index etc) as those details can change over 
time and aren't relevant to the test.  Sufficient to check
`DW_AT_linkage_name {{.*}} "_ZN7myClass7findMaxEv"`



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-22 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:2925
+return C.getQualifiedType(T.getTypePtr(), Quals);
+  }
 case Type::DeducedTemplateSpecialization: {

You need to mark this `LLVM_FALLTHROUGH` now or you'll get a warning.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:3104
   case Type::Auto:
+if (CGM.getCodeGenOpts().DwarfVersion >= 5) {
+  return CreateType(cast(Ty));

LLVM coding style doesn't put single statements into `{}`



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:3106
+  return CreateType(cast(Ty));
+}
   case Type::Attributed:

same here



Comment at: clang/test/CodeGenCXX/debug-info-auto-return.cpp:7
+
+// CHECK: !DISubprogram(name: "findMax",{{.*}}, type: !18
+// CHECK: !18 =  !DISubroutineType(types: !19)

Please don't hardcode the MDNode numbers, they will inevitably change over 
time. Instead use variables:
```
type: ![[SUBROUTINE_TYPE:[0-9]+]]`
// CHECK: ![[SUBROUTINE_TYPE]] =  !DISubroutineType(types: ![[ARGS:[0-9]+)
```
etc


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-22 Thread Awanish Pandey via Phabricator via cfe-commits
awpandey marked 2 inline comments as done.
awpandey added a comment.

Thanks @aprantl  for your suggestions. I have revised by patch based on that.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-22 Thread Awanish Pandey via Phabricator via cfe-commits
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 (0007) 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
+  

[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-21 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:822
+  auto BTName = "auto";
+  return DBuilder.createUnspecifiedType(BTName);
+}

` DBuilder.createUnspecifiedType("auto")`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-21 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

Thanks! Couple of minor comments inline.




Comment at: clang/test/CodeGenCXX/debug-info-auto-return.cpp:2
+//  Test for debug info for C++11 auto return member functions
+// Supported: -O0, standalone DI
+// RUN: %clang_cc1 -dwarf-version=5  -emit-llvm -triple x86_64-linux-gnu %s -o 
- \

What does this comment mean? This should work regardless of optimization level, 
right?



Comment at: clang/test/CodeGenCXX/debug-info-auto-return.cpp:8
+
+// CHECK: !DIBasicType(tag: DW_TAG_unspecified_type, name: "auto")
+

Can you also CHECK that it is attached to the node we're expecting it to?



Comment at: llvm/test/DebugInfo/X86/debug-info-auto-return.ll:1
+;RUN: llc %s -filetype=obj -o - | llvm-dwarfdump -v - | FileCheck %s
+

I think you may need %llc_dwarf here to avoid problems on Windows bots?



Comment at: llvm/test/DebugInfo/X86/debug-info-auto-return.ll:110
+
+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 }

please remove all unnecessary (quoted) attributes. This makes the test easier 
to maintain and read.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70524/new/

https://reviews.llvm.org/D70524



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-20 Thread Awanish Pandey via Phabricator via cfe-commits
awpandey created this revision.
awpandey added reviewers: jini.susan.george, SouraVX, alok, aprantl, dblaikie.
awpandey added projects: clang, LLVM, debug-info.
Herald added subscribers: llvm-commits, cfe-commits, ormris.

This patch will provide support for auto return type for the C++ member 
functions. Before this return type of the member function is deduced and store 
in the DIE.


Repository:
  rG LLVM Github Monorepo

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 %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 (0007) 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 =