Skip to content

Commit e3dc222

Browse files
committed
Merging r353865, r353866, and r353874:
------------------------------------------------------------------------ r353865 | sfertile | 2019-02-12 09:48:22 -0800 (Tue, 12 Feb 2019) | 1 line [PowerPC] Fix printing of negative offsets in call instruction dissasembly. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r353866 | sfertile | 2019-02-12 09:49:04 -0800 (Tue, 12 Feb 2019) | 4 lines [PPC64] Update tests to reflect change in printing of call operand. [NFC] The printing of branch operands for call instructions was changed to properly handle negative offsets. Updating the tests to reflect that. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r353874 | sfertile | 2019-02-12 12:03:04 -0800 (Tue, 12 Feb 2019) | 5 lines Fix undefined behaviour in PPCInstPrinter::printBranchOperand. Fix the undefined behaviour introduced by my previous patch r353865 (left shifting a potentially negative value), which was caught by the bots that run UBSan. ------------------------------------------------------------------------ llvm-svn: 362043
1 parent f0bd598 commit e3dc222

File tree

13 files changed

+73
-16
lines changed

13 files changed

+73
-16
lines changed

lld/test/ELF/ppc64-bsymbolic-toc-restore.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ caller:
5353
# CHECK-LABEL: caller
5454
# CHECK: bl .+44
5555
# CHECK-NEXT: mr 31, 3
56-
# CHECK-NEXT: bl .+67108816
56+
# CHECK-NEXT: bl .-48
5757
# CHECK-NEXT: ld 2, 24(1)
5858
# CHECK-NEXT: add 3, 3, 31
5959
# CHECK-NEXT: addi 1, 1, 32

lld/test/ELF/ppc64-call-reach.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ test:
6262
# CHECK: 10010024: {{.*}} b .+33554428
6363

6464
# NEGOFFSET-LABEL: test
65-
# NEGOFFSET: 10010014: {{.*}} bl .+33554432
65+
# NEGOFFSET: 10010014: {{.*}} bl .-33554432
6666
# NEGOFFSET: 10010024: {{.*}} b .+33554432
6767

6868
# .branch_lt[0]
@@ -83,7 +83,7 @@ test:
8383
# the offset is interpreted as a signed 26 bit value so 67108812 is actually
8484
# -52.
8585
# THUNK-LABEL: test:
86-
# THUNK: 10010034: {{.*}} bl .+67108812
86+
# THUNK: 10010034: {{.*}} bl .-52
8787
# THUNK: 10010044: {{.*}} b .+67108812
8888

8989
# The offset from the TOC to the .branch_lt section is (-1 << 16) - 32768.

lld/test/ELF/ppc64-ifunc.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
# CHECK: _start:
4343
# CHECK-NEXT: addis 2, 12, 2
4444
# CHECK-NEXT: addi 2, 2, -32588
45-
# CHECK-NEXT: bl .+67108812
45+
# CHECK-NEXT: bl .-52
4646
# CHECK-NEXT: ld 2, 24(1)
47-
# CHECK-NEXT: bl .+67108824
47+
# CHECK-NEXT: bl .-40
4848
# CHECK-NEXT: ld 2, 24(1)
4949

5050
# Check tocbase

lld/test/ELF/ppc64-local-dynamic.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ k:
113113
// Dis: test:
114114
// Dis: addis 3, 2, 0
115115
// Dis-NEXT: addi 3, 3, -32760
116-
// Dis-NEXT: bl .+67108804
116+
// Dis-NEXT: bl .-60
117117
// Dis-NEXT: ld 2, 24(1)
118118
// Dis-NEXT: addis 3, 3, 0
119119
// Dis-NEXT: lwa 3, -32768(3)

lld/test/ELF/ppc64-plt-stub.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
// CHECK: _start:
25-
// CHECK: bl .+67108824
25+
// CHECK: bl .-40
2626
.text
2727
.abiversion 2
2828
.globl _start

lld/test/ELF/ppc64-rel-calls.s

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ bar:
3030
nop
3131
blr
3232

33-
# FIXME: The printing here is misleading, the branch offset here is negative.
34-
# CHECK: 1001000c: {{.*}} bl .+67108852
33+
# CHECK: 1001000c: {{.*}} bl .-12
3534
# CHECK: 10010010: {{.*}} nop
36-
# CHECK: 10010014: {{.*}} bl .+67108844
35+
# CHECK: 10010014: {{.*}} bl .-20
3736
# CHECK: 10010018: {{.*}} nop
3837
# CHECK: 1001001c: {{.*}} blr

lld/test/ELF/ppc64-toc-restore-recursive-call.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# CHECK-NEXT: 10000:
1919
# CHECK-LABEL: recursive_func
2020
# CHECK-NEXT: 10014:
21-
# CHECK: 1003c: {{[0-9a-fA-F ]+}} bl .+67108804
21+
# CHECK: 1003c: {{.*}} bl .-60
2222
# CHECK-NEXT: ld 2, 24(1)
2323

2424
.abiversion 2

lld/test/ELF/ppc64-toc-restore.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ _start:
3232

3333
// CHECK: Disassembly of section .text:
3434
// CHECK: _start:
35-
// CHECK: 1001001c: {{.*}} bl .+67108836
35+
// CHECK: 1001001c: {{.*}} bl .-28
3636
// CHECK-NOT: 10010020: {{.*}} nop
3737
// CHECK: 10010020: {{.*}} ld 2, 24(1)
38-
// CHECK: 10010024: {{.*}} bl .+67108848
38+
// CHECK: 10010024: {{.*}} bl .-16
3939
// CHECK-NOT: 10010028: {{.*}} nop
4040
// CHECK-NOT: 10010028: {{.*}} ld 2, 24(1)
4141

@@ -68,5 +68,5 @@ last:
6868
bl foo
6969
nop
7070
// CHECK: last:
71-
// CHECK: 10010038: {{.*}} bl .+67108808
71+
// CHECK: 10010038: {{.*}} bl .-56
7272
// CHECK-NEXT: 1001003c: {{.*}} ld 2, 24(1)

llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ extern "C" void LLVMInitializePowerPCDisassembler() {
6161
createPPCLEDisassembler);
6262
}
6363

64+
static DecodeStatus DecodePCRel24BranchTarget(MCInst &Inst, unsigned Imm,
65+
uint64_t Addr,
66+
const void *Decoder) {
67+
int32_t Offset = SignExtend32<24>(Imm);
68+
Inst.addOperand(MCOperand::createImm(Offset));
69+
return MCDisassembler::Success;
70+
}
71+
6472
// FIXME: These can be generated by TableGen from the existing register
6573
// encoding values!
6674

llvm/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,11 @@ void PPCInstPrinter::printBranchOperand(const MCInst *MI, unsigned OpNo,
382382

383383
// Branches can take an immediate operand. This is used by the branch
384384
// selection pass to print .+8, an eight byte displacement from the PC.
385-
O << ".+";
386-
printAbsBranchOperand(MI, OpNo, O);
385+
O << ".";
386+
int32_t Imm = SignExtend32<32>((unsigned)MI->getOperand(OpNo).getImm() << 2);
387+
if (Imm >= 0)
388+
O << "+";
389+
O << Imm;
387390
}
388391

389392
void PPCInstPrinter::printAbsBranchOperand(const MCInst *MI, unsigned OpNo,

0 commit comments

Comments
 (0)