diff mbox

[match-and-simplify] reject conditional convert and commutative ops in result operand

Message ID CAJXstsCO-PmKS=gV9uCw_yWNQthNvjOg80G_My65O+uPFfwwNA@mail.gmail.com
State New
Headers show

Commit Message

Prathamesh Kulkarni Oct. 27, 2014, 2:32 p.m. UTC
I suppose we should reject conditional convert and commutative ops in
result operand ? since it would create 1-n mapping from match ->
result.

* genmatch.c
  (fatal_at): New overloaded function with source_location as first parameter.
  (has_opt_convert_or_commutative_ops): New function.
  (lower): Call has_opt_convert_or_commutative_ops.

Thanks,
Prathamesh

Comments

Richard Biener Oct. 28, 2014, 10:20 a.m. UTC | #1
On Mon, Oct 27, 2014 at 3:32 PM, Prathamesh Kulkarni
<bilbotheelffriend@gmail.com> wrote:
> I suppose we should reject conditional convert and commutative ops in
> result operand ? since it would create 1-n mapping from match ->
> result.

Yeah.  Same is true for parsing of :type syntax for the match part.
Now that we have a class parser I think it would be better to simply
record whether we are parsing ->match or ->result and issue the
diagnostic at parsing time.

Can you adjust the patch accordingly?

Thanks,
Richard.

> * genmatch.c
>   (fatal_at): New overloaded function with source_location as first parameter.
>   (has_opt_convert_or_commutative_ops): New function.
>   (lower): Call has_opt_convert_or_commutative_ops.
>
> Thanks,
> Prathamesh
diff mbox

Patch

Index: gcc/genmatch.c
===================================================================
--- gcc/genmatch.c	(revision 216718)
+++ gcc/genmatch.c	(working copy)
@@ -83,6 +83,18 @@ 
 #if GCC_VERSION >= 4001
 __attribute__((format (printf, 2, 3)))
 #endif
+fatal_at (source_location src_loc, const char *msg, ...)
+{
+  va_list ap;
+  va_start (ap, msg);
+  error_cb (0, CPP_DL_FATAL, 0, src_loc, 0, msg, &ap);
+  va_end (ap);
+}
+
+static void
+#if GCC_VERSION >= 4001
+__attribute__((format (printf, 2, 3)))
+#endif
 fatal_at (const cpp_token *tk, const char *msg, ...)
 {
   va_list ap;
@@ -877,11 +889,46 @@ 
     simplifiers.safe_push (worklist[i]);
 }
 
+bool
+has_opt_convert_or_commutative_ops (operand *o)
+{
+  if (!o)
+    return false;
+
+  if (capture *c = dyn_cast<capture *> (o))
+    {
+      if (c->what)
+	return has_opt_convert_or_commutative_ops (c->what);
+      else
+	return false;
+    }
+
+  expr *e = dyn_cast<expr *> (o);
+  if (!e)
+    return false;
+
+  if (*e->operation == CONVERT0 || *e->operation == CONVERT1
+      || *e->operation == CONVERT2 || e->is_commutative)
+    return true;
+
+  for (unsigned i = 0; i < e->ops.length (); ++i)
+    if (has_opt_convert_or_commutative_ops (e->ops[i]))
+      return true;
+
+  return false;
+}
+
+  
+
 /* Lower the AST for everything in SIMPLIFIERS.  */
 
 static void
 lower (vec<simplify *>& simplifiers)
 {
+  for (unsigned i = 0; i < simplifiers.length (); ++i)
+    if (has_opt_convert_or_commutative_ops (simplifiers[i]->result))
+      fatal_at (simplifiers[i]->result_location, "result operand cannot contain conditional convert or commutative operator");
+
   auto_vec<simplify *> out_simplifiers0;
   for (unsigned i = 0; i < simplifiers.length (); ++i)
     lower_opt_convert (simplifiers[i], out_simplifiers0);