[flang-commits] [PATCH] D104290: [flang] Check there's no dependency on C++ libs

Diana Picus via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue Jun 15 04:06:28 PDT 2021


rovka created this revision.
rovka added reviewers: klausler, jeanPerier.
rovka added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a reviewer: sscalpone.
rovka requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104290

Files:
  flang/test/Runtime/no-cpp-dep.c
  flang/test/lit.cfg.py
  flang/test/lit.site.cfg.py.in


Index: flang/test/lit.site.cfg.py.in
===================================================================
--- flang/test/lit.site.cfg.py.in
+++ flang/test/lit.site.cfg.py.in
@@ -9,8 +9,10 @@
 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
Index: flang/test/lit.cfg.py
===================================================================
--- flang/test/lit.cfg.py
+++ flang/test/lit.cfg.py
@@ -75,6 +75,19 @@
    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:
+    config.available_features.add('c-compiler')
+    tools.append(ToolSubst('%cc', command=config.cc, unresolved='ignore'))
+    tools.append(ToolSubst('%libruntime',
+        command=os.path.join(config.flang_lib_dir, 'libFortranRuntime.a'),
+        unresolved='warn'))
+    tools.append(ToolSubst('%runtimeincludes',
+        command=os.path.join(config.flang_src_dir, 'runtime'),
+        unresolved='warn'))
+
 if config.flang_standalone_build:
     llvm_config.add_tool_substitutions(tools, [config.flang_llvm_tools_dir])
 else:
Index: flang/test/Runtime/no-cpp-dep.c
===================================================================
--- /dev/null
+++ flang/test/Runtime/no-cpp-dep.c
@@ -0,0 +1,19 @@
+// 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;
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104290.352092.patch
Type: text/x-patch
Size: 2431 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20210615/67a47b10/attachment-0001.bin>


More information about the flang-commits mailing list