Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -647,8 +647,7 @@ int Offset = TFI->getFrameIndexReference(*Asm->MF, Fragment.FI, FrameReg); DwarfExpr.addFragmentOffset(Expr); SmallVector Ops; - Ops.push_back(dwarf::DW_OP_plus_uconst); - Ops.push_back(Offset); + DIExpression::appendOffset(Ops, Offset); // According to // https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-specific-dwarf // cuda-gdb requires DW_AT_address_class for all variables to be able to Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp @@ -280,19 +280,27 @@ // Pattern-match combinations for which more efficient representations exist. // [Reg, DW_OP_plus_uconst, Offset] --> [DW_OP_breg, Offset]. if (Op && (Op->getOp() == dwarf::DW_OP_plus_uconst)) { - SignedOffset = Op->getArg(0); - ExprCursor.take(); + uint64_t Offset = Op->getArg(0); + uint64_t IntMax = static_cast(std::numeric_limits::max()); + if (Offset <= IntMax) { + SignedOffset = Offset; + ExprCursor.take(); + } } // [Reg, DW_OP_constu, Offset, DW_OP_plus] --> [DW_OP_breg, Offset] // [Reg, DW_OP_constu, Offset, DW_OP_minus] --> [DW_OP_breg,-Offset] // If Reg is a subregister we need to mask it out before subtracting. if (Op && Op->getOp() == dwarf::DW_OP_constu) { + uint64_t Offset = Op->getArg(0); + uint64_t IntMax = static_cast(std::numeric_limits::max()); auto N = ExprCursor.peekNext(); - if (N && (N->getOp() == dwarf::DW_OP_plus || - (N->getOp() == dwarf::DW_OP_minus && !SubRegisterSizeInBits))) { - int Offset = Op->getArg(0); - SignedOffset = (N->getOp() == dwarf::DW_OP_minus) ? -Offset : Offset; + if (N && N->getOp() == dwarf::DW_OP_plus && Offset <= IntMax) { + SignedOffset = Offset; + ExprCursor.consume(2); + } else if (N && N->getOp() == dwarf::DW_OP_minus && + !SubRegisterSizeInBits && Offset <= IntMax + 1) { + SignedOffset = -static_cast(Offset); ExprCursor.consume(2); } } Index: llvm/trunk/test/DebugInfo/NVPTX/dbg-declare-alloca.ll =================================================================== --- llvm/trunk/test/DebugInfo/NVPTX/dbg-declare-alloca.ll +++ llvm/trunk/test/DebugInfo/NVPTX/dbg-declare-alloca.ll @@ -125,12 +125,12 @@ ; CHECK-NEXT: } ; CHECK-NEXT: .section .debug_info ; CHECK-NEXT: { -; CHECK-NEXT: .b32 136 // Length of Unit +; CHECK-NEXT: .b32 134 // Length of Unit ; CHECK-NEXT: .b8 2 // DWARF version number ; CHECK-NEXT: .b8 0 ; CHECK-NEXT: .b32 .debug_abbrev // Offset Into Abbrev. Section ; CHECK-NEXT: .b8 8 // Address Size (in bytes) -; CHECK-NEXT: .b8 1 // Abbrev [1] 0xb:0x81 DW_TAG_compile_unit +; CHECK-NEXT: .b8 1 // Abbrev [1] 0xb:0x7f DW_TAG_compile_unit ; CHECK-NEXT: .b8 99 // DW_AT_producer ; CHECK-NEXT: .b8 108 ; CHECK-NEXT: .b8 97 @@ -151,7 +151,7 @@ ; CHECK-NEXT: .b8 0 ; CHECK-NEXT: .b64 Lfunc_begin0 // DW_AT_low_pc ; CHECK-NEXT: .b64 Lfunc_end0 // DW_AT_high_pc -; CHECK-NEXT: .b8 2 // Abbrev [2] 0x31:0x3e DW_TAG_subprogram +; CHECK-NEXT: .b8 2 // Abbrev [2] 0x31:0x3c DW_TAG_subprogram ; CHECK-NEXT: .b64 Lfunc_begin0 // DW_AT_low_pc ; CHECK-NEXT: .b64 Lfunc_end0 // DW_AT_high_pc ; CHECK-NEXT: .b8 1 // DW_AT_frame_base @@ -176,20 +176,18 @@ ; CHECK-NEXT: .b8 3 // DW_AT_decl_line ; CHECK-NEXT: .b8 1 // DW_AT_prototyped ; CHECK-NEXT: .b8 1 // DW_AT_external -; CHECK-NEXT: .b8 3 // Abbrev [3] 0x58:0x16 DW_TAG_variable +; CHECK-NEXT: .b8 3 // Abbrev [3] 0x58:0x14 DW_TAG_variable ; CHECK-NEXT: .b8 6 // DW_AT_address_class -; CHECK-NEXT: .b8 11 // DW_AT_location +; CHECK-NEXT: .b8 9 // DW_AT_location ; CHECK-NEXT: .b8 3 ; CHECK-NEXT: .b64 __local_depot0 -; CHECK-NEXT: .b8 35 -; CHECK-NEXT: .b8 0 ; CHECK-NEXT: .b8 111 // DW_AT_name ; CHECK-NEXT: .b8 0 ; CHECK-NEXT: .b8 1 // DW_AT_decl_file ; CHECK-NEXT: .b8 4 // DW_AT_decl_line -; CHECK-NEXT: .b32 111 // DW_AT_type +; CHECK-NEXT: .b32 109 // DW_AT_type ; CHECK-NEXT: .b8 0 // End Of Children Mark -; CHECK-NEXT: .b8 4 // Abbrev [4] 0x6f:0x15 DW_TAG_structure_type +; CHECK-NEXT: .b8 4 // Abbrev [4] 0x6d:0x15 DW_TAG_structure_type ; CHECK-NEXT: .b8 70 // DW_AT_name ; CHECK-NEXT: .b8 111 ; CHECK-NEXT: .b8 111 @@ -197,17 +195,17 @@ ; CHECK-NEXT: .b8 4 // DW_AT_byte_size ; CHECK-NEXT: .b8 1 // DW_AT_decl_file ; CHECK-NEXT: .b8 1 // DW_AT_decl_line -; CHECK-NEXT: .b8 5 // Abbrev [5] 0x77:0xc DW_TAG_member +; CHECK-NEXT: .b8 5 // Abbrev [5] 0x75:0xc DW_TAG_member ; CHECK-NEXT: .b8 120 // DW_AT_name ; CHECK-NEXT: .b8 0 -; CHECK-NEXT: .b32 132 // DW_AT_type +; CHECK-NEXT: .b32 130 // DW_AT_type ; CHECK-NEXT: .b8 1 // DW_AT_decl_file ; CHECK-NEXT: .b8 1 // DW_AT_decl_line ; CHECK-NEXT: .b8 2 // DW_AT_data_member_location ; CHECK-NEXT: .b8 35 ; CHECK-NEXT: .b8 0 ; CHECK-NEXT: .b8 0 // End Of Children Mark -; CHECK-NEXT: .b8 6 // Abbrev [6] 0x84:0x7 DW_TAG_base_type +; CHECK-NEXT: .b8 6 // Abbrev [6] 0x82:0x7 DW_TAG_base_type ; CHECK-NEXT: .b8 105 // DW_AT_name ; CHECK-NEXT: .b8 110 ; CHECK-NEXT: .b8 116 Index: llvm/trunk/test/DebugInfo/X86/dw_op_constu.mir =================================================================== --- llvm/trunk/test/DebugInfo/X86/dw_op_constu.mir +++ llvm/trunk/test/DebugInfo/X86/dw_op_constu.mir @@ -147,14 +147,28 @@ # CHECK-LABEL: .Ldebug_loc0: # CHECK-NEXT: .quad .Ltmp0-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp1-.Lfunc_begin0 -# CHECK-NEXT: .short 2 # Loc expr size +# CHECK-NEXT: .short 9 # Loc expr size # CHECK-NEXT: .byte 114 # DW_OP_breg2 -# CHECK-NEXT: .byte 1 # 1 +# CHECK-NEXT: .byte 0 # 0 +# CHECK-NEXT: .byte 16 # DW_OP_constu +# CHECK-NEXT: .byte 255 # 4294967295 +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 15 # +# CHECK-NEXT: .byte 28 # DW_OP_minus # CHECK-NEXT: .quad .Ltmp1-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp2-.Lfunc_begin0 -# CHECK-NEXT: .short 2 # Loc expr size +# CHECK-NEXT: .short 9 # Loc expr size # CHECK-NEXT: .byte 114 # DW_OP_breg2 # CHECK-NEXT: .byte 0 # 0 +# CHECK-NEXT: .byte 16 # DW_OP_constu +# CHECK-NEXT: .byte 128 # 4294967296 +# CHECK-NEXT: .byte 128 # +# CHECK-NEXT: .byte 128 # +# CHECK-NEXT: .byte 128 # +# CHECK-NEXT: .byte 16 # +# CHECK-NEXT: .byte 28 # DW_OP_minus # CHECK-NEXT: .quad .Ltmp2-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp3-.Lfunc_begin0 # CHECK-NEXT: .short 6 # Loc expr size @@ -180,25 +194,54 @@ # CHECK-NEXT: .byte 0 # 0 # CHECK-NEXT: .quad .Ltmp5-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp6-.Lfunc_begin0 -# CHECK-NEXT: .short 2 # Loc expr size +# CHECK-NEXT: .short 5 # Loc expr size # CHECK-NEXT: .byte 114 # DW_OP_breg2 -# CHECK-NEXT: .byte 1 # 1 +# CHECK-NEXT: .byte 0 # 0 +# CHECK-NEXT: .byte 48 # DW_OP_lit0 +# CHECK-NEXT: .byte 32 # DW_OP_not +# CHECK-NEXT: .byte 28 # DW_OP_minus # CHECK-NEXT: .quad .Ltmp6-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp7-.Lfunc_begin0 -# CHECK-NEXT: .short 2 # Loc expr size +# CHECK-NEXT: .short 14 # Loc expr size # CHECK-NEXT: .byte 114 # DW_OP_breg2 -# CHECK-NEXT: .byte 2 # 2 +# CHECK-NEXT: .byte 0 # 0 +# CHECK-NEXT: .byte 16 # DW_OP_constu +# CHECK-NEXT: .byte 254 # 18446744073709551614 +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 1 # +# CHECK-NEXT: .byte 28 # DW_OP_minus #----------------------------------------------------------------------- # CHECK-NEXT: .quad .Ltmp8-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp9-.Lfunc_begin0 -# CHECK-NEXT: .short 2 # Loc expr size +# CHECK-NEXT: .short 9 # Loc expr size # CHECK-NEXT: .byte 114 # DW_OP_breg2 -# CHECK-NEXT: .byte 127 # -1 +# CHECK-NEXT: .byte 0 # 0 +# CHECK-NEXT: .byte 16 # DW_OP_constu +# CHECK-NEXT: .byte 255 # 4294967295 +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 15 # +# CHECK-NEXT: .byte 34 # DW_OP_plus # CHECK-NEXT: .quad .Ltmp9-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp10-.Lfunc_begin0 -# CHECK-NEXT: .short 2 # Loc expr size +# CHECK-NEXT: .short 9 # Loc expr size # CHECK-NEXT: .byte 114 # DW_OP_breg2 # CHECK-NEXT: .byte 0 # 0 +# CHECK-NEXT: .byte 16 # DW_OP_constu +# CHECK-NEXT: .byte 128 # 4294967296 +# CHECK-NEXT: .byte 128 # +# CHECK-NEXT: .byte 128 # +# CHECK-NEXT: .byte 128 # +# CHECK-NEXT: .byte 16 # +# CHECK-NEXT: .byte 34 # DW_OP_plus # CHECK-NEXT: .quad .Ltmp10-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp11-.Lfunc_begin0 # CHECK-NEXT: .short 6 # Loc expr size @@ -210,13 +253,16 @@ # CHECK-NEXT: .byte 7 # # CHECK-NEXT: .quad .Ltmp11-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp12-.Lfunc_begin0 -# CHECK-NEXT: .short 6 # Loc expr size +# CHECK-NEXT: .short 9 # Loc expr size # CHECK-NEXT: .byte 114 # DW_OP_breg2 -# CHECK-NEXT: .byte 128 # -2147483648 +# CHECK-NEXT: .byte 0 # 0 +# CHECK-NEXT: .byte 16 # DW_OP_constu +# CHECK-NEXT: .byte 128 # 2147483648 # CHECK-NEXT: .byte 128 # # CHECK-NEXT: .byte 128 # # CHECK-NEXT: .byte 128 # -# CHECK-NEXT: .byte 120 # +# CHECK-NEXT: .byte 8 # +# CHECK-NEXT: .byte 34 # DW_OP_plus # CHECK-NEXT: .quad .Ltmp12-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp13-.Lfunc_begin0 # CHECK-NEXT: .short 2 # Loc expr size @@ -224,25 +270,52 @@ # CHECK-NEXT: .byte 0 # 0 # CHECK-NEXT: .quad .Ltmp13-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp14-.Lfunc_begin0 -# CHECK-NEXT: .short 2 # Loc expr size +# CHECK-NEXT: .short 5 # Loc expr size # CHECK-NEXT: .byte 114 # DW_OP_breg2 -# CHECK-NEXT: .byte 127 # -1 +# CHECK-NEXT: .byte 0 # 0 +# CHECK-NEXT: .byte 48 # DW_OP_lit0 +# CHECK-NEXT: .byte 32 # DW_OP_not +# CHECK-NEXT: .byte 34 # DW_OP_plus # CHECK-NEXT: .quad .Ltmp14-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp15-.Lfunc_begin0 -# CHECK-NEXT: .short 2 # Loc expr size +# CHECK-NEXT: .short 14 # Loc expr size # CHECK-NEXT: .byte 114 # DW_OP_breg2 -# CHECK-NEXT: .byte 126 # -2 +# CHECK-NEXT: .byte 0 # 0 +# CHECK-NEXT: .byte 16 # DW_OP_constu +# CHECK-NEXT: .byte 254 # 18446744073709551614 +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 1 # +# CHECK-NEXT: .byte 34 # DW_OP_plus #----------------------------------------------------------------------- # CHECK-NEXT: .quad .Ltmp16-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp17-.Lfunc_begin0 -# CHECK-NEXT: .short 2 # Loc expr size +# CHECK-NEXT: .short 8 # Loc expr size # CHECK-NEXT: .byte 114 # DW_OP_breg2 -# CHECK-NEXT: .byte 127 # -1 +# CHECK-NEXT: .byte 0 # 0 +# CHECK-NEXT: .byte 35 # DW_OP_plus_uconst +# CHECK-NEXT: .byte 255 # 4294967295 +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 15 # # CHECK-NEXT: .quad .Ltmp17-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp18-.Lfunc_begin0 -# CHECK-NEXT: .short 2 # Loc expr size +# CHECK-NEXT: .short 8 # Loc expr size # CHECK-NEXT: .byte 114 # DW_OP_breg2 # CHECK-NEXT: .byte 0 # 0 +# CHECK-NEXT: .byte 35 # DW_OP_plus_uconst +# CHECK-NEXT: .byte 128 # 4294967296 +# CHECK-NEXT: .byte 128 # +# CHECK-NEXT: .byte 128 # +# CHECK-NEXT: .byte 128 # +# CHECK-NEXT: .byte 16 # # CHECK-NEXT: .quad .Ltmp18-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp19-.Lfunc_begin0 # CHECK-NEXT: .short 6 # Loc expr size @@ -254,13 +327,15 @@ # CHECK-NEXT: .byte 7 # # CHECK-NEXT: .quad .Ltmp19-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp20-.Lfunc_begin0 -# CHECK-NEXT: .short 6 # Loc expr size +# CHECK-NEXT: .short 8 # Loc expr size # CHECK-NEXT: .byte 114 # DW_OP_breg2 -# CHECK-NEXT: .byte 128 # -2147483648 +# CHECK-NEXT: .byte 0 # 0 +# CHECK-NEXT: .byte 35 # DW_OP_plus_uconst +# CHECK-NEXT: .byte 128 # 2147483648 # CHECK-NEXT: .byte 128 # # CHECK-NEXT: .byte 128 # # CHECK-NEXT: .byte 128 # -# CHECK-NEXT: .byte 120 # +# CHECK-NEXT: .byte 8 # # CHECK-NEXT: .quad .Ltmp20-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp21-.Lfunc_begin0 # CHECK-NEXT: .short 2 # Loc expr size @@ -268,13 +343,35 @@ # CHECK-NEXT: .byte 0 # 0 # CHECK-NEXT: .quad .Ltmp21-.Lfunc_begin0 # CHECK-NEXT: .quad .Ltmp22-.Lfunc_begin0 -# CHECK-NEXT: .short 2 # Loc expr size +# CHECK-NEXT: .short 13 # Loc expr size # CHECK-NEXT: .byte 114 # DW_OP_breg2 -# CHECK-NEXT: .byte 127 # -1 +# CHECK-NEXT: .byte 0 # 0 +# CHECK-NEXT: .byte 35 # DW_OP_plus_uconst +# CHECK-NEXT: .byte 255 # 18446744073709551615 +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 1 # # CHECK-NEXT: .quad .Ltmp22-.Lfunc_begin0 # CHECK-NEXT: .quad .Lfunc_end0-.Lfunc_begin0 -# CHECK-NEXT: .short 2 # Loc expr size +# CHECK-NEXT: .short 13 # Loc expr size # CHECK-NEXT: .byte 114 # DW_OP_breg2 -# CHECK-NEXT: .byte 126 # -2 +# CHECK-NEXT: .byte 0 # 0 +# CHECK-NEXT: .byte 35 # DW_OP_plus_uconst +# CHECK-NEXT: .byte 254 # 18446744073709551614 +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 255 # +# CHECK-NEXT: .byte 1 # # CHECK-NEXT: .quad 0 # CHECK-NEXT: .quad 0