Re: r272198 - [DebugInfo] Add calling conventions to DISubroutineType

2016-06-08 Thread David Blaikie via cfe-commits
At least in theory it'd be nice to have test cases for the other call sites
this change adds CC to.

On Wed, Jun 8, 2016 at 1:41 PM, Reid Kleckner via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rnk
> Date: Wed Jun  8 15:41:54 2016
> New Revision: 272198
>
> URL: http://llvm.org/viewvc/llvm-project?rev=272198=rev
> Log:
> [DebugInfo] Add calling conventions to DISubroutineType
>
> Summary:
> 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
>
> Reviewers: aprantl, dblaikie
>
> Subscribers: cfe-commits
>
> Differential Revision: http://reviews.llvm.org/D21141
>
> Added:
> cfe/trunk/test/CodeGenCXX/debug-info-calling-conventions.cpp
> Modified:
> cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=272198=272197=272198=diff
>
> ==
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Jun  8 15:41:54 2016
> @@ -831,6 +831,39 @@ llvm::DIType *CGDebugInfo::CreateType(co
>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::DIType *CGDebugInfo::CreateType(co
>}
>
>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 @@ llvm::DISubroutineType *CGDebugInfo::get
>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 @@ CGDebugInfo::getFunctionForwardDeclarati
>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 @@ llvm::DISubroutineType *CGDebugInfo::get
>
>if (const CXXMethodDecl *Method = dyn_cast(D))
>  return getOrCreateMethodType(Method, F);
> +
> +  const auto *FTy = FnType->getAs();
> +  CallingConv CC = FTy ? FTy->getCallConv() : CallingConv::CC_C;
> +
>if (const ObjCMethodDecl *OMethod = dyn_cast(D)) {
>  // Add "self" and "_cmd"
>  SmallVector Elts;
> @@ -2701,7 +2740,7 @@ llvm::DISubroutineType *CGDebugInfo::get
>Elts.push_back(DBuilder.createUnspecifiedParameter());
>
>  llvm::DITypeRefArray EltTypeArray =
> DBuilder.getOrCreateTypeArray(Elts);
> -  

r272198 - [DebugInfo] Add calling conventions to DISubroutineType

2016-06-08 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Wed Jun  8 15:41:54 2016
New Revision: 272198

URL: http://llvm.org/viewvc/llvm-project?rev=272198=rev
Log:
[DebugInfo] Add calling conventions to DISubroutineType

Summary:
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

Reviewers: aprantl, dblaikie

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D21141

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

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=272198=272197=272198=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Jun  8 15:41:54 2016
@@ -831,6 +831,39 @@ llvm::DIType *CGDebugInfo::CreateType(co
   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::DIType *CGDebugInfo::CreateType(co
   }
 
   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 @@ llvm::DISubroutineType *CGDebugInfo::get
   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 @@ CGDebugInfo::getFunctionForwardDeclarati
   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 @@ llvm::DISubroutineType *CGDebugInfo::get
 
   if (const CXXMethodDecl *Method = dyn_cast(D))
 return getOrCreateMethodType(Method, F);
+
+  const auto *FTy = FnType->getAs();
+  CallingConv CC = FTy ? FTy->getCallConv() : CallingConv::CC_C;
+
   if (const ObjCMethodDecl *OMethod = dyn_cast(D)) {
 // Add "self" and "_cmd"
 SmallVector Elts;
@@ -2701,7 +2740,7 @@ llvm::DISubroutineType *CGDebugInfo::get
   Elts.push_back(DBuilder.createUnspecifiedParameter());
 
 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
-return DBuilder.createSubroutineType(EltTypeArray);
+return DBuilder.createSubroutineType(EltTypeArray, 0, getDwarfCC(CC));
   }
 
   // Handle variadic function types; they need an additional
@@ -2715,7 +2754,7 @@ llvm::DISubroutineType *CGDebugInfo::get
   EltTys.push_back(getOrCreateType(FPT->getParamType(i), F));
   EltTys.push_back(DBuilder.createUnspecifiedParameter());
   llvm::DITypeRefArray EltTypeArray =