PR c/60195
authormpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 19 Feb 2014 06:29:49 +0000 (06:29 +0000)
committermpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 19 Feb 2014 06:29:49 +0000 (06:29 +0000)
c/
* c-typeck.c (convert_lvalue_to_rvalue): Set TREE_NO_WARNING on tmp.
Call mark_exp_read on exp.value.
(build_atomic_assign): Set TREE_NO_WARNING on val and old.  Set
TREE_ADDRESSABLE on old instead of val.
(emit_side_effect_warnings): Warn only if RHS has !TREE_NO_WARNING.
testsuite/
* gcc.dg/pr60195.c: New test.

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

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

index 8d11ad6..32d7242 100644 (file)
@@ -1,3 +1,12 @@
+2014-02-19  Marek Polacek  <polacek@redhat.com>
+
+       PR c/60195
+       * c-typeck.c (convert_lvalue_to_rvalue): Set TREE_NO_WARNING on tmp.
+       Call mark_exp_read on exp.value.
+       (build_atomic_assign): Set TREE_NO_WARNING on val and old.  Set
+       TREE_ADDRESSABLE on old instead of val.
+       (emit_side_effect_warnings): Warn only if RHS has !TREE_NO_WARNING.
+
 2014-02-07  Prathamesh Kulkarni  <bilbotheelffriend@gmail.com>
 
        * c-parser.c (c_parser_get_builtin_args): Replace calls to
index da6a6fc..2b54290 100644 (file)
@@ -2009,6 +2009,7 @@ convert_lvalue_to_rvalue (location_t loc, struct c_expr exp,
       tmp = create_tmp_var (nonatomic_type, NULL);
       tmp_addr = build_unary_op (loc, ADDR_EXPR, tmp, 0);
       TREE_ADDRESSABLE (tmp) = 1;
+      TREE_NO_WARNING (tmp) = 1;
 
       /* Issue __atomic_load (&expr, &tmp, SEQ_CST);  */
       fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
@@ -2017,6 +2018,9 @@ convert_lvalue_to_rvalue (location_t loc, struct c_expr exp,
       params->quick_push (seq_cst);
       func_call = build_function_call_vec (loc, vNULL, fndecl, params, NULL);
 
+      /* EXPR is always read.  */
+      mark_exp_read (exp.value);
+
       /* Return tmp which contains the value loaded.  */
       exp.value = build2 (COMPOUND_EXPR, nonatomic_type, func_call, tmp);
     }
@@ -3615,6 +3619,7 @@ build_atomic_assign (location_t loc, tree lhs, enum tree_code modifycode,
   nonatomic_rhs_type = build_qualified_type (rhs_type, TYPE_UNQUALIFIED);
   val = create_tmp_var (nonatomic_rhs_type, NULL);
   TREE_ADDRESSABLE (val) = 1;
+  TREE_NO_WARNING (val) = 1;
   rhs = build2 (MODIFY_EXPR, nonatomic_rhs_type, val, rhs);
   SET_EXPR_LOCATION (rhs, loc);
   add_stmt (rhs);
@@ -3643,7 +3648,8 @@ build_atomic_assign (location_t loc, tree lhs, enum tree_code modifycode,
   /* Create the variables and labels required for the op= form.  */
   old = create_tmp_var (nonatomic_lhs_type, NULL);
   old_addr = build_unary_op (loc, ADDR_EXPR, old, 0);
-  TREE_ADDRESSABLE (val) = 1;
+  TREE_ADDRESSABLE (old) = 1;
+  TREE_NO_WARNING (old) = 1;
 
   newval = create_tmp_var (nonatomic_lhs_type, NULL);
   newval_addr = build_unary_op (loc, ADDR_EXPR, newval, 0);
@@ -9661,6 +9667,7 @@ emit_side_effect_warnings (location_t loc, tree expr)
       if (!TREE_SIDE_EFFECTS (r)
          && !VOID_TYPE_P (TREE_TYPE (r))
          && !CONVERT_EXPR_P (r)
+         && !TREE_NO_WARNING (r)
          && !TREE_NO_WARNING (expr))
        warning_at (cloc, OPT_Wunused_value,
                    "right-hand operand of comma expression has no effect");
index 4e92a85..e246657 100644 (file)
@@ -1,3 +1,8 @@
+2014-02-19  Marek Polacek  <polacek@redhat.com>
+
+       PR c/60195
+       * gcc.dg/pr60195.c: New test.
+
 2014-02-19  Paul Pluzhnikov  <ppluzhnikov@google.com>
 
        * gcc.dg/vect/no-vfa-vect-depend-2.c (main1): Fix buffer
diff --git a/gcc/testsuite/gcc.dg/pr60195.c b/gcc/testsuite/gcc.dg/pr60195.c
new file mode 100644 (file)
index 0000000..0a50a30
--- /dev/null
@@ -0,0 +1,56 @@
+/* PR c/60195 */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -Wpedantic -Wall" } */
+
+typedef _Atomic int atomic_int;
+
+atomic_int
+fn1 (void)
+{
+  atomic_int y = 0;
+  return y;
+}
+
+atomic_int
+fn2 (void)
+{
+  atomic_int y = 0;
+  y;
+  return y;
+}
+
+atomic_int
+fn3 (void)
+{
+  atomic_int y = 0;
+  y++;
+  return y;
+}
+
+void
+fn4 (void)
+{
+  atomic_int y;
+  y = 0;
+  (void) y;
+}
+
+void
+fn5 (void)
+{
+  atomic_int y = 0; /* { dg-warning "unused variable" } */
+}
+
+void
+fn6 (void)
+{
+  atomic_int y;  /* { dg-warning "set but not used" } */
+  y = 0;
+}
+
+void
+fn7 (void)
+{
+  atomic_int y = 0;
+  y++;
+}