[flang-commits] [flang] 0ad051b - [flang] Check there's no dependency on C++ libs. NFC
Diana Picus via flang-commits
flang-commits at lists.llvm.org
Wed Jun 16 04:39:45 PDT 2021
Author: Diana Picus
Date: 2021-06-16T11:38:25Z
New Revision: 0ad051b5fc22b4e7334635b2bdc54eca8ee7c4c4
URL: https://github.com/llvm/llvm-project/commit/0ad051b5fc22b4e7334635b2bdc54eca8ee7c4c4
DIFF: https://github.com/llvm/llvm-project/commit/0ad051b5fc22b4e7334635b2bdc54eca8ee7c4c4.diff
LOG: [flang] Check there's no dependency on C++ libs. NFC
Add a test to make sure the flang runtime doesn't pull in the C++
runtime libraries.
This is achieved by adding a C file that calls some functions from the
runtime (currently only CpuTime, but we should probably add anything
complicated enough, e.g. IO-related things). We force the C compiler to
use -std=c90 to make sure it's really in C mode (we don't really care
which version of the standard, this one is probably more widely
available). We only enable this test if CMAKE_C_COMPILER is set to
something (which is probably always true in practice).
This is a recommit of 7ddbf26, with 2 fixes:
* Replace C++ comments with C comments
* Only enable the test if libFortranRuntime.a exists (this might not be
the case if e.g. BUILD_SHARED_LIBS=On)
Differential Revision: https://reviews.llvm.org/D104290
Added:
flang/test/Runtime/no-cpp-dep.c
Modified:
flang/test/lit.cfg.py
flang/test/lit.site.cfg.py.in
Removed:
################################################################################
diff --git a/flang/test/Runtime/no-cpp-dep.c b/flang/test/Runtime/no-cpp-dep.c
new file mode 100644
index 000000000000..a35a52d91ac3
--- /dev/null
+++ b/flang/test/Runtime/no-cpp-dep.c
@@ -0,0 +1,23 @@
+/*
+This test makes sure that flang's runtime does not depend on the C++ runtime
+library. It tries to link this simple file against libFortranRuntime.a with
+a C compiler.
+
+REQUIRES: c-compiler
+
+RUN: %cc -std=c90 %s -I%runtimeincludes %libruntime -o /dev/null
+*/
+
+#include "entry-names.h"
+
+/*
+Manually add declarations for the runtime functions that we want to make sure
+we're testing. We can't include any headers directly since they likely contain
+C++ code that would explode here.
+*/
+double RTNAME(CpuTime)();
+
+int main() {
+ double x = RTNAME(CpuTime)();
+ return x;
+}
diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py
index 4109400087e5..374047e6c575 100644
--- a/flang/test/lit.cfg.py
+++ b/flang/test/lit.cfg.py
@@ -75,6 +75,21 @@
tools.append(ToolSubst('%flang_fc1', command=FindTool('f18'),
unresolved='fatal'))
+# Define some variables to help us test that the flang runtime doesn't depend on
+# the C++ runtime libraries. For this we need a C compiler. If for some reason
+# we don't have one, we can just disable the test.
+if config.cc:
+ libruntime = os.path.join(config.flang_lib_dir, 'libFortranRuntime.a')
+ includes = os.path.join(config.flang_src_dir, 'runtime')
+
+ if os.path.isfile(libruntime) and os.path.isdir(includes):
+ config.available_features.add('c-compiler')
+ tools.append(ToolSubst('%cc', command=config.cc, unresolved='fatal'))
+ tools.append(ToolSubst('%libruntime', command=libruntime,
+ unresolved='fatal'))
+ tools.append(ToolSubst('%runtimeincludes', command=includes,
+ unresolved='fatal'))
+
if config.flang_standalone_build:
llvm_config.add_tool_substitutions(tools, [config.flang_llvm_tools_dir])
else:
diff --git a/flang/test/lit.site.cfg.py.in b/flang/test/lit.site.cfg.py.in
index 17822b0b7d2e..bcafd8ac4302 100644
--- a/flang/test/lit.site.cfg.py.in
+++ b/flang/test/lit.site.cfg.py.in
@@ -9,8 +9,10 @@ config.flang_src_dir = "@FLANG_SOURCE_DIR@"
config.flang_tools_dir = "@FLANG_TOOLS_DIR@"
config.flang_intrinsic_modules_dir = "@FLANG_INTRINSIC_MODULES_DIR@"
config.flang_llvm_tools_dir = "@CMAKE_BINARY_DIR@/bin"
+config.flang_lib_dir = "@CMAKE_BINARY_DIR@/lib"
config.python_executable = "@PYTHON_EXECUTABLE@"
config.flang_standalone_build = @FLANG_STANDALONE_BUILD@
+config.cc = "@CMAKE_C_COMPILER@"
# Control the regression test for flang-new driver
import lit.util
More information about the flang-commits
mailing list