[PATCH] Latest version of the -Wunused-but-set-{variable,parameter} patches (misc part)

Jakub Jelinek jakub@redhat.com
Fri Jan 22 16:12:00 GMT 2010


Hi!

Here are various workarounds to avoid the set but not used warnings
during bootstrap.  Bootstrapped/regtested on x86_64-linux and i686-linux.
Ok for 4.6?

	Jakub
-------------- next part --------------
2010-01-22  Jakub Jelinek  <jakub@redhat.com>

	* genemit.c (gen_expand, gen_split): Avoid set but not used warnings
	when operandN variables aren't used in the body of the expander
	or splitter.
	* tree-outof-ssa.c (FOR_EACH_ELIM_GRAPH_SUCC,
	FOR_EACH_ELIM_GRAPH_PRED): Avoid set but not used warnings.
	* tree-ssa-operands.h (FOR_EACH_SSA_TREE_OPERAND): Likewise.
	* tree-flow.h (FOR_EACH_IMM_USE_FAST, FOR_EACH_IMM_USE_STMT):
	Likewise.
	* tree.h (FOR_EACH_CONSTRUCTOR_ELT): Likewise.
	* tree.c (PROCESS_ARG): Likewise.
fortran/
	* parse.c (parse_derived, parse_enum): Avoid set but not used
	warning.
java/
	* expr.c (process_jvm_instruction): Avoid set but not used warning.
	* builtins.c (compareAndSwapInt_builtin, compareAndSwapLong_builtin,
	getVolatile_builtin): Likewise.
libjava/
	* exception.cc (_Jv_Throw): Avoid set but not used warning.
	* include/java-assert.h (JvAssertMessage, JvAssert): Use argument in
	sizeof to avoid set but not used warnings.
libjava/classpath/
	* native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaPortDevice.c
	(Java_gnu_javax_sound_midi_alsa_AlsaPortDevice_run_1receiver_1thread_1):
	Avoid set but not used warning.
libiberty/
	* regex.c (byte_re_match_2_internal): Avoid set but not used
	warning.
gcc/testsuite/
	* gcc.dg/builtin-choose-expr.c: Avoid set but not used warnings.
	* gcc.dg/trunc-1.c: Likewise.
	* gcc.dg/vla-9.c: Likewise.
	* gcc.dg/dfp/composite-type.c: Likewise.
libffi/
	* testsuite/libffi.call/err_bad_abi.c: Remove unused args variable.

--- gcc/tree-outof-ssa.c.jj	2009-11-25 16:47:37.000000000 +0100
+++ gcc/tree-outof-ssa.c	2009-11-27 14:57:14.000000000 +0100
@@ -431,8 +431,9 @@ do {									\
       y_ = VEC_index (int, (GRAPH)->edge_list, x_);			\
       if (y_ != (NODE))							\
         continue;							\
-      (VAR) = VEC_index (int, (GRAPH)->edge_list, x_ + 1);		\
-      (LOCUS) = VEC_index (source_location, (GRAPH)->edge_locus, x_ / 2); \
+      (void) ((VAR) = VEC_index (int, (GRAPH)->edge_list, x_ + 1));	\
+      (void) ((LOCUS) = VEC_index (source_location,			\
+				   (GRAPH)->edge_locus, x_ / 2));	\
       CODE;								\
     }									\
 } while (0)
@@ -451,8 +452,9 @@ do {									\
       y_ = VEC_index (int, (GRAPH)->edge_list, x_ + 1);			\
       if (y_ != (NODE))							\
         continue;							\
-      (VAR) = VEC_index (int, (GRAPH)->edge_list, x_);			\
-      (LOCUS) = VEC_index (source_location, (GRAPH)->edge_locus, x_ / 2); \
+      (void) ((VAR) = VEC_index (int, (GRAPH)->edge_list, x_));		\
+      (void) ((LOCUS) = VEC_index (source_location,			\
+				   (GRAPH)->edge_locus, x_ / 2));	\
       CODE;								\
     }									\
 } while (0)
--- gcc/tree-flow.h.jj	2009-11-25 16:47:37.000000000 +0100
+++ gcc/tree-flow.h	2009-11-27 14:58:54.000000000 +0100
@@ -256,17 +256,17 @@ typedef struct immediate_use_iterator_d
 /* Use this iterator when simply looking at stmts.  Adding, deleting or
    modifying stmts will cause this iterator to malfunction.  */
 
-#define FOR_EACH_IMM_USE_FAST(DEST, ITER, SSAVAR)			\
+#define FOR_EACH_IMM_USE_FAST(DEST, ITER, SSAVAR)		\
   for ((DEST) = first_readonly_imm_use (&(ITER), (SSAVAR));	\
        !end_readonly_imm_use_p (&(ITER));			\
-       (DEST) = next_readonly_imm_use (&(ITER)))
+       (void) ((DEST) = next_readonly_imm_use (&(ITER))))
 
 /* Use this iterator to visit each stmt which has a use of SSAVAR.  */
 
 #define FOR_EACH_IMM_USE_STMT(STMT, ITER, SSAVAR)		\
   for ((STMT) = first_imm_use_stmt (&(ITER), (SSAVAR));		\
        !end_imm_use_stmt_p (&(ITER));				\
-       (STMT) = next_imm_use_stmt (&(ITER)))
+       (void) ((STMT) = next_imm_use_stmt (&(ITER))))
 
 /* Use this to terminate the FOR_EACH_IMM_USE_STMT loop early.  Failure to
    do so will result in leaving a iterator marker node in the immediate
--- gcc/tree.h.jj	2009-11-27 13:00:10.000000000 +0100
+++ gcc/tree.h	2009-11-27 16:14:33.000000000 +0100
@@ -1510,9 +1510,9 @@ struct GTY(()) tree_vec {
 #define FOR_EACH_CONSTRUCTOR_ELT(V, IX, INDEX, VAL) \
   for (IX = 0; (IX >= VEC_length (constructor_elt, V)) \
 	       ? false \
-	       : ((VAL = VEC_index (constructor_elt, V, IX)->value), \
+	       : (((void) (VAL = VEC_index (constructor_elt, V, IX)->value)), \
 		  (INDEX = VEC_index (constructor_elt, V, IX)->index), \
-	       true); \
+		  true); \
        (IX)++)
 
 /* Append a new constructor element to V, with the specified INDEX and VAL.  */
--- gcc/tree.c.jj	2009-11-25 16:47:35.000000000 +0100
+++ gcc/tree.c	2009-11-27 15:13:11.000000000 +0100
@@ -3640,9 +3640,9 @@ build1_stat (enum tree_code code, tree t
 	  side_effects = 1;			\
         if (!TREE_READONLY (arg##N)		\
 	    && !CONSTANT_CLASS_P (arg##N))	\
-	  read_only = 0;			\
+	  (void) (read_only = 0);		\
         if (!TREE_CONSTANT (arg##N))		\
-	  constant = 0;				\
+	  (void) (constant = 0);		\
       }						\
   } while (0)
 
--- gcc/genemit.c.jj	2009-11-27 12:36:45.000000000 +0100
+++ gcc/genemit.c	2009-11-27 13:00:46.000000000 +0100
@@ -520,12 +520,13 @@ gen_expand (rtx expand)
 	 (unless we aren't going to use them at all).  */
       if (XVEC (expand, 1) != 0)
 	{
-	  for (i = 0; i < operands; i++)
-	    printf ("    operand%d = operands[%d];\n", i, i);
-	  for (; i <= max_dup_opno; i++)
-	    printf ("    operand%d = operands[%d];\n", i, i);
-	  for (; i <= max_scratch_opno; i++)
-	    printf ("    operand%d = operands[%d];\n", i, i);
+	  for (i = 0;
+	       i < MAX (operands, MAX (max_scratch_opno, max_dup_opno) + 1);
+	       i++)
+	    {
+	      printf ("    operand%d = operands[%d];\n", i, i);
+	      printf ("    (void) operand%d;\n", i);
+	    }
 	}
       printf ("  }\n");
     }
@@ -647,7 +648,10 @@ gen_split (rtx split)
 
   /* Output code to copy the arguments back out of `operands'  */
   for (i = 0; i < operands; i++)
-    printf ("  operand%d = operands[%d];\n", i, i);
+    {
+      printf ("  operand%d = operands[%d];\n", i, i);
+      printf ("  (void) operand%d;\n", i);
+    }
 
   /* Output code to construct the rtl for the instruction bodies.
      Use emit_insn to add them to the sequence being accumulated.
--- gcc/tree-ssa-operands.h.jj	2009-11-25 16:47:35.000000000 +0100
+++ gcc/tree-ssa-operands.h	2009-11-27 15:00:35.000000000 +0100
@@ -160,7 +160,7 @@ typedef struct ssa_operand_iterator_d
 #define FOR_EACH_SSA_TREE_OPERAND(TREEVAR, STMT, ITER, FLAGS)	\
   for (TREEVAR = op_iter_init_tree (&(ITER), STMT, FLAGS);	\
        !op_iter_done (&(ITER));					\
-       TREEVAR = op_iter_next_tree (&(ITER)))
+       (void) (TREEVAR = op_iter_next_tree (&(ITER))))
 
 /* This macro executes a loop over the operands of STMT specified in FLAG,
    returning each operand as a 'use_operand_p' in the variable USEVAR.
--- gcc/fortran/parse.c.jj	2010-01-20 09:04:00.000000000 +0100
+++ gcc/fortran/parse.c	2010-01-22 14:56:33.000000000 +0100
@@ -1940,14 +1940,12 @@ parse_derived_contains (void)
 static void
 parse_derived (void)
 {
-  int compiling_type, seen_private, seen_sequence, seen_component, error_flag;
+  int compiling_type, seen_private, seen_sequence, seen_component;
   gfc_statement st;
   gfc_state_data s;
   gfc_symbol *sym;
   gfc_component *c;
 
-  error_flag = 0;
-
   accept_statement (ST_DERIVED_DECL);
   push_state (&s, COMP_DERIVED, gfc_new_block);
 
@@ -1974,18 +1972,15 @@ parse_derived (void)
 
 	case ST_FINAL:
 	  gfc_error ("FINAL declaration at %C must be inside CONTAINS");
-	  error_flag = 1;
 	  break;
 
 	case ST_END_TYPE:
 endType:
 	  compiling_type = 0;
 
-	  if (!seen_component
-	      && (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: Derived type "
-				 "definition at %C without components")
-		  == FAILURE))
-	    error_flag = 1;
+	  if (!seen_component)
+	    gfc_notify_std (GFC_STD_F2003, "Fortran 2003: Derived type "
+			    "definition at %C without components");
 
 	  accept_statement (ST_END_TYPE);
 	  break;
@@ -1995,7 +1990,6 @@ endType:
 	    {
 	      gfc_error ("PRIVATE statement in TYPE at %C must be inside "
 			 "a MODULE");
-	      error_flag = 1;
 	      break;
 	    }
 
@@ -2003,15 +1997,11 @@ endType:
 	    {
 	      gfc_error ("PRIVATE statement at %C must precede "
 			 "structure components");
-	      error_flag = 1;
 	      break;
 	    }
 
 	  if (seen_private)
-	    {
-	      gfc_error ("Duplicate PRIVATE statement at %C");
-	      error_flag = 1;
-	    }
+	    gfc_error ("Duplicate PRIVATE statement at %C");
 
 	  s.sym->component_access = ACCESS_PRIVATE;
 
@@ -2024,7 +2014,6 @@ endType:
 	    {
 	      gfc_error ("SEQUENCE statement at %C must precede "
 			 "structure components");
-	      error_flag = 1;
 	      break;
 	    }
 
@@ -2035,7 +2024,6 @@ endType:
 	  if (seen_sequence)
 	    {
 	      gfc_error ("Duplicate SEQUENCE statement at %C");
-	      error_flag = 1;
 	    }
 
 	  seen_sequence = 1;
@@ -2044,14 +2032,12 @@ endType:
 	  break;
 
 	case ST_CONTAINS:
-	  if (gfc_notify_std (GFC_STD_F2003,
-			      "Fortran 2003:  CONTAINS block in derived type"
-			      " definition at %C") == FAILURE)
-	    error_flag = 1;
+	  gfc_notify_std (GFC_STD_F2003,
+			  "Fortran 2003:  CONTAINS block in derived type"
+			  " definition at %C");
 
 	  accept_statement (ST_CONTAINS);
-	  if (parse_derived_contains ())
-	    error_flag = 1;
+	  parse_derived_contains ();
 	  goto endType;
 
 	default:
@@ -2105,14 +2091,11 @@ endType:
 static void
 parse_enum (void)
 {
-  int error_flag;
   gfc_statement st;
   int compiling_enum;
   gfc_state_data s;
   int seen_enumerator = 0;
 
-  error_flag = 0;
-
   push_state (&s, COMP_ENUM, gfc_new_block);
 
   compiling_enum = 1;
@@ -2134,10 +2117,7 @@ parse_enum (void)
 	case ST_END_ENUM:
 	  compiling_enum = 0;
 	  if (!seen_enumerator)
-	    {
-	      gfc_error ("ENUM declaration at %C has no ENUMERATORS");
-	      error_flag = 1;
-	    }
+	    gfc_error ("ENUM declaration at %C has no ENUMERATORS");
 	  accept_statement (st);
 	  break;
 
--- gcc/java/expr.c.jj	2009-11-28 17:21:33.000000000 +0100
+++ gcc/java/expr.c	2010-01-22 15:02:27.000000000 +0100
@@ -3329,6 +3329,7 @@ process_jvm_instruction (int PC, const u
   {									\
     int saw_index = 0;							\
     int index     = OPERAND_VALUE;					\
+    (void) saw_index; /* Avoid set but not used warning.  */		\
     build_java_ret							\
       (find_local_variable (index, return_address_type_node, oldpc));	\
   }
--- gcc/java/builtins.c.jj	2009-11-28 17:21:33.000000000 +0100
+++ gcc/java/builtins.c	2010-01-22 15:05:10.000000000 +0100
@@ -323,6 +323,7 @@ compareAndSwapInt_builtin (tree method_r
     {
       tree addr, stmt;
       UNMARSHAL5 (orig_call);
+      (void) value_type; /* Avoid set but not used warning.  */
 
       addr = build_addr_sum (int_type_node, obj_arg, offset_arg);
       stmt = build_call_expr (built_in_decls[BUILT_IN_BOOL_COMPARE_AND_SWAP_4],
@@ -347,6 +348,7 @@ compareAndSwapLong_builtin (tree method_
     {
       tree addr, stmt;
       UNMARSHAL5 (orig_call);
+      (void) value_type; /* Avoid set but not used warning.  */
 
       addr = build_addr_sum (long_type_node, obj_arg, offset_arg);
       stmt = build_call_expr (built_in_decls[BUILT_IN_BOOL_COMPARE_AND_SWAP_8],
@@ -410,7 +412,8 @@ getVolatile_builtin (tree method_return_
 {
   tree addr, stmt, modify_stmt, tmp;
   UNMARSHAL3 (orig_call);
-  
+  (void) this_arg; /* Avoid set but not used warning.  */
+
   addr = build_addr_sum (method_return_type, obj_arg, offset_arg);
   addr 
     = fold_convert (build_pointer_type (build_type_variant 
--- libjava/classpath/native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaPortDevice.c.jj	2008-09-05 12:57:59.000000000 +0200
+++ libjava/classpath/native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaPortDevice.c	2009-11-27 17:34:12.000000000 +0100
@@ -48,7 +48,7 @@ Java_gnu_javax_sound_midi_alsa_AlsaPortD
   (JNIEnv *env, jobject this __attribute__((unused)), 
    jlong client, jlong port, jobject receiver)
 {
-  int rc;
+  int rc __attribute__((unused));
   snd_seq_port_info_t *pinfo, *sinfo;
   snd_seq_port_subscribe_t *subs;
   snd_seq_addr_t sender, dest;
--- libjava/exception.cc.jj	2009-11-18 15:52:41.000000000 +0100
+++ libjava/exception.cc	2010-01-22 15:09:35.000000000 +0100
@@ -111,11 +111,10 @@ _Jv_Throw (jthrowable value)
 
   /* We're happy with setjmp/longjmp exceptions or region-based
      exception handlers: entry points are provided here for both.  */
-  _Unwind_Reason_Code code;
 #ifdef SJLJ_EXCEPTIONS
-  code = _Unwind_SjLj_RaiseException (&xh->unwindHeader);
+  _Unwind_SjLj_RaiseException (&xh->unwindHeader);
 #else
-  code = _Unwind_RaiseException (&xh->unwindHeader);
+  _Unwind_RaiseException (&xh->unwindHeader);
 #endif
 
   /* If code == _URC_END_OF_STACK, then we reached top of stack without
--- libjava/include/java-assert.h.jj	2009-05-04 16:46:47.000000000 +0200
+++ libjava/include/java-assert.h	2010-01-22 15:12:08.000000000 +0100
@@ -29,8 +29,8 @@ void _Jv_Abort (const char *, const char
 #else /* __GCJ_DEBUG */
 
 #define _Jv_AssertDoCall(Message)
-#define JvAssertMessage(Expr, Message)
-#define JvAssert(Expr)
+#define JvAssertMessage(Expr, Message) (void) sizeof (Expr)
+#define JvAssert(Expr) (void) sizeof (Expr)
 #define JvFail(Message) _Jv_Abort (0, 0, 0, Message)
 
 #endif /* not __GCJ_DEBUG */
--- libiberty/regex.c.jj	2009-10-02 10:02:01.000000000 +0200
+++ libiberty/regex.c	2009-11-27 17:33:04.000000000 +0100
@@ -7140,8 +7140,8 @@ byte_re_match_2_internal (struct re_patt
                register from the stack, since lowest will == highest in
                `pop_failure_point'.  */
             active_reg_t dummy_low_reg, dummy_high_reg;
-            UCHAR_T *pdummy = NULL;
-            const CHAR_T *sdummy = NULL;
+            UCHAR_T *pdummy ATTRIBUTE_UNUSED = NULL;
+            const CHAR_T *sdummy ATTRIBUTE_UNUSED = NULL;
 
             DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n");
             POP_FAILURE_POINT (sdummy, pdummy,
--- gcc/testsuite/gcc.dg/builtin-choose-expr.c.jj	2009-11-27 12:25:18.000000000 +0100
+++ gcc/testsuite/gcc.dg/builtin-choose-expr.c	2009-11-27 13:00:46.000000000 +0100
@@ -29,6 +29,8 @@
           t1 = t1b;						\
           t2 = t2a;						\
           t2 = t2b;						\
+          (void) t1;						\
+          (void) t2;						\
         } while (0)
 
 
--- gcc/testsuite/gcc.dg/trunc-1.c.jj	2009-11-27 12:25:18.000000000 +0100
+++ gcc/testsuite/gcc.dg/trunc-1.c	2009-11-27 13:00:46.000000000 +0100
@@ -11,5 +11,5 @@ main (void)
 
   len = ~(sizeof (size_t) - 1); /* { dg-bogus "truncated" "bogus truncation warning" } */
 
-  return 0;
+  return len - len;
 }
--- gcc/testsuite/gcc.dg/vla-9.c.jj	2009-11-27 12:25:18.000000000 +0100
+++ gcc/testsuite/gcc.dg/vla-9.c	2009-11-27 13:00:46.000000000 +0100
@@ -6,4 +6,5 @@ void f(__SIZE_TYPE__ d)
 {
   typedef int t[d];
   t *g = (__typeof (g)) d;
+  (void) g;
 }
--- gcc/testsuite/gcc.dg/dfp/composite-type.c.jj	2009-11-27 12:25:18.000000000 +0100
+++ gcc/testsuite/gcc.dg/dfp/composite-type.c	2009-11-27 13:00:46.000000000 +0100
@@ -30,18 +30,19 @@ do \
  d##TYPE = f2_##TYPE(h1_##TYPE); \
  d##TYPE = f2_##TYPE(h2_##TYPE); \
  d##TYPE = f2_##TYPE(h3_##TYPE); \
+ (void) d##TYPE; \
 } while(0)
  
 DECIMAL_COMPOSITE_DECL(32);  /* { dg-error "incompatible types when assigning to type '\[^\n\]*' from type '\[^\n\]*'" } */
-/* { dg-message "note: expected '\[^'\n\]*' but argument is of type '\[^'\n\]*'" "note: expected" { target *-*-* } 35 } */
+/* { dg-message "note: expected '\[^'\n\]*' but argument is of type '\[^'\n\]*'" "note: expected" { target *-*-* } 36 } */
 
 
 DECIMAL_COMPOSITE_DECL(64);  /* { dg-error "incompatible types when assigning to type '\[^\n\]*' from type '\[^\n\]*'" } */
-/* { dg-message "note: expected '\[^'\n\]*' but argument is of type '\[^'\n\]*'" "note: expected" { target *-*-* } 39 } */
+/* { dg-message "note: expected '\[^'\n\]*' but argument is of type '\[^'\n\]*'" "note: expected" { target *-*-* } 40 } */
 
 
 DECIMAL_COMPOSITE_DECL(128); /* { dg-error "incompatible types when assigning to type '\[^\n\]*' from type '\[^\n\]*'" } */
-/* { dg-message "note: expected '\[^'\n\]*' but argument is of type '\[^'\n\]*'" "note: expected" { target *-*-* } 43 } */
+/* { dg-message "note: expected '\[^'\n\]*' but argument is of type '\[^'\n\]*'" "note: expected" { target *-*-* } 44 } */
 
 
 int main()
--- libffi/testsuite/libffi.call/err_bad_abi.c.jj	2009-06-30 13:10:41.000000000 +0200
+++ libffi/testsuite/libffi.call/err_bad_abi.c	2010-01-20 16:26:15.000000000 +0100
@@ -17,11 +17,9 @@ int main (void)
 	ffi_cif cif;
         void *code;
 	ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
-	void* args[1];
 	ffi_type* arg_types[1];
 
 	arg_types[0] = NULL;
-	args[0] = NULL;
 
 	CHECK(ffi_prep_cif(&cif, 255, 0, &ffi_type_void,
 		arg_types) == FFI_BAD_ABI);


More information about the Gcc-patches mailing list