Re: [PATCH] D21141: [DebugInfo] Add calling conventions to DISubroutineType

2016-06-08 Thread Reid Kleckner via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL272198: [DebugInfo] Add calling conventions to 
DISubroutineType (authored by rnk).

Changed prior to commit:
  http://reviews.llvm.org/D21141?vs=60055&id=60101#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D21141

Files:
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
  cfe/trunk/test/CodeGenCXX/debug-info-calling-conventions.cpp

Index: cfe/trunk/test/CodeGenCXX/debug-info-calling-conventions.cpp
===
--- cfe/trunk/test/CodeGenCXX/debug-info-calling-conventions.cpp
+++ cfe/trunk/test/CodeGenCXX/debug-info-calling-conventions.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -triple=i686-pc-windows-msvc -debug-info-kind=limited -emit-llvm -o - | FileCheck %s
+
+struct A {
+  void thiscallcc();
+};
+void A::thiscallcc() {}
+
+// CHECK: !DISubprogram(name: "thiscallcc", {{.*}} type: ![[thiscallty:[^,]*]], {{.*}})
+// CHECK: ![[thiscallty]] = !DISubroutineType(cc: DW_CC_BORLAND_thiscall, types: ![[thisargs:[^,)]*]])
+// CHECK: ![[thisargs]] = !{null, ![[thisptrty:[^,}]*]]}
+// CHECK: ![[thisptrty]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{.*}}, size: 32, align: 32, flags: DIFlagArtificial | DIFlagObjectPointer)
+
+void cdeclcc() {}
+void __fastcall fastcallcc() {}
+void __stdcall stdcallcc() {}
+void __vectorcall vectorcallcc() {}
+
+// CHECK: !DISubprogram(name: "cdeclcc", {{.*}} type: ![[cdeclty:[^,]*]], {{.*}})
+// CHECK: ![[cdeclty]] = !DISubroutineType(types: ![[noargs:[^,)]*]])
+// CHECK: ![[noargs]] = !{null}
+// CHECK: !DISubprogram(name: "fastcallcc", {{.*}} type: ![[fastcallty:[^,]*]], {{.*}})
+// CHECK: ![[fastcallty]] = !DISubroutineType(cc: DW_CC_BORLAND_msfastcall, types: ![[noargs]])
+// CHECK: !DISubprogram(name: "stdcallcc", {{.*}} type: ![[stdcallty:[^,]*]], {{.*}})
+// CHECK: ![[stdcallty]] = !DISubroutineType(cc: DW_CC_BORLAND_stdcall, types: ![[noargs]])
+// CHECK: !DISubprogram(name: "vectorcallcc", {{.*}} type: ![[vectorcallty:[^,]*]], {{.*}})
+// CHECK: ![[vectorcallty]] = !DISubroutineType(cc: DW_CC_LLVM_vectorcall, types: ![[noargs]])
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -831,6 +831,39 @@
   getDeclContextDescriptor(Ty->getDecl()));
 }
 
+static unsigned getDwarfCC(CallingConv CC) {
+  switch (CC) {
+  case CC_C:
+// Avoid emitting DW_AT_calling_convention if the C convention was used.
+return 0;
+
+  case CC_X86StdCall:
+return llvm::dwarf::DW_CC_BORLAND_stdcall;
+  case CC_X86FastCall:
+return llvm::dwarf::DW_CC_BORLAND_msfastcall;
+  case CC_X86ThisCall:
+return llvm::dwarf::DW_CC_BORLAND_thiscall;
+  case CC_X86VectorCall:
+return llvm::dwarf::DW_CC_LLVM_vectorcall;
+  case CC_X86Pascal:
+return llvm::dwarf::DW_CC_BORLAND_pascal;
+
+  // FIXME: Create new DW_CC_ codes for these calling conventions.
+  case CC_X86_64Win64:
+  case CC_X86_64SysV:
+  case CC_AAPCS:
+  case CC_AAPCS_VFP:
+  case CC_IntelOclBicc:
+  case CC_SpirFunction:
+  case CC_SpirKernel:
+  case CC_Swift:
+  case CC_PreserveMost:
+  case CC_PreserveAll:
+return 0;
+  }
+  return 0;
+}
+
 llvm::DIType *CGDebugInfo::CreateType(const FunctionType *Ty,
   llvm::DIFile *Unit) {
   SmallVector EltTys;
@@ -850,7 +883,8 @@
   }
 
   llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
-  return DBuilder.createSubroutineType(EltTypeArray);
+  return DBuilder.createSubroutineType(EltTypeArray, 0,
+   getDwarfCC(Ty->getCallConv()));
 }
 
 /// Convert an AccessSpecifier into the corresponding DINode flag.
@@ -1103,7 +1137,8 @@
   if (Func->getExtProtoInfo().RefQualifier == RQ_RValue)
 Flags |= llvm::DINode::FlagRValueReference;
 
-  return DBuilder.createSubroutineType(EltTypeArray, Flags);
+  return DBuilder.createSubroutineType(EltTypeArray, Flags,
+   getDwarfCC(Func->getCallConv()));
 }
 
 /// isFunctionLocalClass - Return true if CXXRecordDecl is defined
@@ -2562,9 +2597,9 @@
   SmallVector ArgTypes;
   for (const ParmVarDecl *Parm: FD->parameters())
 ArgTypes.push_back(Parm->getType());
-  QualType FnType =
-CGM.getContext().getFunctionType(FD->getReturnType(), ArgTypes,
- FunctionProtoType::ExtProtoInfo());
+  CallingConv CC = FD->getType()->castAs()->getCallConv();
+  QualType FnType = CGM.getContext().getFunctionType(
+  FD->getReturnType(), ArgTypes, FunctionProtoType::ExtProtoInfo(CC));
   llvm::DISubprogram *SP = DBuilder.createTempFunctionFwdDecl(
   DContext, Name, LinkageName, Unit, Line,
   getOrCreateFunctionType(FD, FnType, Unit), !FD->isExternallyVisible(),
@@ -2668,6 +2703,10 @@
 
   if (const CXXMethodDecl *Method = d

Re: [PATCH] D21141: [DebugInfo] Add calling conventions to DISubroutineType

2016-06-08 Thread Adrian Prantl via cfe-commits
aprantl accepted this revision.
aprantl added a comment.
This revision is now accepted and ready to land.

Function pointers make sense to me, thanks!
LGTM



Comment at: lib/CodeGen/CGDebugInfo.cpp:834
@@ -833,1 +833,3 @@
 
+static unsigned getDwarfCC(CallingConv CC) {
+  switch (CC) {

I just wanted to say that it would be nice to have this function in DIBuilder, 
but then realized that CallingConv is defined in clang.


http://reviews.llvm.org/D21141



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


Re: [PATCH] D21141: [DebugInfo] Add calling conventions to DISubroutineType

2016-06-08 Thread Reid Kleckner via cfe-commits
rnk added a comment.

In http://reviews.llvm.org/D21141#452517, @aprantl wrote:

> Assuming that we could usually get the calling convention from the Function — 
> what's the motivation for emitting the calling convention of a subprogram 
> that has been optimized away?


I don't have any motivation to emit DISubprograms for optimized away code, but 
Functions aren't always available. Function pointers can also have calling 
conventions, and they will only have a DISubroutineType.


http://reviews.llvm.org/D21141



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


Re: [PATCH] D21141: [DebugInfo] Add calling conventions to DISubroutineType

2016-06-08 Thread Adrian Prantl via cfe-commits
aprantl added a comment.

Assuming that we could usually get the calling convention from the Function — 
what's the motivation for emitting the calling convention of a subprogram that 
has been optimized away?


http://reviews.llvm.org/D21141



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


[PATCH] D21141: [DebugInfo] Add calling conventions to DISubroutineType

2016-06-08 Thread Reid Kleckner via cfe-commits
rnk created this revision.
rnk added reviewers: aprantl, dblaikie.
rnk added a subscriber: cfe-commits.
rnk added a dependency: D21114: [DebugInfo] Add calling convention support for 
DWARF and CodeView.

This should have been a very simple change, but it was greatly
complicated by the construction of new Decls during IR generation.

In particular, we reconstruct the AST function type in order to get the
implicit 'this' parameter into C++ method types.

We also have to worry about FunctionDecls whose types are not
FunctionTypes because CGBlocks.cpp constructs some dummy FunctionDecls
with 'void' type.

Depends on D21114

http://reviews.llvm.org/D21141

Files:
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenFunction.cpp
  test/CodeGenCXX/debug-info-calling-conventions.cpp

Index: test/CodeGenCXX/debug-info-calling-conventions.cpp
===
--- /dev/null
+++ test/CodeGenCXX/debug-info-calling-conventions.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -triple=i686-pc-windows-msvc -debug-info-kind=limited -emit-llvm -o - | FileCheck %s
+
+struct A {
+  void thiscallcc();
+};
+void A::thiscallcc() {}
+
+// CHECK: !DISubprogram(name: "thiscallcc", {{.*}} type: ![[thiscallty:[^,]*]], {{.*}})
+// CHECK: ![[thiscallty]] = !DISubroutineType(cc: DW_CC_BORLAND_thiscall, types: ![[thisargs:[^,)]*]])
+// CHECK: ![[thisargs]] = !{null, ![[thisptrty:[^,}]*]]}
+// CHECK: ![[thisptrty]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{.*}}, size: 32, align: 32, flags: DIFlagArtificial | DIFlagObjectPointer)
+
+void cdeclcc() {}
+void __fastcall fastcallcc() {}
+void __stdcall stdcallcc() {}
+void __vectorcall vectorcallcc() {}
+
+// CHECK: !DISubprogram(name: "cdeclcc", {{.*}} type: ![[cdeclty:[^,]*]], {{.*}})
+// CHECK: ![[cdeclty]] = !DISubroutineType(types: ![[noargs:[^,)]*]])
+// CHECK: ![[noargs]] = !{null}
+// CHECK: !DISubprogram(name: "fastcallcc", {{.*}} type: ![[fastcallty:[^,]*]], {{.*}})
+// CHECK: ![[fastcallty]] = !DISubroutineType(cc: DW_CC_BORLAND_msfastcall, types: ![[noargs]])
+// CHECK: !DISubprogram(name: "stdcallcc", {{.*}} type: ![[stdcallty:[^,]*]], {{.*}})
+// CHECK: ![[stdcallty]] = !DISubroutineType(cc: DW_CC_BORLAND_stdcall, types: ![[noargs]])
+// CHECK: !DISubprogram(name: "vectorcallcc", {{.*}} type: ![[vectorcallty:[^,]*]], {{.*}})
+// CHECK: ![[vectorcallty]] = !DISubroutineType(cc: DW_CC_LLVM_vectorcall, types: ![[noargs]])
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -762,15 +762,18 @@
 
   // Emit subprogram debug descriptor.
   if (CGDebugInfo *DI = getDebugInfo()) {
+// Reconstruct the type from the argument list so that implicit parameters,
+// such as 'this' and 'vtt', show up in the debug info. Preserve the calling
+// convention.
+CallingConv CC = CallingConv::CC_C;
+if (auto *FD = dyn_cast_or_null(D))
+  if (const auto *SrcFnTy = FD->getType()->getAs())
+CC = SrcFnTy->getCallConv();
 SmallVector ArgTypes;
-for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
-	 i != e; ++i) {
-  ArgTypes.push_back((*i)->getType());
-}
-
-QualType FnType =
-  getContext().getFunctionType(RetTy, ArgTypes,
-   FunctionProtoType::ExtProtoInfo());
+for (const VarDecl *VD : Args)
+  ArgTypes.push_back(VD->getType());
+QualType FnType = getContext().getFunctionType(
+RetTy, ArgTypes, FunctionProtoType::ExtProtoInfo(CC));
 DI->EmitFunctionStart(GD, Loc, StartLoc, FnType, CurFn, Builder);
   }
 
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -831,6 +831,39 @@
   getDeclContextDescriptor(Ty->getDecl()));
 }
 
+static unsigned getDwarfCC(CallingConv CC) {
+  switch (CC) {
+  case CC_C:
+// Avoid emitting DW_AT_calling_convention if the C convention was used.
+return 0;
+
+  case CC_X86StdCall:
+return llvm::dwarf::DW_CC_BORLAND_stdcall;
+  case CC_X86FastCall:
+return llvm::dwarf::DW_CC_BORLAND_msfastcall;
+  case CC_X86ThisCall:
+return llvm::dwarf::DW_CC_BORLAND_thiscall;
+  case CC_X86VectorCall:
+return llvm::dwarf::DW_CC_LLVM_vectorcall;
+  case CC_X86Pascal:
+return llvm::dwarf::DW_CC_BORLAND_pascal;
+
+  // FIXME: Create new DW_CC_ codes for these calling conventions.
+  case CC_X86_64Win64:
+  case CC_X86_64SysV:
+  case CC_AAPCS:
+  case CC_AAPCS_VFP:
+  case CC_IntelOclBicc:
+  case CC_SpirFunction:
+  case CC_SpirKernel:
+  case CC_Swift:
+  case CC_PreserveMost:
+  case CC_PreserveAll:
+return 0;
+  }
+  return 0;
+}
+
 llvm::DIType *CGDebugInfo::CreateType(const FunctionType *Ty,
   llvm::DIFile *Unit) {
   SmallVector EltTys;
@@ -850,7 +883,8 @@
   }
 
   llvm::DITypeRefArray Elt