C++ PATCH for c++/86240, ICE with ABSU_EXPR

Marek Polacek polacek@redhat.com
Wed Jun 20 15:34:00 GMT 2018


The recent change introducing ABSU_EXPR neglected to also handle this code
in cxx_eval_constant_expression so this patch puts it there.  Also two
other spots for good measure.  It's possible we'll find out that we need
to fix other spots too.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-06-20  Marek Polacek  <polacek@redhat.com>

	PR c++/86240
	* constexpr.c (cxx_eval_constant_expression): Handle ABSU_EXPR.
	(fold_simple_1): Likewise.
	* error.c (dump_expr): Likewise.

	* g++.dg/pr86240.C: New test.

diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c
index 216eecd4b06..44f3093ab47 100644
--- gcc/cp/constexpr.c
+++ gcc/cp/constexpr.c
@@ -4412,6 +4412,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
     case FLOAT_EXPR:
     case NEGATE_EXPR:
     case ABS_EXPR:
+    case ABSU_EXPR:
     case BIT_NOT_EXPR:
     case TRUTH_NOT_EXPR:
     case FIXED_CONVERT_EXPR:
@@ -5056,6 +5057,7 @@ fold_simple_1 (tree t)
       return fold_sizeof_expr (t);
 
     case ABS_EXPR:
+    case ABSU_EXPR:
     case CONJ_EXPR:
     case REALPART_EXPR:
     case IMAGPART_EXPR:
diff --git gcc/cp/error.c gcc/cp/error.c
index 6a261132afb..b0d8e322e65 100644
--- gcc/cp/error.c
+++ gcc/cp/error.c
@@ -2764,6 +2764,7 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
     case VEC_DELETE_EXPR:
     case MODOP_EXPR:
     case ABS_EXPR:
+    case ABSU_EXPR:
     case CONJ_EXPR:
     case VECTOR_CST:
     case FIXED_CST:
diff --git gcc/testsuite/g++.dg/pr86240.C gcc/testsuite/g++.dg/pr86240.C
index e69de29bb2d..16ae89cccd1 100644
--- gcc/testsuite/g++.dg/pr86240.C
+++ gcc/testsuite/g++.dg/pr86240.C
@@ -0,0 +1,12 @@
+// { dg-do compile }
+
+extern "C" int abs (int);
+struct a {
+  short b;
+} e;
+short c;
+bool
+foo ()
+{
+  return abs(c) >= e.b;
+}



More information about the Gcc-patches mailing list