<div dir="ltr">\o/ awesome! (I added that "indirect" hack ages ago, unfortunately - one consolation is that it was worse before: Clang would describe the parameter's type as "T&" in the DWARF, instead of as "T"... )</div><br><div class="gmail_quote"><div dir="ltr">On Mon, Apr 17, 2017 at 6:34 PM Adrian Prantl via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: adrian<br>
Date: Mon Apr 17 20:22:01 2017<br>
New Revision: 300523<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=300523&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=300523&view=rev</a><br>
Log:<br>
Debug Info: Remove special-casing of indirect function argument handling.<br>
<br>
LLVM has changed the semantics of dbg.declare for describing function<br>
arguments. After this patch a dbg.declare always takes the *address*<br>
of a variable as the first argument, even if the argument is not an<br>
alloca.<br>
<br>
<a href="https://bugs.llvm.org/show_bug.cgi?id=32382" rel="noreferrer" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=32382</a><br>
rdar://problem/31205000<br>
<br>
Modified:<br>
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
cfe/trunk/test/CodeGen/debug-info-vla.c<br>
cfe/trunk/test/CodeGenCXX/debug-info.cpp<br>
cfe/trunk/test/CodeGenOpenCL/<a href="http://amdgpu-debug-info-variable-expression.cl" rel="noreferrer" target="_blank">amdgpu-debug-info-variable-expression.cl</a><br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=300523&r1=300522&r2=300523&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=300523&r1=300522&r2=300523&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Apr 17 20:22:01 2017<br>
@@ -3466,17 +3466,17 @@ void CGDebugInfo::EmitDeclare(const VarD<br>
// functions there won't be an implicit param at arg1 and<br>
// otherwise it is 'self' or 'this'.<br>
if (isa<ImplicitParamDecl>(VD) && ArgNo && *ArgNo == 1)<br>
- Flags |= llvm::DINode::FlagObjectPointer;<br>
- if (auto *Arg = dyn_cast<llvm::Argument>(Storage))<br>
- if (Arg->getType()->isPointerTy() && !Arg->hasByValAttr() &&<br>
- !VD->getType()->isPointerType())<br>
- Expr.push_back(llvm::dwarf::DW_OP_deref);<br>
+ Flags |= llvm::DINode::FlagObjectPointer;<br>
<br>
+ // Note: Older versions of clang used to emit byval references with an extra<br>
+ // DW_OP_deref, because they referenced the IR arg directly instead of<br>
+ // referencing an alloca. Newer versions of LLVM don't treat allocas<br>
+ // differently from other function arguments when used in a dbg.declare.<br>
auto *Scope = cast<llvm::DIScope>(LexicalBlockStack.back());<br>
-<br>
StringRef Name = VD->getName();<br>
if (!Name.empty()) {<br>
if (VD->hasAttr<BlocksAttr>()) {<br>
+ // Here, we need an offset *into* the alloca.<br>
CharUnits offset = CharUnits::fromQuantity(32);<br>
Expr.push_back(llvm::dwarf::DW_OP_plus);<br>
// offset of __forwarding field<br>
@@ -3488,22 +3488,7 @@ void CGDebugInfo::EmitDeclare(const VarD<br>
// offset of x field<br>
offset = CGM.getContext().toCharUnitsFromBits(XOffset);<br>
Expr.push_back(offset.getQuantity());<br>
-<br>
- // Create the descriptor for the variable.<br>
- auto *D = ArgNo<br>
- ? DBuilder.createParameterVariable(Scope, VD->getName(),<br>
- *ArgNo, Unit, Line, Ty)<br>
- : DBuilder.createAutoVariable(Scope, VD->getName(), Unit,<br>
- Line, Ty, Align);<br>
-<br>
- // Insert an llvm.dbg.declare into the current block.<br>
- DBuilder.insertDeclare(<br>
- Storage, D, DBuilder.createExpression(Expr),<br>
- llvm::DebugLoc::get(Line, Column, Scope, CurInlinedAt),<br>
- Builder.GetInsertBlock());<br>
- return;<br>
- } else if (isa<VariableArrayType>(VD->getType()))<br>
- Expr.push_back(llvm::dwarf::DW_OP_deref);<br>
+ }<br>
} else if (const auto *RT = dyn_cast<RecordType>(VD->getType())) {<br>
// If VD is an anonymous union then Storage represents value for<br>
// all union fields.<br>
@@ -3606,8 +3591,7 @@ void CGDebugInfo::EmitDeclareOfBlockDecl<br>
->getElementOffset(blockInfo.getCapture(VD).getIndex()));<br>
<br>
SmallVector<int64_t, 9> addr;<br>
- if (isa<llvm::AllocaInst>(Storage))<br>
- addr.push_back(llvm::dwarf::DW_OP_deref);<br>
+ addr.push_back(llvm::dwarf::DW_OP_deref);<br>
addr.push_back(llvm::dwarf::DW_OP_plus);<br>
addr.push_back(offset.getQuantity());<br>
if (isByRef) {<br>
@@ -3633,12 +3617,11 @@ void CGDebugInfo::EmitDeclareOfBlockDecl<br>
// Insert an llvm.dbg.declare into the current block.<br>
auto DL =<br>
llvm::DebugLoc::get(Line, Column, LexicalBlockStack.back(), CurInlinedAt);<br>
+ auto *Expr = DBuilder.createExpression(addr);<br>
if (InsertPoint)<br>
- DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(addr), DL,<br>
- InsertPoint);<br>
+ DBuilder.insertDeclare(Storage, D, Expr, DL, InsertPoint);<br>
else<br>
- DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(addr), DL,<br>
- Builder.GetInsertBlock());<br>
+ DBuilder.insertDeclare(Storage, D, Expr, DL, Builder.GetInsertBlock());<br>
}<br>
<br>
void CGDebugInfo::EmitDeclareOfArgVariable(const VarDecl *VD, llvm::Value *AI,<br>
<br>
Modified: cfe/trunk/test/CodeGen/debug-info-vla.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-vla.c?rev=300523&r1=300522&r2=300523&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-vla.c?rev=300523&r1=300522&r2=300523&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGen/debug-info-vla.c (original)<br>
+++ cfe/trunk/test/CodeGen/debug-info-vla.c Mon Apr 17 20:22:01 2017<br>
@@ -4,8 +4,8 @@ void testVLAwithSize(int s)<br>
{<br>
// CHECK: dbg.declare<br>
// CHECK: dbg.declare({{.*}}, metadata ![[VAR:.*]], metadata ![[EXPR:.*]])<br>
-// CHECK: ![[VAR]] = !DILocalVariable(name: "vla",{{.*}} line: [[@LINE+2]]<br>
-// CHECK: ![[EXPR]] = !DIExpression(DW_OP_deref)<br>
+// CHECK: ![[EXPR]] = !DIExpression()<br>
+// CHECK: ![[VAR]] = !DILocalVariable(name: "vla",{{.*}} line: [[@LINE+1]]<br>
int vla[s];<br>
int i;<br>
for (i = 0; i < s; i++) {<br>
<br>
Modified: cfe/trunk/test/CodeGenCXX/debug-info.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info.cpp?rev=300523&r1=300522&r2=300523&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info.cpp?rev=300523&r1=300522&r2=300523&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/debug-info.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/debug-info.cpp Mon Apr 17 20:22:01 2017<br>
@@ -21,6 +21,7 @@<br>
<br>
// CHECK: ![[INCTYPE]] = !DICompositeType(tag: DW_TAG_structure_type, name: "incomplete"<br>
// CHECK-SAME: DIFlagFwdDecl<br>
+// CHECK: ![[EXPR]] = !DIExpression()<br>
<br>
template<typename T> struct Identity {<br>
typedef T Type;<br>
@@ -117,7 +118,6 @@ struct foo {<br>
// For some reason function arguments ended up down here<br>
// CHECK: ![[F]] = !DILocalVariable(name: "f", arg: 1, scope: ![[FUNC]]<br>
// CHECK-SAME: type: ![[FOO]]<br>
-// CHECK: ![[EXPR]] = !DIExpression(DW_OP_deref)<br>
foo func(foo f) {<br>
return f; // reference 'f' for now because otherwise we hit another bug<br>
}<br>
<br>
Modified: cfe/trunk/test/CodeGenOpenCL/<a href="http://amdgpu-debug-info-variable-expression.cl" rel="noreferrer" target="_blank">amdgpu-debug-info-variable-expression.cl</a><br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl?rev=300523&r1=300522&r2=300523&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl?rev=300523&r1=300522&r2=300523&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenOpenCL/<a href="http://amdgpu-debug-info-variable-expression.cl" rel="noreferrer" target="_blank">amdgpu-debug-info-variable-expression.cl</a> (original)<br>
+++ cfe/trunk/test/CodeGenOpenCL/<a href="http://amdgpu-debug-info-variable-expression.cl" rel="noreferrer" target="_blank">amdgpu-debug-info-variable-expression.cl</a> Mon Apr 17 20:22:01 2017<br>
@@ -1,6 +1,5 @@<br>
// RUN: %clang -cl-std=CL2.0 -emit-llvm -g -O0 -S -target amdgcn-amd-amdhsa -mcpu=fiji -o - %s | FileCheck %s<br>
<br>
-// CHECK-DAG: ![[NONE:[0-9]+]] = !DIExpression()<br>
// CHECK-DAG: ![[LOCAL:[0-9]+]] = !DIExpression(DW_OP_constu, 2, DW_OP_swap, DW_OP_xderef)<br>
// CHECK-DAG: ![[PRIVATE:[0-9]+]] = !DIExpression(DW_OP_constu, 1, DW_OP_swap, DW_OP_xderef)<br>
<br>
@@ -82,7 +81,7 @@ kernel void kernel1(<br>
int *FuncVar4 = Tmp1;<br>
<br>
// CHECK-DAG: ![[FUNCVAR5:[0-9]+]] = !DILocalVariable(name: "FuncVar5", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})<br>
- // CHECK-DAG: call void @llvm.dbg.declare(metadata i32 addrspace(1)** {{.*}}, metadata ![[FUNCVAR5]], metadata ![[NONE]]), !dbg !{{[0-9]+}}<br>
+ // CHECK-DAG: call void @llvm.dbg.declare(metadata i32 addrspace(1)** {{.*}}, metadata ![[FUNCVAR5]], metadata ![[NONE:[0-9]+]]), !dbg !{{[0-9]+}}<br>
global int *constant FuncVar5 = KernelArg0;<br>
// CHECK-DAG: ![[FUNCVAR6:[0-9]+]] = !DILocalVariable(name: "FuncVar6", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})<br>
// CHECK-DAG: call void @llvm.dbg.declare(metadata i32 addrspace(2)** {{.*}}, metadata ![[FUNCVAR6]], metadata ![[NONE]]), !dbg !{{[0-9]+}}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>