fdeazeve added a comment. The code in Mem2Reg (Local.cpp) is wrong in the presence of DIExprs, but by luck we conservatively don't do anything.
The function below is roughly doing: "if this store covers the entire size of the `DIVar`, rewrite the dbg declare into a dbg value. This is only correct if the `DIExpr` is empty. In most cases, "luckily" the size of a pointer doesn't match the size of the `DIVar`, but it should be possible to come up with IR examples where we generate invalid debug information in the presence of a `OP_deref`. /// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic. void llvm::ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII, StoreInst *SI, DIBuilder &Builder) { assert(DII->isAddressOfVariable() || isa<DbgAssignIntrinsic>(DII)); auto *DIVar = DII->getVariable(); assert(DIVar && "Missing variable"); auto *DIExpr = DII->getExpression(); DIExpr->startsWithDeref(); Value *DV = SI->getValueOperand(); DebugLoc NewLoc = getDebugValueLoc(DII); if (!valueCoversEntireFragment(DV->getType(), DII)) { // FIXME: If storing to a part of the variable described by the dbg.declare, // then we want to insert a dbg.value for the corresponding fragment. LLVM_DEBUG(dbgs() << "Failed to convert dbg.declare to dbg.value: " << *DII << '\n'); // For now, when there is a store to parts of the variable (but we do not // know which part) we insert an dbg.value intrinsic to indicate that we // know nothing about the variable's content. DV = UndefValue::get(DV->getType()); Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc, SI); return; } Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc, SI); } Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D141381/new/ https://reviews.llvm.org/D141381 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits