diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -1411,6 +1411,13 @@ static bool valueCoversEntireFragment(Type *ValTy, DbgVariableIntrinsic *DII) { const DataLayout &DL = DII->getModule()->getDataLayout(); TypeSize ValueSize = DL.getTypeAllocSizeInBits(ValTy); + + // If we are replacing a double indirection with a single-indirection, the + // fragment size could be (happens with reference params) that of the object + // but the pointer will only be 32/64 bits. + if (ValTy->isPointerTy()) + return true; + if (Optional FragmentSize = DII->getFragmentSizeInBits()) { assert(!ValueSize.isScalable() && "Fragments don't work on scalable types."); diff --git a/llvm/test/Transforms/Util/int128-ref-debuginfo.ll b/llvm/test/Transforms/Util/int128-ref-debuginfo.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/Util/int128-ref-debuginfo.ll @@ -0,0 +1,33 @@ +; RUN: opt -mem2reg -S < %s | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; CHECK-LABEL: @test +define void @test(i128* %ptr) { + %p = alloca i128*, align 8 + store i128* %ptr, i128** %p, align 8 +; CHECK: call void @llvm.dbg.value(metadata i128* %ptr, metadata !7, metadata !DIExpression()), !dbg !11 + call void @llvm.dbg.declare(metadata i128** %p, metadata !7, metadata !DIExpression()), !dbg !11 + ret void +} + +declare void @llvm.dbg.declare(metadata, metadata, metadata) #0 + +attributes #0 = { nofree nosync nounwind readnone speculatable willreturn } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "foo", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3) +!1 = !DIFile(filename: "test.cu", directory: "/foo/bar") +!2 = !{} +!3 = !{!4} +!4 = !DIDerivedType(tag: DW_TAG_typedef, name: "__int128_t", scope: !1, file: !1, baseType: !5) +!5 = !DIBasicType(name: "__int128", size: 128, encoding: DW_ATE_signed) +!6 = !{i32 1, !"Debug Info Version", i32 3} +!7 = !DILocalVariable(name: "ptr", arg: 1, scope: !8, file: !1, line: 2, type: !10) +!8 = distinct !DISubprogram(name: "test", linkageName: "test", scope: !1, file: !1, line: 5, type: !9, scopeLine: 5, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!9 = !DISubroutineType(types: !2) +!10 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !4) +!11 = !DILocation(line: 2, column: 3, scope: !8)