diff mbox

[C] Tidy build_unary_op

Message ID 20160910163653.GL19950@redhat.com
State New
Headers show

Commit Message

Marek Polacek Sept. 10, 2016, 4:36 p.m. UTC
A minor cleanup.  First, FLAG is a really bad name for a parameter, and second,
using two vars for the same thing is redundant (we never modify any of them).
Also some bad formatting.

Bootstrap/regtest on x86_64-linux running.  Ok for trunk?

2016-09-10  Marek Polacek  <polacek@redhat.com>

	* c-typeck.c (build_unary_op): Rename FLAG parameter to NOCONVERT.  Use
	it.


	Marek

Comments

Joseph Myers Sept. 12, 2016, 9:53 p.m. UTC | #1
On Sat, 10 Sep 2016, Marek Polacek wrote:

> A minor cleanup.  First, FLAG is a really bad name for a parameter, and second,
> using two vars for the same thing is redundant (we never modify any of them).
> Also some bad formatting.
> 
> Bootstrap/regtest on x86_64-linux running.  Ok for trunk?

OK.  If changing this argument it would seem natural to make it a bool 
(and update callers to use true/false), unless that would be confusing for 
other reasons (e.g. passing it through to other functions where the 
corresponding argument isn't boolean).
Marek Polacek Sept. 13, 2016, 9:12 a.m. UTC | #2
On Mon, Sep 12, 2016 at 09:53:52PM +0000, Joseph Myers wrote:
> On Sat, 10 Sep 2016, Marek Polacek wrote:
> 
> > A minor cleanup.  First, FLAG is a really bad name for a parameter, and second,
> > using two vars for the same thing is redundant (we never modify any of them).
> > Also some bad formatting.
> > 
> > Bootstrap/regtest on x86_64-linux running.  Ok for trunk?
> 
> OK.  If changing this argument it would seem natural to make it a bool 

Thanks.

> (and update callers to use true/false), unless that would be confusing for 
> other reasons (e.g. passing it through to other functions where the 
> corresponding argument isn't boolean).

Yeah, I had been meaning to do that, but then I noticed that I'd have to
change c-common hook too, and thus even the C++ FE.  I'm going to commit
this patch and then do the int -> bool change later on. 

	Marek
diff mbox

Patch

diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index d56c3d6..8c7f895 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -4112,17 +4112,17 @@  cas_loop:
 /* Construct and perhaps optimize a tree representation
    for a unary operation.  CODE, a tree_code, specifies the operation
    and XARG is the operand.
-   For any CODE other than ADDR_EXPR, FLAG nonzero suppresses
+   For any CODE other than ADDR_EXPR, NOCONVERT nonzero suppresses
    the default promotions (such as from short to int).
-   For ADDR_EXPR, the default promotions are not applied; FLAG nonzero
+   For ADDR_EXPR, the default promotions are not applied; NOCONVERT nonzero
    allows non-lvalues; this is only used to handle conversion of non-lvalue
    arrays to pointers in C99.
 
    LOCATION is the location of the operator.  */
 
 tree
-build_unary_op (location_t location,
-		enum tree_code code, tree xarg, int flag)
+build_unary_op (location_t location, enum tree_code code, tree xarg,
+		int noconvert)
 {
   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
   tree arg = xarg;
@@ -4131,7 +4131,6 @@  build_unary_op (location_t location,
   tree val;
   tree ret = error_mark_node;
   tree eptype = NULL_TREE;
-  int noconvert = flag;
   const char *invalid_op_diag;
   bool int_operands;
 
@@ -4276,7 +4275,8 @@  build_unary_op (location_t location,
       if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
 	{
 	  tree inner = build_unary_op (location, code,
-				       C_MAYBE_CONST_EXPR_EXPR (arg), flag);
+				       C_MAYBE_CONST_EXPR_EXPR (arg),
+				       noconvert);
 	  if (inner == error_mark_node)
 	    return error_mark_node;
 	  ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
@@ -4486,7 +4486,7 @@  build_unary_op (location_t location,
 
       /* Anything not already handled and not a true memory reference
 	 or a non-lvalue array is an error.  */
-      if (typecode != FUNCTION_TYPE && !flag
+      if (typecode != FUNCTION_TYPE && !noconvert
 	  && !lvalue_or_else (location, arg, lv_addressof))
 	return error_mark_node;
 
@@ -4495,7 +4495,8 @@  build_unary_op (location_t location,
       if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
 	{
 	  tree inner = build_unary_op (location, code,
-				       C_MAYBE_CONST_EXPR_EXPR (arg), flag);
+				       C_MAYBE_CONST_EXPR_EXPR (arg),
+				       noconvert);
 	  ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
 			C_MAYBE_CONST_EXPR_PRE (arg), inner);
 	  gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));