Skip to content

Commit adf51a2

Browse files
committed
Address feedback, and fix deref to match allocated type
Not only was the type used in the expression potentially different than the location op used, but we were treating all variables as being "ptr" type, rather than the actual allocated type.
1 parent a396d4f commit adf51a2

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

flang/test/Integration/amdgpu/debug-declare-target-function-var.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function add(a, b) result(ret)
1515
!CHECK: define float @add_({{.*}}){{.*}}!dbg ![[SP:[0-9]+]] {
1616
!CHECK: #dbg_declare({{.*}}, ![[A:[0-9]+]], !DIExpression(DIOpArg(0, ptr addrspace(5)), DIOpDeref(ptr), DIOpDeref(ptr)), !{{.*}})
1717
!CHECK: #dbg_declare({{.*}}, ![[B:[0-9]+]], !DIExpression(DIOpArg(0, ptr addrspace(5)), DIOpDeref(ptr), DIOpDeref(ptr)), !{{.*}})
18-
!CHECK: #dbg_declare({{.*}}, ![[RET:[0-9]+]], !DIExpression(DIOpArg(0, ptr addrspace(5)), DIOpDeref(ptr)), !{{.*}})
18+
!CHECK: #dbg_declare({{.*}}, ![[RET:[0-9]+]], !DIExpression(DIOpArg(0, ptr addrspace(5)), DIOpDeref(float)), !{{.*}})
1919
!CHECK: }
2020
!CHECK: ![[SP]] = {{.*}}!DISubprogram(name: "add"{{.*}})
2121
!CHECK: ![[A]] = !DILocalVariable(name: "a", arg: 1, scope: ![[SP]]{{.*}})

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5792,14 +5792,13 @@ static void updateDebugInfoForDeclareTargetFunctions(
57925792
if (DR->getNumVariableLocationOps() != 1u)
57935793
return;
57945794
auto Loc = DR->getVariableLocationOp(0u);
5795-
llvm::Type *Ty = Loc->getType();
5796-
if (auto *Ref = dyn_cast<llvm::AddrSpaceCastInst>(Loc)) {
5797-
DR->replaceVariableLocationOp(0u, Loc->stripPointerCasts());
5798-
Ty = Ref->getPointerOperand()->getType();
5799-
}
5795+
if (!isa<llvm::AllocaInst>(Loc->stripPointerCasts()))
5796+
return;
5797+
llvm::AllocaInst *AI = cast<llvm::AllocaInst>(Loc->stripPointerCasts());
5798+
DR->replaceVariableLocationOp(0u, AI);
58005799
llvm::DIExprBuilder EB(Fn->getContext());
5801-
EB.append<llvm::DIOp::Arg>(0u, Ty);
5802-
EB.append<llvm::DIOp::Deref>(Loc->getType());
5800+
EB.append<llvm::DIOp::Arg>(0u, AI->getType());
5801+
EB.append<llvm::DIOp::Deref>(AI->getAllocatedType());
58035802
DR->setExpression(EB.intoExpression());
58045803
};
58055804

0 commit comments

Comments
 (0)