This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On Tue, Oct 28, 2014 at 3:50 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
> 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?
Is the following version okay ?

* genmatch.c
  (parser): Add new member parsing_match_operand.
  (parser::parse_operation): Check for conditional convert in result operand.
  (parser::parse_expr): Check for commutative operator in result operand.
                                     Check for :type in match operand.
  (parser::parse_simplify): Set/unset parsing_match_operand.

Thanks,
Prathamesh

>
> 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
Index: gcc/genmatch.c
===================================================================
--- gcc/genmatch.c	(revision 216776)
+++ gcc/genmatch.c	(working copy)
@@ -2453,6 +2453,7 @@
 public:
   vec<simplify *> simplifiers;
   vec<predicate_id *> user_predicates;
+  bool parsing_match_operand;
 };
 
 /* Lexing helpers.  */
@@ -2598,6 +2599,9 @@
 	;
       else
 	fatal_at (id_tok, "non-convert operator conditionalized");
+
+      if (!parsing_match_operand)
+	fatal_at (id_tok, "conditional convert can only be used in match expression");
       eat_token (CPP_QUERY);
     }
   else if (strcmp  (id, "convert1") == 0
@@ -2652,11 +2656,20 @@
 	{
 	  const char *s = get_ident ();
 	  if (s[0] == 'c' && !s[1])
-	    is_commutative = true;
+	    {
+	      if (!parsing_match_operand)
+		fatal_at (token, "flag :c can only be used in match expression");
+	      is_commutative = true;
+	    }
 	  else if (s[1] != '\0')
-	    expr_type = s;
+	    {
+	      if (parsing_match_operand)
+		fatal_at (token, "':type' can only be used in result expression");
+	      expr_type = s;
+	    }
 	  else
 	    fatal_at (token, "flag %s not recognized", s);
+	  
 	  token = peek ();
 	}
       else
@@ -2809,6 +2822,7 @@
 {
   /* Reset the capture map.  */
   capture_ids = new std::map<std::string, unsigned>;
+  parsing_match_operand = true;
 
   const cpp_token *loc = peek ();
   struct operand *match = parse_op ();
@@ -2818,6 +2832,7 @@
       && is_a <predicate_id *> (as_a <expr *> (match)->operation))
     fatal_at (loc, "outermost expression cannot be a predicate");
 
+  parsing_match_operand = false; 
   const cpp_token *token = peek ();
 
   /* If this if is immediately closed then it is part of a predicate

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]