r332296 - [CodeView] Improve debugging of virtual base class member variables

2018-05-15 Thread Brock Wyma via cfe-commits
Author: bwyma
Date: Mon May 14 14:21:22 2018
New Revision: 332296

URL: http://llvm.org/viewvc/llvm-project?rev=332296&view=rev
Log:
[CodeView] Improve debugging of virtual base class member variables

Initial support for passing the virtual base pointer offset to CodeViewDebug.

https://reviews.llvm.org/D46271


Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/test/CodeGenCXX/debug-info-access.cpp
cfe/trunk/test/CodeGenCXX/debug-info-ms-vbase.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=332296&r1=332295&r2=332296&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon May 14 14:21:22 2018
@@ -1536,6 +1536,7 @@ void CGDebugInfo::CollectCXXBasesAux(
 auto *BaseTy = getOrCreateType(BI.getType(), Unit);
 llvm::DINode::DIFlags BFlags = StartingFlags;
 uint64_t BaseOffset;
+uint32_t VBPtrOffset = 0;
 
 if (BI.isVirtual()) {
   if (CGM.getTarget().getCXXABI().isItaniumFamily()) {
@@ -1549,6 +1550,8 @@ void CGDebugInfo::CollectCXXBasesAux(
 // vbase offset offset in Itanium.
 BaseOffset =
 4 * CGM.getMicrosoftVTableContext().getVBTableIndex(RD, Base);
+VBPtrOffset = CGM.getContext().getASTRecordLayout(RD).getVBPtrOffset()
+ .getQuantity();
   }
   BFlags |= llvm::DINode::FlagVirtual;
 } else
@@ -1558,7 +1561,8 @@ void CGDebugInfo::CollectCXXBasesAux(
 
 BFlags |= getAccessFlag(BI.getAccessSpecifier(), RD);
 llvm::DIType *DTy =
-DBuilder.createInheritance(RecordTy, BaseTy, BaseOffset, BFlags);
+DBuilder.createInheritance(RecordTy, BaseTy, BaseOffset, VBPtrOffset,
+   BFlags);
 EltTys.push_back(DTy);
   }
 }
@@ -2192,7 +2196,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDef
 if (!SClassTy)
   return nullptr;
 
-llvm::DIType *InhTag = DBuilder.createInheritance(RealDecl, SClassTy, 0,
+llvm::DIType *InhTag = DBuilder.createInheritance(RealDecl, SClassTy, 0, 0,
   llvm::DINode::FlagZero);
 EltTys.push_back(InhTag);
   }

Modified: cfe/trunk/test/CodeGenCXX/debug-info-access.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-access.cpp?rev=332296&r1=332295&r2=332296&view=diff
==
--- cfe/trunk/test/CodeGenCXX/debug-info-access.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-access.cpp Mon May 14 14:21:22 2018
@@ -10,7 +10,7 @@ struct A {
 };
 
 
-// CHECK: !DIDerivedType(tag: DW_TAG_inheritance,{{.*}} baseType: 
![[A]],{{.*}} flags: DIFlagPublic)
+// CHECK: !DIDerivedType(tag: DW_TAG_inheritance,{{.*}} baseType: 
![[A]],{{.*}} flags: DIFlagPublic, extraData: i32 0)
 class B : public A {
 public:
   // CHECK-DAG: !DISubprogram(name: "pub",{{.*}} line: [[@LINE+1]],{{.*}} 
flags: DIFlagPublic | DIFlagPrototyped,

Modified: cfe/trunk/test/CodeGenCXX/debug-info-ms-vbase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-ms-vbase.cpp?rev=332296&r1=332295&r2=332296&view=diff
==
--- cfe/trunk/test/CodeGenCXX/debug-info-ms-vbase.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-ms-vbase.cpp Mon May 14 14:21:22 2018
@@ -8,7 +8,7 @@
 // CHECK: ![[elements]] = !{![[NoPrimaryBase_base:[0-9]+]]}
 
 // CHECK: ![[NoPrimaryBase_base]] = !DIDerivedType(tag: DW_TAG_inheritance, 
scope: ![[NoPrimaryBase]],
-// CHECK-SAME: baseType: ![[HasVirtualMethod:[0-9]+]], offset: 4, flags: 
DIFlagVirtual)
+// CHECK-SAME: baseType: ![[HasVirtualMethod:[0-9]+]], offset: 4, flags: 
DIFlagVirtual, extraData: i32 0)
 
 // CHECK: ![[HasVirtualMethod]] = distinct !DICompositeType(tag: 
DW_TAG_structure_type, name: "HasVirtualMethod"
 
@@ -18,11 +18,11 @@
 // CHECK: ![[elements]] = !{![[SecondaryVTable_base:[0-9]+]], 
![[HasVirtualMethod_base:[0-9]+]], ![[vshape:[0-9]+]]}
 
 // CHECK: ![[SecondaryVTable_base]] = !DIDerivedType(tag: DW_TAG_inheritance, 
scope: ![[HasPrimaryBase]],
-// CHECK-SAME: baseType: ![[SecondaryVTable:[0-9]+]], offset: 4, flags: 
DIFlagVirtual)
+// CHECK-SAME: baseType: ![[SecondaryVTable:[0-9]+]], offset: 4, flags: 
DIFlagVirtual, extraData: i32 4)
 
 // CHECK: ![[SecondaryVTable]] = distinct !DICompositeType(tag: 
DW_TAG_structure_type, name: "SecondaryVTable"
 
-// CHECK: ![[HasVirtualMethod_base]] = !DIDerivedType(tag: DW_TAG_inheritance, 
scope: ![[HasPrimaryBase]], baseType: ![[HasVirtualMethod]])
+// CHECK: ![[HasVirtualMethod_base]] = !DIDerivedType(tag: DW_TAG_inheritance, 
scope: ![[HasPrimaryBase]], baseType: ![[HasVirtualMethod]], extraData: i32 0)
 
 // CHECK: ![[HasIndirectVirtualBase:[0-9]+]] = distinct !DICompositeType(tag: 
DW_TAG_st

r332975 - [CodeView] Enable debugging of captured variables within C++ lambdas

2018-05-22 Thread Brock Wyma via cfe-commits
Author: bwyma
Date: Tue May 22 05:41:19 2018
New Revision: 332975

URL: http://llvm.org/viewvc/llvm-project?rev=332975&view=rev
Log:

[CodeView] Enable debugging of captured variables within C++ lambdas

This change will help Visual Studio resolve forward references to C++ lambda
routines used by captured variables.

Differential Revision: https://reviews.llvm.org/D45438


Added:
cfe/trunk/test/CodeGen/debug-info-codeview-unnamed.c
cfe/trunk/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=332975&r1=332974&r2=332975&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue May 22 05:41:19 2018
@@ -801,22 +801,46 @@ static bool hasCXXMangling(const TagDecl
   }
 }
 
-/// In C++ mode, types have linkage, so we can rely on the ODR and
-/// on their mangled names, if they're external.
-static SmallString<256> getUniqueTagTypeName(const TagType *Ty,
- CodeGenModule &CGM,
- llvm::DICompileUnit *TheCU) {
-  SmallString<256> FullName;
+// Determines if the tag declaration will require a type identifier.
+static bool needsTypeIdentifier(const TagDecl *TD,
+CodeGenModule& CGM,
+llvm::DICompileUnit *TheCU) {
+  // We only add a type identifier for types with C++ name mangling.
+  if (!hasCXXMangling(TD, TheCU))
+return false;
+
+  // CodeView types with C++ mangling need a type identifier.
+  if (CGM.getCodeGenOpts().EmitCodeView)
+return true;
+
+  // Externally visible types with C++ mangling need a type identifier.
+  if (TD->isExternallyVisible())
+return true;
+
+  return false;
+}
+
+// When emitting CodeView debug information we need to produce a type
+// identifier for all types which have a C++ mangling.  Until a GUID is added
+// to the identifier (not currently implemented) the result will not be unique
+// across compilation units.
+// When emitting DWARF debug information, we need to produce a type identifier
+// for all externally visible types with C++ name mangling. This identifier
+// should be unique across ODR-compliant compilation units.
+static SmallString<256> getTypeIdentifier(const TagType *Ty,
+  CodeGenModule &CGM,
+  llvm::DICompileUnit *TheCU) {
+  SmallString<256> Identifier;
   const TagDecl *TD = Ty->getDecl();
 
-  if (!hasCXXMangling(TD, TheCU) || !TD->isExternallyVisible())
-return FullName;
+  if (!needsTypeIdentifier(TD, CGM, TheCU))
+return Identifier;
 
   // TODO: This is using the RTTI name. Is there a better way to get
   // a unique string for a type?
-  llvm::raw_svector_ostream Out(FullName);
+  llvm::raw_svector_ostream Out(Identifier);
   CGM.getCXXABI().getMangleContext().mangleCXXRTTIName(QualType(Ty, 0), Out);
-  return FullName;
+  return Identifier;
 }
 
 /// \return the appropriate DWARF tag for a composite type.
@@ -849,10 +873,10 @@ CGDebugInfo::getOrCreateRecordFwdDecl(co
   uint32_t Align = 0;
 
   // Create the type.
-  SmallString<256> FullName = getUniqueTagTypeName(Ty, CGM, TheCU);
+  SmallString<256> Identifier = getTypeIdentifier(Ty, CGM, TheCU);
   llvm::DICompositeType *RetTy = DBuilder.createReplaceableCompositeType(
   getTagForRecord(RD), RDName, Ctx, DefUnit, Line, 0, Size, Align,
-  llvm::DINode::FlagFwdDecl, FullName);
+  llvm::DINode::FlagFwdDecl, Identifier);
   if (CGM.getCodeGenOpts().DebugFwdTemplateParams)
 if (auto *TSpecial = dyn_cast(RD))
   DBuilder.replaceArrays(RetTy, llvm::DINodeArray(),
@@ -2477,7 +2501,7 @@ llvm::DIType *CGDebugInfo::CreateEnumTyp
 Align = getDeclAlignIfRequired(ED, CGM.getContext());
   }
 
-  SmallString<256> FullName = getUniqueTagTypeName(Ty, CGM, TheCU);
+  SmallString<256> Identifier = getTypeIdentifier(Ty, CGM, TheCU);
 
   bool isImportedFromModule =
   DebugTypeExtRefs && ED->isFromASTFile() && ED->getDefinition();
@@ -2500,7 +2524,7 @@ llvm::DIType *CGDebugInfo::CreateEnumTyp
 StringRef EDName = ED->getName();
 llvm::DIType *RetTy = DBuilder.createReplaceableCompositeType(
 llvm::dwarf::DW_TAG_enumeration_type, EDName, EDContext, DefUnit, Line,
-0, Size, Align, llvm::DINode::FlagFwdDecl, FullName);
+0, Size, Align, llvm::DINode::FlagFwdDecl, Identifier);
 
 ReplaceMap.emplace_back(
 std::piecewise_construct, std::make_tuple(Ty),
@@ -2520,7 +2544,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDef
 Align = getDeclAlignIfRequired(ED, CGM.getContext());
   }
 
-  SmallString<256> FullName = getUniqueTagTypeName(Ty, CGM, TheCU);
+  SmallString<256> Identifier = getTypeIdentifier(

r330132 - [CodeView] Initial support for emitting S_THUNK32 symbols for compiler...

2018-04-16 Thread Brock Wyma via cfe-commits
Author: bwyma
Date: Mon Apr 16 09:53:57 2018
New Revision: 330132

URL: http://llvm.org/viewvc/llvm-project?rev=330132&view=rev
Log:
[CodeView] Initial support for emitting S_THUNK32 symbols for compiler...

When emitting CodeView debug information, compiler-generated thunk routines
should be emitted using S_THUNK32 symbols instead of S_GPROC32_ID symbols so
Visual Studio can properly step into the user code.  This initial support only
handles standard thunk ordinals.

Differential Revision: https://reviews.llvm.org/D43838


Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/test/CodeGenCXX/debug-info-thunk.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=330132&r1=330131&r2=330132&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Apr 16 09:53:57 2018
@@ -3217,7 +3217,8 @@ llvm::DISubroutineType *CGDebugInfo::get
 
 void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
 SourceLocation ScopeLoc, QualType FnType,
-llvm::Function *Fn, CGBuilderTy &Builder) {
+llvm::Function *Fn, bool CurFuncIsThunk,
+CGBuilderTy &Builder) {
 
   StringRef Name;
   StringRef LinkageName;
@@ -3263,6 +3264,10 @@ void CGDebugInfo::EmitFunctionStart(Glob
 // Artificial functions should not silently reuse CurLoc.
 CurLoc = SourceLocation();
   }
+
+  if (CurFuncIsThunk)
+Flags |= llvm::DINode::FlagThunk;
+
   unsigned LineNo = getLineNumber(Loc);
   unsigned ScopeLine = getLineNumber(ScopeLoc);
 

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=330132&r1=330131&r2=330132&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Mon Apr 16 09:53:57 2018
@@ -366,7 +366,8 @@ public:
   /// \param ScopeLoc  The location of the function body.
   void EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
  SourceLocation ScopeLoc, QualType FnType,
- llvm::Function *Fn, CGBuilderTy &Builder);
+ llvm::Function *Fn, bool CurFnIsThunk,
+ CGBuilderTy &Builder);
 
   /// Start a new scope for an inlined function.
   void EmitInlineFunctionStart(CGBuilderTy &Builder, GlobalDecl GD);

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=330132&r1=330131&r2=330132&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Mon Apr 16 09:53:57 2018
@@ -1018,7 +1018,8 @@ void CodeGenFunction::StartFunction(Glob
   ArgTypes.push_back(VD->getType());
 QualType FnType = getContext().getFunctionType(
 RetTy, ArgTypes, FunctionProtoType::ExtProtoInfo(CC));
-DI->EmitFunctionStart(GD, Loc, StartLoc, FnType, CurFn, Builder);
+DI->EmitFunctionStart(GD, Loc, StartLoc, FnType, CurFn, CurFuncIsThunk,
+  Builder);
   }
 
   if (ShouldInstrumentFunction()) {

Modified: cfe/trunk/test/CodeGenCXX/debug-info-thunk.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-thunk.cpp?rev=330132&r1=330131&r2=330132&view=diff
==
--- cfe/trunk/test/CodeGenCXX/debug-info-thunk.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-thunk.cpp Mon Apr 16 09:53:57 2018
@@ -1,29 +1,277 @@
-// RUN: %clang_cc1 %s -triple %itanium_abi_triple -debug-info-kind=limited -S 
-emit-llvm -o - | FileCheck %s
-
-struct A {
-  virtual void f();
-};
-
-struct B {
-  virtual void f();
-};
-
-struct C : A, B {
-  virtual void f();
-};
-
-void C::f() { }
-// CHECK: define {{.*}}void @_ZThn{{[48]}}_N1C1fEv
-// CHECK-SAME: !dbg ![[SP:[0-9]+]]
-// CHECK-NOT: {{ret }}
-// CHECK: = load{{.*}} !dbg ![[DBG:[0-9]+]]
-// CHECK-NOT: {{ret }}
-// CHECK: ret void, !dbg ![[DBG]]
+// RUN: %clang_cc1 %s -triple=x86_64-pc-windows-msvc -debug-info-kind=limited 
-S -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -debug-info-kind=limited -S 
-emit-llvm -o - | FileCheck %s -check-prefix=ITANIUM
+//
+// Validate we emit a "DIFlagThunk" flag on DISubprogram entries for thunks.
+// This flag is used for emitting S_THUNK32 symbols for CodeView debugging.
+//
+// NOTE:
+// Because thunks are compiler generated and don't exist in the source, 

[clang] [Clang][OpenCL][AMDGPU] Allow a kernel to call another kernel (PR #115821)

2025-04-14 Thread Brock Wyma via cfe-commits

bwyma wrote:

@t-tye Would you mind reviewing this patch from a debug perspective?

Potentially multiple subprograms with the same source name, same source 
correlation in different routines, missing artificial or trampoline attributes, 
stepping between functions works as expected, etc. Your input would be 
appreciated.

https://github.com/llvm/llvm-project/pull/115821
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits