summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2016-01-21 11:51:47 -0800
committerH.J. Lu <hjl.tools@gmail.com>2016-01-22 10:49:32 -0800
commit8dcdab63ef8df5c9f2739383686bc7eedcb303e5 (patch)
tree93cd493e747cc68df8837868faa04024a040335b
parent64c6e7a35bf51c2794a8cfd9f6c0f5b92929c0f7 (diff)
downloadgcc-hjl/pr69399/gcc-5-branch.tar.gz
Add HAVE_WORKING_CXX_BUILTIN_CONSTANT_Phjl/pr69399/gcc-5-branch
Without the fix for PR 65656, g++ miscompiles __builtin_constant_p in wi::lrshift in wide-int.h. Add a check with PR 65656 testcase to verify that C++ __builtin_constant_p works properly. gcc/ PR c++/69399 * configure.ac: Check if C++ __builtin_constant_p works properly. (HAVE_WORKING_CXX_BUILTIN_CONSTANT_P): AC_DEFINE. * system.h (STATIC_CONSTANT_P): Use __builtin_constant_p only if HAVE_WORKING_CXX_BUILTIN_CONSTANT_P is defined. * config.in: Regenerated. * configure: Likewise. gcc/testsuite/ PR c++/69399 * gcc.dg/torture/pr69399.c: New test.
-rw-r--r--gcc/config.in7
-rwxr-xr-xgcc/configure45
-rw-r--r--gcc/configure.ac27
-rw-r--r--gcc/system.h2
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr69399.c21
5 files changed, 97 insertions, 5 deletions
diff --git a/gcc/config.in b/gcc/config.in
index 53352580b69..44db08990ce 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -1775,6 +1775,13 @@
#endif
+/* Define this macro if C++ __builtin_constant_p with constexpr does not crash
+ with a variable. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_WORKING_CXX_BUILTIN_CONSTANT_P
+#endif
+
+
/* Define to 1 if `fork' works. */
#ifndef USED_FOR_TARGET
#undef HAVE_WORKING_FORK
diff --git a/gcc/configure b/gcc/configure
index 3c9279593f1..cc4b02d3c00 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -6340,6 +6340,43 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
ac_compiler_gnu=$ac_cv_c_compiler_gnu
+# Check if C++ __builtin_constant_p works properly. Without the fix
+# for PR 65656, g++ miscompiles __builtin_constant_p in wi::lrshift in
+# wide-int.h. Add a check with PR 65656 testcase to verify that C++
+# __builtin_constant_p works properly.
+if test "$GCC" = yes; then
+ saved_CFLAGS="$CFLAGS"
+ saved_CXXFLAGS="$CXXFLAGS"
+ CFLAGS="$CFLAGS -O -x c++ -std=c++11"
+ CXXFLAGS="$CXXFLAGS -O -x c++ -std=c++11"
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX __builtin_constant_p works with constexpr" >&5
+$as_echo_n "checking whether $CXX __builtin_constant_p works with constexpr... " >&6; }
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+foo (int argc)
+{
+ constexpr bool x = __builtin_constant_p(argc);
+ return x ? 1 : 0;
+}
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+$as_echo "#define HAVE_WORKING_CXX_BUILTIN_CONSTANT_P 1" >>confdefs.h
+
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ CFLAGS="$saved_CFLAGS"
+ CXXFLAGS="$saved_CXXFLAGS"
+fi
+
@@ -16134,7 +16171,7 @@ _LT_EOF
if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
else
- export_symbols_cmds='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+ export_symbols_cmds='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "L")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
fi
aix_use_runtimelinking=no
@@ -18162,7 +18199,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 18165 "configure"
+#line 18202 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -18268,7 +18305,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 18271 "configure"
+#line 18308 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -20620,7 +20657,7 @@ $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie
if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
export_symbols_cmds_CXX='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
else
- export_symbols_cmds_CXX='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+ export_symbols_cmds_CXX='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "L")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
fi
;;
pw32*)
diff --git a/gcc/configure.ac b/gcc/configure.ac
index d41408143a1..b7b0bfeb98a 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -346,6 +346,33 @@ struct X<long long> { typedef long long t; };
fi
AC_LANG_POP(C++)
+# Check if C++ __builtin_constant_p works properly. Without the fix
+# for PR 65656, g++ miscompiles __builtin_constant_p in wi::lrshift in
+# wide-int.h. Add a check with PR 65656 testcase to verify that C++
+# __builtin_constant_p works properly.
+if test "$GCC" = yes; then
+ saved_CFLAGS="$CFLAGS"
+ saved_CXXFLAGS="$CXXFLAGS"
+ CFLAGS="$CFLAGS -O -x c++ -std=c++11"
+ CXXFLAGS="$CXXFLAGS -O -x c++ -std=c++11"
+ AC_MSG_CHECKING(whether $CXX __builtin_constant_p works with constexpr)
+ AC_COMPILE_IFELSE([
+int
+foo (int argc)
+{
+ constexpr bool x = __builtin_constant_p(argc);
+ return x ? 1 : 0;
+}
+],
+ [AC_MSG_RESULT([yes])
+ AC_DEFINE(HAVE_WORKING_CXX_BUILTIN_CONSTANT_P, 1,
+[Define this macro if C++ __builtin_constant_p with constexpr does not
+ crash with a variable.])],
+ [AC_MSG_RESULT([no])])
+ CFLAGS="$saved_CFLAGS"
+ CXXFLAGS="$saved_CXXFLAGS"
+fi
+
diff --git a/gcc/system.h b/gcc/system.h
index 94d8138c020..3c5863caad6 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -726,7 +726,7 @@ extern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN;
#define gcc_unreachable() (fancy_abort (__FILE__, __LINE__, __FUNCTION__))
#endif
-#if GCC_VERSION >= 3001
+#if GCC_VERSION >= 3001 && defined HAVE_WORKING_CXX_BUILTIN_CONSTANT_P
#define STATIC_CONSTANT_P(X) (__builtin_constant_p (X) && (X))
#else
#define STATIC_CONSTANT_P(X) (false && (X))
diff --git a/gcc/testsuite/gcc.dg/torture/pr69399.c b/gcc/testsuite/gcc.dg/torture/pr69399.c
new file mode 100644
index 00000000000..3e171695c52
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr69399.c
@@ -0,0 +1,21 @@
+/* { dg-do run { target int128 } } */
+
+typedef __UINT64_TYPE__ u64;
+typedef unsigned __int128 u128;
+
+static unsigned __attribute__((noinline, noclone))
+foo(u64 u)
+{
+ u128 v = u | 0xffffff81;
+ v >>= 64;
+ return v;
+}
+
+int
+main()
+{
+ unsigned x = foo(27);
+ if (x != 0)
+ __builtin_abort();
+ return 0;
+}