]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Fix up __builtin_assoc_barrier handling in the C FE [PR104427]
authorJakub Jelinek <jakub@redhat.com>
Wed, 9 Feb 2022 19:45:31 +0000 (20:45 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 9 Feb 2022 19:46:10 +0000 (20:46 +0100)
The following testcase ICEs, because when creating PAREN_EXPR for
__builtin_assoc_barrier the FE doesn't do the usual tweaks for
EXCESS_PRECISION_EXPR or C_MAYBE_CONST_EXPR.  I believe that the
declared effect of the builtin is just association barrier, so
e.g. excess precision should be still handled like if it wasn't
there.

The following patch uses build_unary_op to handle those.

2022-02-09  Jakub Jelinek  <jakub@redhat.com>

PR c/104427
* c-parser.cc (c_parser_postfix_expression)
<case RID_BUILTIN_ASSOC_BARRIER>: Use parser_build_unary_op
instead of build1_loc to build PAREN_EXPR.
* c-typeck.cc (build_unary_op): Handle PAREN_EXPR.
* c-fold.cc (c_fully_fold_internal): Likewise.

* gcc.dg/pr104427.c: New test.

gcc/c/c-fold.cc
gcc/c/c-parser.cc
gcc/c/c-typeck.cc
gcc/testsuite/gcc.dg/pr104427.c [new file with mode: 0644]

index fc593753c1b94ffdfb0d9e7e45280734afb593a3..76ea25b3d7febeda3b1b65b4656a0e43f9d7ad60 100644 (file)
@@ -465,6 +465,7 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
     case BIT_NOT_EXPR:
     case TRUTH_NOT_EXPR:
     case CONJ_EXPR:
+    case PAREN_EXPR:
     unary:
       /* Unary operations.  */
       orig_op0 = op0 = TREE_OPERAND (expr, 0);
index e9086c5852478a95383093831a67af89f3be98d1..7e81c33de1154a6dd41383bd9b09f9c4acdf5fff 100644 (file)
@@ -10128,8 +10128,7 @@ c_parser_postfix_expression (c_parser *parser)
            mark_exp_read (e1.value);
            location_t end_loc = c_parser_peek_token (parser)->get_finish ();
            parens.skip_until_found_close (parser);
-           expr.value = build1_loc (loc, PAREN_EXPR, TREE_TYPE (e1.value),
-                                    e1.value);
+           expr = parser_build_unary_op (loc, PAREN_EXPR, e1);
            set_c_expr_source_range (&expr, start_loc, end_loc);
          }
          break;
index b06f07874768de7cc63b20967a0f0ab516c03b0b..39094cc6f5075fb5a78b2c49190c9a7965a96347 100644 (file)
@@ -4921,6 +4921,10 @@ build_unary_op (location_t location, enum tree_code code, tree xarg,
       ret = val;
       goto return_build_unary_op;
 
+    case PAREN_EXPR:
+      ret = build1 (code, TREE_TYPE (arg), arg);
+      goto return_build_unary_op;
+
     default:
       gcc_unreachable ();
     }
diff --git a/gcc/testsuite/gcc.dg/pr104427.c b/gcc/testsuite/gcc.dg/pr104427.c
new file mode 100644 (file)
index 0000000..397cb13
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR c/104427 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+/* { dg-add-options float16 } */
+/* { dg-require-effective-target float16 } */
+
+_Float16 x, y;
+
+int
+foo ()
+{
+  return __builtin_assoc_barrier (x + y) - y;
+}