OSDN Git Service

PR bootstrap/43699
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 12 Apr 2010 13:27:07 +0000 (13:27 +0000)
committerMasaki Muranaka <monaka@monami-software.com>
Sun, 23 May 2010 05:31:39 +0000 (14:31 +0900)
* c-typeck.c (c_process_expr_stmt): Call mark_exp_read even
for exprs satisfying handled_component_p.

* gcc.dg/Wunused-var-7.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@158224 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wunused-var-7.c [new file with mode: 0644]

index e5f48ed..163bf0a 100644 (file)
@@ -1,3 +1,9 @@
+2010-04-12  Jakub Jelinek  <jakub@redhat.com>
+
+       PR bootstrap/43699
+       * c-typeck.c (c_process_expr_stmt): Call mark_exp_read even
+       for exprs satisfying handled_component_p.
+
 2010-04-12  Eric Botcazou  <ebotcazou@adacore.com>
 
        * expr.c (categorize_ctor_elements_1): Properly count sub-elements of
index 326fa86..cd1f9bb 100644 (file)
@@ -8859,17 +8859,13 @@ c_process_expr_stmt (location_t loc, tree expr)
       && warn_unused_value)
     emit_side_effect_warnings (loc, expr);
 
-  exprv = expr;
-  while (TREE_CODE (exprv) == COMPOUND_EXPR)
-    exprv = TREE_OPERAND (exprv, 1);
-  if (DECL_P (exprv) || handled_component_p (exprv))
-    mark_exp_read (exprv);
+  if (DECL_P (expr) || handled_component_p (expr))
+    mark_exp_read (expr);
 
   /* If the expression is not of a type to which we cannot assign a line
      number, wrap the thing in a no-op NOP_EXPR.  */
   if (DECL_P (expr) || CONSTANT_CLASS_P (expr))
     {
-      mark_exp_read (expr);
       expr = build1 (NOP_EXPR, TREE_TYPE (expr), expr);
       SET_EXPR_LOCATION (expr, loc);
     }
index 47b221c..88b78d0 100644 (file)
@@ -1,5 +1,8 @@
 2010-04-12  Jakub Jelinek  <jakub@redhat.com>
 
+       PR bootstrap/43699
+       * gcc.dg/Wunused-var-7.c: New test.
+
        PR tree-optimization/43560
        * gcc.c-torture/execute/pr43560.c: New test.
 
diff --git a/gcc/testsuite/gcc.dg/Wunused-var-7.c b/gcc/testsuite/gcc.dg/Wunused-var-7.c
new file mode 100644 (file)
index 0000000..e82e708
--- /dev/null
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-options "-Wunused -W" } */
+
+int
+f1 (unsigned int x)
+{
+  int c = ({ union { unsigned int a; int b; } u; u.a = x; u.b; });
+  return c;
+}
+
+void
+f2 (void)
+{
+  struct S { int i; } a;
+  int b[1];
+  a.i = 1;
+  a.i;                         /* { dg-warning "with no effect" } */
+  b[0] = 1;
+  b[0];                                /* { dg-warning "with no effect" } */
+}
+
+void
+f3 (void)
+{
+  struct S { int i; } a;       /* { dg-warning "set but not used" } */
+  int b[1];                    /* { dg-warning "set but not used" } */
+  a.i = 1;
+  b[0] = 1;
+}