[flang-commits] [flang] 41a1415 - [Flang][Driver][NFC] Improve -emit-obj unit tests

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Thu May 4 02:13:30 PDT 2023


Author: Sergio Afonso
Date: 2023-05-04T10:13:07+01:00
New Revision: 41a1415dc32f89f8de356a1874be673c82d716a7

URL: https://github.com/llvm/llvm-project/commit/41a1415dc32f89f8de356a1874be673c82d716a7
DIFF: https://github.com/llvm/llvm-project/commit/41a1415dc32f89f8de356a1874be673c82d716a7.diff

LOG: [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

Added: 
    

Modified: 
    flang/test/Driver/code-gen-aarch64.f90
    flang/test/Driver/code-gen-rv64.f90
    flang/test/Driver/code-gen-x86.f90

Removed: 
    


################################################################################
diff  --git a/flang/test/Driver/code-gen-aarch64.f90 b/flang/test/Driver/code-gen-aarch64.f90
index b6be486395316..e258b59c05f03 100644
--- a/flang/test/Driver/code-gen-aarch64.f90
+++ b/flang/test/Driver/code-gen-aarch64.f90
@@ -1,22 +1,9 @@
 ! Test -emit-obj (X86)
 
-! REQUIRES: aarch64-registered-target, x86-registered-target
+! REQUIRES: aarch64-registered-target
 
-! RUN: rm -f %t.o
-! RUN: %flang_fc1 -emit-obj -triple aarch64-unknown-linux-gnu %s -o %t.o
-! RUN: llvm-objdump --triple aarch64-unknown-linux-gnu --disassemble-all %t.o | FileCheck %s --check-prefix=CORRECT_TRIPLE
-! RUN: rm -f %t.o
-! RUN: %flang -c --target=aarch64-unknown-linux-gnu %s -o %t.o
-! RUN: llvm-objdump --triple aarch64-unknown-linux-gnu --disassemble-all %t.o | FileCheck %s --check-prefix=CORRECT_TRIPLE
-
-! RUN: %flang -c --target=aarch64-unknown-linux-gnu %s -o %t.o
-! RUN: llvm-objdump --triple x86_64-unknown-linux-gnu --disassemble-all %t.o | FileCheck %s --check-prefix=INCORRECT_TRIPLE
-
-! CORRECT_TRIPLE-LABEL: <_QQmain>:
-! CORRECT_TRIPLE-NEXT:  	ret
-
-! When incorrect triple is used to disassemble, there won't be a ret instruction at all.
-! INCORRECT_TRIPLE-LABEL: <_QQmain>:
-! INCORRECT_TRIPLE-NOT:  	ret
+! RUN: %flang_fc1 -triple aarch64-unknown-linux-gnu -emit-obj %s -o - | \
+! RUN: llvm-readobj -h - | FileCheck %s
 
+! CHECK: Arch: aarch64
 end program

diff  --git a/flang/test/Driver/code-gen-rv64.f90 b/flang/test/Driver/code-gen-rv64.f90
index c29ec9eff0aa2..f7bdb842559a4 100644
--- a/flang/test/Driver/code-gen-rv64.f90
+++ b/flang/test/Driver/code-gen-rv64.f90
@@ -2,16 +2,15 @@
 
 ! REQUIRES: riscv-registered-target
 
-! RUN: rm -f %t.o
 ! RUN: %flang_fc1 -triple riscv64-unknown-linux-gnu \
-! RUN:   -target-feature +d -target-feature +c -emit-obj %s -o %t.o
-! RUN: llvm-readobj -h %t.o | FileCheck %s
+! RUN:   -target-feature +d -target-feature +c -emit-obj %s -o - | \
+! RUN: llvm-readobj -h - | FileCheck %s
 
-! RUN: rm -f %t.o
-! RUN: %flang --target=riscv64-unknown-linux-gnu -c %s -o %t.o
-! RUN: llvm-readobj -h %t.o | FileCheck %s
+! RUN: %flang --target=riscv64-unknown-linux-gnu -c %s -o - | \
+! RUN: llvm-readobj -h - | FileCheck %s
 
 ! If Flang failed to emit target-feature info, then Flags will be 0x0.
+! CHECK: Arch: riscv64
 ! CHECK: Flags [ (0x5)
 ! CHECK-NEXT: EF_RISCV_FLOAT_ABI_DOUBLE (0x4)
 ! CHECK-NEXT: EF_RISCV_RVC (0x1)

diff  --git a/flang/test/Driver/code-gen-x86.f90 b/flang/test/Driver/code-gen-x86.f90
index b2bf95613efae..a6e5096f0de4b 100644
--- a/flang/test/Driver/code-gen-x86.f90
+++ b/flang/test/Driver/code-gen-x86.f90
@@ -1,22 +1,9 @@
 ! Test -emit-obj (X86)
 
-! REQUIRES: x86-registered-target, aarch64-registered-target
+! REQUIRES: x86-registered-target
 
-! RUN: rm -f %t.o
-! RUN: %flang_fc1 -triple x86_64-unknown-linux-gnu -emit-obj %s -o %t.o
-! RUN: llvm-objdump --triple x86_64-unknown-linux-gnu --disassemble-all %t.o | FileCheck %s --check-prefix=CORRECT_TRIPLE
-! RUN: rm -f %t.o
-! RUN: %flang --target=x86_64-unknown-linux-gnu -c %s -o %t.o
-! RUN: llvm-objdump --triple x86_64-unknown-linux-gnu --disassemble-all %t.o | FileCheck %s --check-prefix=CORRECT_TRIPLE
-
-! RUN: %flang -c --target=x86_64-unknown-linux-gnu %s -o %t.o
-! RUN: llvm-objdump --triple aarch64-unknown-linux-gnu --disassemble-all %t.o | FileCheck %s --check-prefix=INCORRECT_TRIPLE
-
-! CORRECT_TRIPLE-LABEL: <_QQmain>:
-! CORRECT_TRIPLE-NEXT:  	retq
-
-! When incorrect triple is used to disassemble, there won't be a ret(q) instruction at all.
-! INCORRECT_TRIPLE-LABEL: <_QQmain>:
-! INCORRECT_TRIPLE-NOT:  	ret
+! RUN: %flang_fc1 -triple x86_64-unknown-linux-gnu -emit-obj %s -o - | \
+! RUN: llvm-readobj -h - | FileCheck %s
 
+! CHECK: Arch: x86_64
 end program


        


More information about the flang-commits mailing list