Skip to content

Commit 06358bd

Browse files
committed
Configure: if we compile with clang, check that it is not broken
Some linux distibutions (for example, Mageia 2, Fedora 17) ship Clang that is essentially broken for the end user. Clang can not find or compile libstdc++ headers. The issue is that our configure prefers clang over gcc, thus selecting a broken Clang when a working GCC is available. Now we detect this issue by compiling a simple program. If it does not compile, configure stops with an error suggesting the user to select a different compiler. llvm-svn: 171975
1 parent 52b1515 commit 06358bd

File tree

2 files changed

+119
-2
lines changed

2 files changed

+119
-2
lines changed

llvm/autoconf/configure.ac

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,32 @@ AC_PROG_CC(clang llvm-gcc gcc)
6565
AC_PROG_CXX(clang++ llvm-g++ g++)
6666
AC_PROG_CPP
6767

68+
dnl If CXX is Clang, check that it can find and parse C++ standard library
69+
dnl headers.
70+
if test "$CXX" = "clang++" ; then
71+
AC_MSG_CHECKING([whether clang works])
72+
AC_LANG_PUSH([C++])
73+
dnl Note that space between 'include' and '(' is required. There's a broken
74+
dnl regex in aclocal that otherwise will think that we call m4's include
75+
dnl builtin.
76+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <limits>
77+
#if __has_include (<cxxabi.h>)
78+
#include <cxxabi.h>
79+
#endif
80+
#if __has_include (<unwind.h>)
81+
#include <unwind.h>
82+
#endif
83+
]])],
84+
[
85+
AC_MSG_RESULT([yes])
86+
],
87+
[
88+
AC_MSG_RESULT([no])
89+
AC_MSG_ERROR([Selected compiler could not find or parse C++ standard library headers. Rerun with CC=c-compiler CXX=c++-compiler ./configure ...])
90+
])
91+
AC_LANG_POP([C++])
92+
fi
93+
6894
dnl Configure all of the projects present in our source tree. While we could
6995
dnl just AC_CONFIG_SUBDIRS on the set of directories in projects that have a
7096
dnl configure script, that usage of the AC_CONFIG_SUBDIRS macro is deprecated.

llvm/configure

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3471,6 +3471,98 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
34713471
ac_compiler_gnu=$ac_cv_c_compiler_gnu
34723472

34733473

3474+
if test "$CXX" = "clang++" ; then
3475+
{ echo "$as_me:$LINENO: checking whether clang works" >&5
3476+
echo $ECHO_N "checking whether clang works... $ECHO_C" >&6; }
3477+
ac_ext=cpp
3478+
ac_cpp='$CXXCPP $CPPFLAGS'
3479+
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
3480+
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
3481+
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
3482+
3483+
3484+
cat >conftest.$ac_ext <<_ACEOF
3485+
/* confdefs.h. */
3486+
_ACEOF
3487+
cat confdefs.h >>conftest.$ac_ext
3488+
cat >>conftest.$ac_ext <<_ACEOF
3489+
/* end confdefs.h. */
3490+
#include <limits>
3491+
#if __has_include (<cxxabi.h>)
3492+
#include <cxxabi.h>
3493+
#endif
3494+
#if __has_include (<unwind.h>)
3495+
#include <unwind.h>
3496+
#endif
3497+
3498+
int
3499+
main ()
3500+
{
3501+
3502+
;
3503+
return 0;
3504+
}
3505+
_ACEOF
3506+
rm -f conftest.$ac_objext
3507+
if { (ac_try="$ac_compile"
3508+
case "(($ac_try" in
3509+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
3510+
*) ac_try_echo=$ac_try;;
3511+
esac
3512+
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
3513+
(eval "$ac_compile") 2>conftest.er1
3514+
ac_status=$?
3515+
grep -v '^ *+' conftest.er1 >conftest.err
3516+
rm -f conftest.er1
3517+
cat conftest.err >&5
3518+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
3519+
(exit $ac_status); } &&
3520+
{ ac_try='test -z "$ac_cxx_werror_flag" || test ! -s conftest.err'
3521+
{ (case "(($ac_try" in
3522+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
3523+
*) ac_try_echo=$ac_try;;
3524+
esac
3525+
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
3526+
(eval "$ac_try") 2>&5
3527+
ac_status=$?
3528+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
3529+
(exit $ac_status); }; } &&
3530+
{ ac_try='test -s conftest.$ac_objext'
3531+
{ (case "(($ac_try" in
3532+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
3533+
*) ac_try_echo=$ac_try;;
3534+
esac
3535+
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
3536+
(eval "$ac_try") 2>&5
3537+
ac_status=$?
3538+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
3539+
(exit $ac_status); }; }; then
3540+
3541+
{ echo "$as_me:$LINENO: result: yes" >&5
3542+
echo "${ECHO_T}yes" >&6; }
3543+
3544+
else
3545+
echo "$as_me: failed program was:" >&5
3546+
sed 's/^/| /' conftest.$ac_ext >&5
3547+
3548+
3549+
{ echo "$as_me:$LINENO: result: no" >&5
3550+
echo "${ECHO_T}no" >&6; }
3551+
{ { echo "$as_me:$LINENO: error: Selected compiler could not find or parse C++ standard library headers. Rerun with CC=c-compiler CXX=c++-compiler ./configure ..." >&5
3552+
echo "$as_me: error: Selected compiler could not find or parse C++ standard library headers. Rerun with CC=c-compiler CXX=c++-compiler ./configure ..." >&2;}
3553+
{ (exit 1); exit 1; }; }
3554+
3555+
fi
3556+
3557+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
3558+
ac_ext=c
3559+
ac_cpp='$CPP $CPPFLAGS'
3560+
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
3561+
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
3562+
ac_compiler_gnu=$ac_cv_c_compiler_gnu
3563+
3564+
fi
3565+
34743566

34753567

34763568
if test -d ${srcdir}/projects/llvm-gcc ; then
@@ -10393,7 +10485,7 @@ else
1039310485
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
1039410486
lt_status=$lt_dlunknown
1039510487
cat > conftest.$ac_ext <<EOF
10396-
#line 10396 "configure"
10488+
#line 10488 "configure"
1039710489
#include "confdefs.h"
1039810490

1039910491
#if HAVE_DLFCN_H
@@ -16330,7 +16422,6 @@ rm -f core conftest.err conftest.$ac_objext \
1633016422

1633116423

1633216424

16333-
1633416425
{ echo "$as_me:$LINENO: checking for HUGE_VAL sanity" >&5
1633516426
echo $ECHO_N "checking for HUGE_VAL sanity... $ECHO_C" >&6; }
1633616427
if test "${ac_cv_huge_val_sanity+set}" = set; then

0 commit comments

Comments
 (0)