Skip to content

Commit faa0df3

Browse files
committed
[flang][driver] Make -stdlib= option visible to flang and silently ignored by it
This patch is to address a sudden problem I have encountered while trying to build mixed-language Fortran/C++ project. As I wanted the C++ part to utilize libc++ (instead of system-provided libstdc++), I've specified the `-stdlib=libc++` option globally, in the CXXFLAGS and LDFLAGS variables. This has saved me from making expensive changes in the Makefiles. Unfortunately, since it was the flang complier that was invoked for linking, suddenly it ended up with an error: ``` flang-new: error: unknown argument '-stdlib=libc++'; did you mean '-Xclang -stdlib=libc++'? ``` This has created a nowhere to go situation, the only remaining option is to make the -stdlib flag visible to flang and silently ignored.
1 parent 8b47711 commit faa0df3

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5812,7 +5812,7 @@ def std_EQ : Joined<["-", "--"], "std=">,
58125812
;
58135813
}]>;
58145814
def stdlib_EQ : Joined<["-", "--"], "stdlib=">,
5815-
Visibility<[ClangOption, CC1Option]>,
5815+
Visibility<[ClangOption, CC1Option, FlangOption]>,
58165816
HelpText<"C++ standard library to use">, Values<"libc++,libstdc++,platform">;
58175817
def stdlibxx_isystem : JoinedOrSeparate<["-"], "stdlib++-isystem">,
58185818
Group<clang_i_Group>,
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// REQUIRES: system-linux
2+
// RUN: split-file %s %t
3+
// RUN: chmod +x %t/mixed-runtest.sh
4+
// RUN: %t/mixed-runtest.sh -stdlib=platform %t %t/mixed-cppfile.cpp
5+
// %t/mixed-fortranfile.f90 %flang | FileCheck %s
6+
7+
//--- mixed-cppfile.cpp
8+
#include <iostream>
9+
10+
extern "C" void hello(void) { std::cout<<"Hello"<<std::endl; }
11+
12+
// clang-format off
13+
// CHECK: PASS
14+
//--- mixed-fortranfile.f90
15+
program mixed
16+
implicit none
17+
interface
18+
subroutine hello() bind(c)
19+
implicit none
20+
end subroutine
21+
end interface
22+
23+
call hello()
24+
end program
25+
26+
//--- mixed-runtest.sh
27+
#!/bin/bash
28+
LDFLAGS=$1
29+
TMPDIR=$2
30+
CPPFILE=$3
31+
F90FILE=$4
32+
FLANG=$5
33+
BINDIR=`dirname $FLANG`
34+
CPPCOMP=$BINDIR/clang++
35+
if [ -x $CPPCOMP ]
36+
then
37+
$CPPCOMP -shared $LDFLAGS $CPPFILE -o $TMPDIR/libmixed.so
38+
$FLANG $LDFLAGS -o $TMPDIR/mixed $F90FILE -L$TMPDIR -lmixed -Wl,-rpath=$TMPDIR
39+
if [ -x $TMPDIR/mixed ]
40+
then
41+
echo "PASS"
42+
else
43+
echo "FAIL"
44+
fi
45+
else
46+
# No clang compiler, just pass by default
47+
echo "PASS"
48+
fi

0 commit comments

Comments
 (0)