[flang-commits] [flang] [flang] Fix flang tests on MacOS (PR #70811)

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Fri Nov 10 05:47:13 PST 2023


https://github.com/luporl updated https://github.com/llvm/llvm-project/pull/70811

>From daf354d6653860a9bc17497b175b46f6b9481e6b Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Tue, 31 Oct 2023 11:20:54 -0300
Subject: [PATCH 1/6] [flang] Fix flang tests on MacOS

Skip unsupported flang tests on MacOS.

Issues #70805 and #70807 were opened for the failing tests that
remain, as these reveal real problems with flang.
---
 flang/test/Driver/lto-flags.f90           | 3 ++-
 flang/test/Driver/save-mlir-temps.f90     | 3 ++-
 flang/test/Evaluate/fold-out_of_range.f90 | 2 +-
 flang/test/Runtime/no-cpp-dep.c           | 3 +++
 4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/flang/test/Driver/lto-flags.f90 b/flang/test/Driver/lto-flags.f90
index da456b47ef4357e..b4819852fbc3616 100644
--- a/flang/test/Driver/lto-flags.f90
+++ b/flang/test/Driver/lto-flags.f90
@@ -10,7 +10,7 @@
 ! RUN: %flang -### -S -flto=jobserver %s 2>&1 | FileCheck %s --check-prefix=FULL-LTO
 
 ! Also check linker plugin opt for Thin LTO
-! RUN: %flang -### -flto=thin %s 2>&1 | FileCheck %s --check-prefix=THIN-LTO
+! RUN: %flang --target=x86_64-linux-gnu -### -flto=thin %s 2>&1 | FileCheck %s --check-prefix=THIN-LTO
 
 ! RUN: not %flang -### -S -flto=somelto %s 2>&1 | FileCheck %s --check-prefix=ERROR
 
@@ -28,6 +28,7 @@
 ! THIN-LTO: flang-new: warning: the option '-flto=thin' is a work in progress
 ! THIN-LTO: "-fc1"
 ! THIN-LTO-SAME: "-flto=thin"
+! NOTE: This check fails on MacOS.
 ! THIN-LTO: "-plugin-opt=thinlto"
 
 ! ERROR: error: unsupported argument 'somelto' to option '-flto=
diff --git a/flang/test/Driver/save-mlir-temps.f90 b/flang/test/Driver/save-mlir-temps.f90
index 8985271e27282e3..2eaadd051e58cc2 100644
--- a/flang/test/Driver/save-mlir-temps.f90
+++ b/flang/test/Driver/save-mlir-temps.f90
@@ -7,7 +7,8 @@
 ! As `flang` does not implement `-fc1as` (i.e. a driver for the integrated
 ! assembler), we need to use `-fno-integrated-as` here.
 
-! UNSUPPORTED: system-windows
+! This test fails on MacOS with the error "can't specifiy -Q with -arch arm64"
+! UNSUPPORTED: system-windows, system-darwin
 
 !--------------------------
 ! Invalid output directory
diff --git a/flang/test/Evaluate/fold-out_of_range.f90 b/flang/test/Evaluate/fold-out_of_range.f90
index fd1b1c286f2fb18..de66c803b103e19 100644
--- a/flang/test/Evaluate/fold-out_of_range.f90
+++ b/flang/test/Evaluate/fold-out_of_range.f90
@@ -1,5 +1,5 @@
 ! RUN: %python %S/test_folding.py %s %flang_fc1
-! UNSUPPORTED: target=powerpc{{.*}}, target=aarch{{.*}}, system-windows, system-solaris
+! UNSUPPORTED: target=powerpc{{.*}}, target=aarch{{.*}}, target=arm{{.*}}, system-windows, system-solaris
 ! Tests folding of OUT_OF_RANGE().
 module m
   integer(1),  parameter :: i1v(*)  = [ -huge(1_1)  - 1_1,  huge(1_1) ]
diff --git a/flang/test/Runtime/no-cpp-dep.c b/flang/test/Runtime/no-cpp-dep.c
index f8fe97b5bf78e24..7d1f05759623caa 100644
--- a/flang/test/Runtime/no-cpp-dep.c
+++ b/flang/test/Runtime/no-cpp-dep.c
@@ -5,6 +5,9 @@ a C compiler.
 
 REQUIRES: c-compiler
 
+MacOS doesn't have a separate libm.
+UNSUPPORTED: system-darwin
+
 RUN: %cc -std=c99 %s -I%include %libruntime %libdecimal -lm -o /dev/null
 */
 

>From fb787a1a1347a62babaec4f949d50daf749ad78a Mon Sep 17 00:00:00 2001
From: kkwli <kkwli at users.noreply.github.com>
Date: Mon, 6 Nov 2023 11:02:19 -0500
Subject: [PATCH 2/6] [flang] Match argument types for std::min (#71102)

PR #68342 causes build breakage on MacOS due to uint64_t being defined
as unsigned long long instead of unsigned long. It leads to type
mismatch in the arguments for std::min.
---
 flang/lib/Evaluate/fold-implementation.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/flang/lib/Evaluate/fold-implementation.h b/flang/lib/Evaluate/fold-implementation.h
index 868b7b6990fd384..a1bde778e5ec07e 100644
--- a/flang/lib/Evaluate/fold-implementation.h
+++ b/flang/lib/Evaluate/fold-implementation.h
@@ -910,7 +910,8 @@ template <typename T> Expr<T> Folder<T>::RESHAPE(FunctionRef<T> &&funcRef) {
                 : pad->Reshape(std::move(shape.value()))};
         ConstantSubscripts subscripts{result.lbounds()};
         auto copied{result.CopyFrom(*source,
-            std::min(source->size(), resultElements), subscripts, dimOrderPtr)};
+            std::min(static_cast<uint64_t>(source->size()), resultElements),
+            subscripts, dimOrderPtr)};
         if (copied < resultElements) {
           CHECK(pad);
           copied += result.CopyFrom(

>From 420c384b0c4a6cdeb9c559eaf77b340ea4cc9a6a Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Tue, 7 Nov 2023 17:30:02 -0300
Subject: [PATCH 3/6] [flang] Port no-cpp-dep test to MacOS

---
 flang/test/Runtime/no-cpp-dep.c | 3 ---
 flang/test/lit.cfg.py           | 5 ++++-
 flang/test/lit.site.cfg.py.in   | 1 +
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/flang/test/Runtime/no-cpp-dep.c b/flang/test/Runtime/no-cpp-dep.c
index 7d1f05759623caa..f8fe97b5bf78e24 100644
--- a/flang/test/Runtime/no-cpp-dep.c
+++ b/flang/test/Runtime/no-cpp-dep.c
@@ -5,9 +5,6 @@ a C compiler.
 
 REQUIRES: c-compiler
 
-MacOS doesn't have a separate libm.
-UNSUPPORTED: system-darwin
-
 RUN: %cc -std=c99 %s -I%include %libruntime %libdecimal -lm -o /dev/null
 */
 
diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py
index dda8ed456c986a5..ac504dc5d1fbdfa 100644
--- a/flang/test/lit.cfg.py
+++ b/flang/test/lit.cfg.py
@@ -163,7 +163,10 @@
         and os.path.isdir(include)
     ):
         config.available_features.add("c-compiler")
-        tools.append(ToolSubst("%cc", command=config.cc, unresolved="fatal"))
+        cc_cmd = config.cc
+        if config.osx_sysroot:
+            cc_cmd += " -isysroot " + config.osx_sysroot
+        tools.append(ToolSubst("%cc", command=cc_cmd, unresolved="fatal"))
         tools.append(ToolSubst("%libruntime", command=libruntime, unresolved="fatal"))
         tools.append(ToolSubst("%libdecimal", command=libdecimal, unresolved="fatal"))
         tools.append(ToolSubst("%include", command=include, unresolved="fatal"))
diff --git a/flang/test/lit.site.cfg.py.in b/flang/test/lit.site.cfg.py.in
index 46ba53ef672efa8..32099f43d3135f4 100644
--- a/flang/test/lit.site.cfg.py.in
+++ b/flang/test/lit.site.cfg.py.in
@@ -22,6 +22,7 @@ config.flang_standalone_build = @FLANG_STANDALONE_BUILD@
 config.has_plugins = @LLVM_ENABLE_PLUGINS@
 config.linked_bye_extension = @LLVM_BYE_LINK_INTO_TOOLS@
 config.cc = "@CMAKE_C_COMPILER@"
+config.osx_sysroot = path(r"@CMAKE_OSX_SYSROOT@")
 config.targets_to_build = "@TARGETS_TO_BUILD@"
 
 import lit.llvm

>From 347ef615426898fa7af2bf1dd12b9065d0b2b3c1 Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Tue, 7 Nov 2023 18:02:45 -0300
Subject: [PATCH 4/6] [flang] Address reviewer's comments

Also mark ctofortran.f90 as unsupported on Darwin.
---
 flang/test/Driver/ctofortran.f90      | 3 ++-
 flang/test/Driver/lto-flags.f90       | 6 +++---
 flang/test/Driver/save-mlir-temps.f90 | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/flang/test/Driver/ctofortran.f90 b/flang/test/Driver/ctofortran.f90
index 6483e0deb3866e3..828e87e89db69b0 100644
--- a/flang/test/Driver/ctofortran.f90
+++ b/flang/test/Driver/ctofortran.f90
@@ -1,4 +1,5 @@
-! UNSUPPORTED: system-windows
+! MacOS needs -isysroot <osx_sysroot> with clang and flang to build binaries.
+! UNSUPPORTED: system-windows, system-darwin
 ! RUN: split-file %s %t
 ! RUN: chmod +x %t/runtest.sh
 ! RUN: %t/runtest.sh %t %flang $t/ffile.f90 $t/cfile.c
diff --git a/flang/test/Driver/lto-flags.f90 b/flang/test/Driver/lto-flags.f90
index b4819852fbc3616..f6d054eac03cdae 100644
--- a/flang/test/Driver/lto-flags.f90
+++ b/flang/test/Driver/lto-flags.f90
@@ -10,7 +10,8 @@
 ! RUN: %flang -### -S -flto=jobserver %s 2>&1 | FileCheck %s --check-prefix=FULL-LTO
 
 ! Also check linker plugin opt for Thin LTO
-! RUN: %flang --target=x86_64-linux-gnu -### -flto=thin %s 2>&1 | FileCheck %s --check-prefix=THIN-LTO
+! RUN: %flang -### -flto=thin %s 2>&1 | FileCheck %s --check-prefix=%if \
+! RUN:        system-darwin %{THIN-LTO%} %else %{THIN-LTO,THIN-LTO-NOT-DARWIN%}
 
 ! RUN: not %flang -### -S -flto=somelto %s 2>&1 | FileCheck %s --check-prefix=ERROR
 
@@ -28,7 +29,6 @@
 ! THIN-LTO: flang-new: warning: the option '-flto=thin' is a work in progress
 ! THIN-LTO: "-fc1"
 ! THIN-LTO-SAME: "-flto=thin"
-! NOTE: This check fails on MacOS.
-! THIN-LTO: "-plugin-opt=thinlto"
+! THIN-LTO-NOT-DARWIN: "-plugin-opt=thinlto"
 
 ! ERROR: error: unsupported argument 'somelto' to option '-flto=
diff --git a/flang/test/Driver/save-mlir-temps.f90 b/flang/test/Driver/save-mlir-temps.f90
index 2eaadd051e58cc2..244cffed92acba6 100644
--- a/flang/test/Driver/save-mlir-temps.f90
+++ b/flang/test/Driver/save-mlir-temps.f90
@@ -7,7 +7,7 @@
 ! As `flang` does not implement `-fc1as` (i.e. a driver for the integrated
 ! assembler), we need to use `-fno-integrated-as` here.
 
-! This test fails on MacOS with the error "can't specifiy -Q with -arch arm64"
+! -fno-integrated-as isn't supported on arm64 Macs.
 ! UNSUPPORTED: system-windows, system-darwin
 
 !--------------------------

>From 8fcbb6afc553a40bc52c206467446460ac18919c Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Tue, 7 Nov 2023 18:34:36 -0300
Subject: [PATCH 5/6] Fix flang/test/Driver/lto-flags.f90 on Linux

---
 flang/test/Driver/lto-flags.f90 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/test/Driver/lto-flags.f90 b/flang/test/Driver/lto-flags.f90
index f6d054eac03cdae..a0b7816875eb4b1 100644
--- a/flang/test/Driver/lto-flags.f90
+++ b/flang/test/Driver/lto-flags.f90
@@ -10,7 +10,7 @@
 ! RUN: %flang -### -S -flto=jobserver %s 2>&1 | FileCheck %s --check-prefix=FULL-LTO
 
 ! Also check linker plugin opt for Thin LTO
-! RUN: %flang -### -flto=thin %s 2>&1 | FileCheck %s --check-prefix=%if \
+! RUN: %flang -### -flto=thin %s 2>&1 | FileCheck %s --check-prefixes=%if \
 ! RUN:        system-darwin %{THIN-LTO%} %else %{THIN-LTO,THIN-LTO-NOT-DARWIN%}
 
 ! RUN: not %flang -### -S -flto=somelto %s 2>&1 | FileCheck %s --check-prefix=ERROR

>From 2ea9dec79c077339567b59c5494da0f3a09bdf89 Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Fri, 10 Nov 2023 10:46:02 -0300
Subject: [PATCH 6/6] [flang] Address review's comments

---
 flang/test/Driver/lto-flags.f90       | 13 +++++++------
 flang/test/Driver/save-mlir-temps.f90 |  4 ++--
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/flang/test/Driver/lto-flags.f90 b/flang/test/Driver/lto-flags.f90
index a0b7816875eb4b1..2b3b08fbcc7119b 100644
--- a/flang/test/Driver/lto-flags.f90
+++ b/flang/test/Driver/lto-flags.f90
@@ -10,8 +10,9 @@
 ! RUN: %flang -### -S -flto=jobserver %s 2>&1 | FileCheck %s --check-prefix=FULL-LTO
 
 ! Also check linker plugin opt for Thin LTO
-! RUN: %flang -### -flto=thin %s 2>&1 | FileCheck %s --check-prefixes=%if \
-! RUN:        system-darwin %{THIN-LTO%} %else %{THIN-LTO,THIN-LTO-NOT-DARWIN%}
+! RUN: %flang -### -flto=thin %s 2>&1 | FileCheck %s \
+! RUN:        --check-prefixes=%if system-darwin %{THIN-LTO-ALL%} \
+! RUN:        %else %{THIN-LTO-ALL,THIN-LTO-LINKER-PLUGIN%}
 
 ! RUN: not %flang -### -S -flto=somelto %s 2>&1 | FileCheck %s --check-prefix=ERROR
 
@@ -26,9 +27,9 @@
 ! FULL-LTO: "-fc1"
 ! FULL-LTO-SAME: "-flto=full"
 
-! THIN-LTO: flang-new: warning: the option '-flto=thin' is a work in progress
-! THIN-LTO: "-fc1"
-! THIN-LTO-SAME: "-flto=thin"
-! THIN-LTO-NOT-DARWIN: "-plugin-opt=thinlto"
+! THIN-LTO-ALL: flang-new: warning: the option '-flto=thin' is a work in progress
+! THIN-LTO-ALL: "-fc1"
+! THIN-LTO-ALL-SAME: "-flto=thin"
+! THIN-LTO-LINKER-PLUGIN: "-plugin-opt=thinlto"
 
 ! ERROR: error: unsupported argument 'somelto' to option '-flto=
diff --git a/flang/test/Driver/save-mlir-temps.f90 b/flang/test/Driver/save-mlir-temps.f90
index 244cffed92acba6..50bc83030caa910 100644
--- a/flang/test/Driver/save-mlir-temps.f90
+++ b/flang/test/Driver/save-mlir-temps.f90
@@ -6,8 +6,8 @@
 
 ! As `flang` does not implement `-fc1as` (i.e. a driver for the integrated
 ! assembler), we need to use `-fno-integrated-as` here.
-
-! -fno-integrated-as isn't supported on arm64 Macs.
+! However, calling an external assembler on arm64 Macs fails, because it's
+! currently being invoked with the `-Q` flag, that is not supported on arm64.
 ! UNSUPPORTED: system-windows, system-darwin
 
 !--------------------------



More information about the flang-commits mailing list