[COMMITTED] c++: Avoid ICE when constexpr __builtin_strchr fails.
diff mbox series

Message ID 20200123181103.9384-1-jason@redhat.com
State New
Headers show
Series
  • [COMMITTED] c++: Avoid ICE when constexpr __builtin_strchr fails.
Related show

Commit Message

Jason Merrill Jan. 23, 2020, 6:11 p.m. UTC
If we can't change the argument to &"...", use the original arg instead of
the partially munged one.

Tested x86_64-pc-linux-gnu, applying to trunk.

	PR c++/93331 - ICE with __builtin_strchr.
	* constexpr.c (cxx_eval_builtin_function_call): Use the original
	argument if we didn't manage to extract a STRING_CST.
---
 gcc/cp/constexpr.c                                             | 3 +++
 .../{gcc.c-torture/compile => c-c++-common}/pr34029-1.c        | 0
 2 files changed, 3 insertions(+)
 rename gcc/testsuite/{gcc.c-torture/compile => c-c++-common}/pr34029-1.c (100%)


base-commit: 6d00f052ef209bacdd93f503b0c5fb428cc6c434

Patch
diff mbox series

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 5864b67d4de..f6b8f331bc9 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1293,6 +1293,7 @@  cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, tree fun,
   for (i = 0; i < nargs; ++i)
     {
       tree arg = CALL_EXPR_ARG (t, i);
+      tree oarg = arg;
 
       /* To handle string built-ins we need to pass ADDR_EXPR<STRING_CST> since
 	 expand_builtin doesn't know how to look in the values table.  */
@@ -1327,6 +1328,8 @@  cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, tree fun,
 	    arg = braced_lists_to_strings (TREE_TYPE (arg), arg);
 	  if (TREE_CODE (arg) == STRING_CST)
 	    arg = build_address (arg);
+	  else
+	    arg = oarg;
 	}
 
       args[i] = arg;
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr34029-1.c b/gcc/testsuite/c-c++-common/pr34029-1.c
similarity index 100%
rename from gcc/testsuite/gcc.c-torture/compile/pr34029-1.c
rename to gcc/testsuite/c-c++-common/pr34029-1.c