Skip to content

Commit 41a1415

Browse files
committed
[Flang][Driver][NFC] Improve -emit-obj unit tests
Instead of looking for the existence of a `ret` instruction after disassembly as a way to check that the right ISA is present in the produced binary, check instead the ELF header of the file. This is a more reliable solution, since the alternative can easily result in false positives. Differential Revision: https://reviews.llvm.org/D149578
1 parent f248fc3 commit 41a1415

File tree

3 files changed

+13
-40
lines changed

3 files changed

+13
-40
lines changed
Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
! Test -emit-obj (X86)
22

3-
! REQUIRES: aarch64-registered-target, x86-registered-target
3+
! REQUIRES: aarch64-registered-target
44

5-
! RUN: rm -f %t.o
6-
! RUN: %flang_fc1 -emit-obj -triple aarch64-unknown-linux-gnu %s -o %t.o
7-
! RUN: llvm-objdump --triple aarch64-unknown-linux-gnu --disassemble-all %t.o | FileCheck %s --check-prefix=CORRECT_TRIPLE
8-
! RUN: rm -f %t.o
9-
! RUN: %flang -c --target=aarch64-unknown-linux-gnu %s -o %t.o
10-
! RUN: llvm-objdump --triple aarch64-unknown-linux-gnu --disassemble-all %t.o | FileCheck %s --check-prefix=CORRECT_TRIPLE
11-
12-
! RUN: %flang -c --target=aarch64-unknown-linux-gnu %s -o %t.o
13-
! RUN: llvm-objdump --triple x86_64-unknown-linux-gnu --disassemble-all %t.o | FileCheck %s --check-prefix=INCORRECT_TRIPLE
14-
15-
! CORRECT_TRIPLE-LABEL: <_QQmain>:
16-
! CORRECT_TRIPLE-NEXT: ret
17-
18-
! When incorrect triple is used to disassemble, there won't be a ret instruction at all.
19-
! INCORRECT_TRIPLE-LABEL: <_QQmain>:
20-
! INCORRECT_TRIPLE-NOT: ret
5+
! RUN: %flang_fc1 -triple aarch64-unknown-linux-gnu -emit-obj %s -o - | \
6+
! RUN: llvm-readobj -h - | FileCheck %s
217

8+
! CHECK: Arch: aarch64
229
end program

flang/test/Driver/code-gen-rv64.f90

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
! REQUIRES: riscv-registered-target
44

5-
! RUN: rm -f %t.o
65
! RUN: %flang_fc1 -triple riscv64-unknown-linux-gnu \
7-
! RUN: -target-feature +d -target-feature +c -emit-obj %s -o %t.o
8-
! RUN: llvm-readobj -h %t.o | FileCheck %s
6+
! RUN: -target-feature +d -target-feature +c -emit-obj %s -o - | \
7+
! RUN: llvm-readobj -h - | FileCheck %s
98

10-
! RUN: rm -f %t.o
11-
! RUN: %flang --target=riscv64-unknown-linux-gnu -c %s -o %t.o
12-
! RUN: llvm-readobj -h %t.o | FileCheck %s
9+
! RUN: %flang --target=riscv64-unknown-linux-gnu -c %s -o - | \
10+
! RUN: llvm-readobj -h - | FileCheck %s
1311

1412
! If Flang failed to emit target-feature info, then Flags will be 0x0.
13+
! CHECK: Arch: riscv64
1514
! CHECK: Flags [ (0x5)
1615
! CHECK-NEXT: EF_RISCV_FLOAT_ABI_DOUBLE (0x4)
1716
! CHECK-NEXT: EF_RISCV_RVC (0x1)

flang/test/Driver/code-gen-x86.f90

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
! Test -emit-obj (X86)
22

3-
! REQUIRES: x86-registered-target, aarch64-registered-target
3+
! REQUIRES: x86-registered-target
44

5-
! RUN: rm -f %t.o
6-
! RUN: %flang_fc1 -triple x86_64-unknown-linux-gnu -emit-obj %s -o %t.o
7-
! RUN: llvm-objdump --triple x86_64-unknown-linux-gnu --disassemble-all %t.o | FileCheck %s --check-prefix=CORRECT_TRIPLE
8-
! RUN: rm -f %t.o
9-
! RUN: %flang --target=x86_64-unknown-linux-gnu -c %s -o %t.o
10-
! RUN: llvm-objdump --triple x86_64-unknown-linux-gnu --disassemble-all %t.o | FileCheck %s --check-prefix=CORRECT_TRIPLE
11-
12-
! RUN: %flang -c --target=x86_64-unknown-linux-gnu %s -o %t.o
13-
! RUN: llvm-objdump --triple aarch64-unknown-linux-gnu --disassemble-all %t.o | FileCheck %s --check-prefix=INCORRECT_TRIPLE
14-
15-
! CORRECT_TRIPLE-LABEL: <_QQmain>:
16-
! CORRECT_TRIPLE-NEXT: retq
17-
18-
! When incorrect triple is used to disassemble, there won't be a ret(q) instruction at all.
19-
! INCORRECT_TRIPLE-LABEL: <_QQmain>:
20-
! INCORRECT_TRIPLE-NOT: ret
5+
! RUN: %flang_fc1 -triple x86_64-unknown-linux-gnu -emit-obj %s -o - | \
6+
! RUN: llvm-readobj -h - | FileCheck %s
217

8+
! CHECK: Arch: x86_64
229
end program

0 commit comments

Comments
 (0)