From: Petr Hosek Date: Wed, 24 Jul 2019 00:16:23 +0000 (+0000) Subject: [SafeStack] Insert the deref before remaining elements X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c6b1a59e768952af4e62a873b5273b054e87025;p=llvm [SafeStack] Insert the deref before remaining elements This is a follow up to D64971. While we need to insert the deref after the offset, it needs to come before the remaining elements in the original expression since the deref needs to happen before the LLVM fragment if present. Differential Revision: https://reviews.llvm.org/D65172 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366865 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp index b6d555cd13e..8e501728599 100644 --- a/lib/Transforms/Utils/Local.cpp +++ b/lib/Transforms/Utils/Local.cpp @@ -1599,13 +1599,8 @@ static void replaceOneDbgValueForAlloca(DbgValueInst *DVI, Value *NewAddress, // Insert the offset before the first deref. // We could just change the offset argument of dbg.value, but it's unsigned... - if (Offset) { - SmallVector Ops; - DIExpression::appendOffset(Ops, Offset); - Ops.append(DIExpr->elements_begin() + 1, DIExpr->elements_end()); - Ops.push_back(dwarf::DW_OP_deref); - DIExpr = Builder.createExpression(Ops); - } + if (Offset) + DIExpr = DIExpression::prepend(DIExpr, 0, Offset); Builder.insertDbgValueIntrinsic(NewAddress, DIVar, DIExpr, Loc, DVI); DVI->eraseFromParent(); diff --git a/test/Transforms/SafeStack/X86/debug-loc2.ll b/test/Transforms/SafeStack/X86/debug-loc2.ll index 30623962691..79b6c10ed7d 100644 --- a/test/Transforms/SafeStack/X86/debug-loc2.ll +++ b/test/Transforms/SafeStack/X86/debug-loc2.ll @@ -24,6 +24,10 @@ entry: ; CHECK: call void @llvm.dbg.value(metadata ![[EMPTY]], metadata !{{.*}}, metadata !{{.*}}) tail call void @llvm.dbg.value(metadata i32* %x1, metadata !10, metadata !24), !dbg !16 +; Supported dbg.value: rewritted based on the [[USP]] value. +; CHECK: call void @llvm.dbg.value(metadata i8* %[[USP]], metadata ![[X1:.*]], metadata !DIExpression(DW_OP_constu, 4, DW_OP_minus, DW_OP_deref, DW_OP_LLVM_fragment, 0, 4)) + tail call void @llvm.dbg.value(metadata i32* %x1, metadata !10, metadata !25), !dbg !16 + ; Supported dbg.value: rewritted based on the [[USP]] value. ; CHECK: call void @llvm.dbg.value(metadata i8* %[[USP]], metadata ![[X1:.*]], metadata !DIExpression(DW_OP_constu, 4, DW_OP_minus, DW_OP_deref)) tail call void @llvm.dbg.value(metadata i32* %x1, metadata !10, metadata !15), !dbg !16 @@ -94,3 +98,4 @@ attributes #4 = { nounwind } !22 = !DILexicalBlockFile(scope: !6, file: !1, discriminator: 1) !23 = !DIExpression() !24 = !DIExpression(DW_OP_constu, 42, DW_OP_minus) +!25 = !DIExpression(DW_OP_deref, DW_OP_LLVM_fragment, 0, 4)