@@ -6986,22 +6986,17 @@ static void FixupDebugInfoForOutlinedFunction(
69866986 // snippet) as location of variable. The AMDGPU backend drops the debug
69876987 // info for variable in such cases. So we change the location to alloca
69886988 // instead.
6989+ if (DR->getNumVariableLocationOps () != 1u )
6990+ return ;
6991+ auto Loc = DR->getVariableLocationOp (0u );
69896992 bool PassByRef = false ;
6990- llvm::Type *locType = nullptr ;
6991- for (auto Loc : DR->location_ops ()) {
6992- locType = Loc->getType ();
6993- if (llvm::LoadInst *Load = dyn_cast<llvm::LoadInst>(Loc)) {
6994- DR->replaceVariableLocationOp (Loc, Load->getPointerOperand ());
6995- PassByRef = true ;
6996- }
6993+ if (llvm::LoadInst *Load = dyn_cast<llvm::LoadInst>(Loc)) {
6994+ Loc = Load->getPointerOperand ();
6995+ PassByRef = true ;
69976996 }
69986997 // Add DIOps based expression. Note that we generate an extra indirection
69996998 // if an argument is mapped by reference. The first reads the pointer
70006999 // from alloca and 2nd read the value of the variable from that pointer.
7001- llvm::DIExprBuilder ExprBuilder (Builder.getContext ());
7002- unsigned int allocaAS = M->getDataLayout ().getAllocaAddrSpace ();
7003- unsigned int defaultAS = M->getDataLayout ().getProgramAddressSpace ();
7004- ExprBuilder.append <llvm::DIOp::Arg>(0u , Builder.getPtrTy (allocaAS));
70057000 // We have 2 options for the variables that are mapped byRef.
70067001 // 1. Use a single indirection but change the type to the reference to the
70077002 // original type. It will show up in the debugger as
@@ -7010,10 +7005,15 @@ static void FixupDebugInfoForOutlinedFunction(
70107005 // 2. Use double indirection and keep the original type. It will show up
70117006 // in debugger as "x=5". This approached is used here as it is
70127007 // consistent with the normal fortran parameters display.
7013- if (PassByRef)
7014- ExprBuilder.append <llvm::DIOp::Deref>(Builder.getPtrTy (defaultAS));
7015- ExprBuilder.append <llvm::DIOp::Deref>(locType);
7016- DR->setExpression (ExprBuilder.intoExpression ());
7008+ if (auto AI = dyn_cast<llvm::AllocaInst>(Loc->stripPointerCasts ())) {
7009+ DR->replaceVariableLocationOp (0u , AI);
7010+ llvm::DIExprBuilder ExprBuilder (Builder.getContext ());
7011+ ExprBuilder.append <llvm::DIOp::Arg>(0u , AI->getType ());
7012+ if (PassByRef)
7013+ ExprBuilder.append <llvm::DIOp::Deref>(AI->getAllocatedType ());
7014+ ExprBuilder.append <llvm::DIOp::Deref>(AI->getAllocatedType ());
7015+ DR->setExpression (ExprBuilder.intoExpression ());
7016+ }
70177017 }
70187018
70197019 DR->setVariable (GetUpdatedDIVariable (OldVar, ArgNo));
0 commit comments