From: Jakub Jelinek Date: Tue, 26 Mar 2019 07:54:02 +0000 (+0100) Subject: re PR c++/89796 (Incorrect warning generated with OpenMP atomic capture) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=22a32ea068e2ec48fc4d377d2c450a873e76faca;p=gcc.git re PR c++/89796 (Incorrect warning generated with OpenMP atomic capture) PR c++/89796 * semantics.c (finish_omp_atomic): Add warning_sentinel for -Wunused-value around finish_expr_stmt call. * g++.dg/gomp/pr89796.C: New test. * gcc.dg/gomp/pr89796.c: New test. From-SVN: r269933 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 703c0f11696..80d4ae3f1b9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-03-26 Jakub Jelinek + + PR c++/89796 + * semantics.c (finish_omp_atomic): Add warning_sentinel for + -Wunused-value around finish_expr_stmt call. + 2019-03-25 Paolo Carlini PR c++/84661 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 15b766d644d..d7e97e0510d 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -8997,6 +8997,11 @@ finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode, OMP_ATOMIC_MEMORY_ORDER (stmt) = mo; SET_EXPR_LOCATION (stmt, loc); } + + /* Avoid -Wunused-value warnings here, the whole construct has side-effects + and even if it might be wrapped from fold-const.c or c-omp.c wrapped + in some tree that appears to be unused, the value is not unused. */ + warning_sentinel w (warn_unused_value); finish_expr_stmt (stmt); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ddd5f50a8a9..f5d92b6704c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-03-26 Jakub Jelinek + + PR c++/89796 + * g++.dg/gomp/pr89796.C: New test. + * gcc.dg/gomp/pr89796.c: New test. + 2019-03-25 David Malcolm PR rtl-optimization/88347 diff --git a/gcc/testsuite/g++.dg/gomp/pr89796.C b/gcc/testsuite/g++.dg/gomp/pr89796.C new file mode 100644 index 00000000000..6bbc34eae32 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/pr89796.C @@ -0,0 +1,53 @@ +// PR c++/89796 +// { dg-do compile } +// { dg-additional-options "-Wunused-value" } + +int +f1 (int &c) +{ + int r; + #pragma omp atomic capture // { dg-bogus "value computed is not used" } + { r = c; c++; } + return r; +} + +template +int +f2 (int &c) +{ + int r; + #pragma omp atomic capture // { dg-bogus "value computed is not used" } + { r = c; c++; } + return r; +} + +int +f3 (int &c) +{ + return f2 <0> (c); +} + +int +f4 (int *p) +{ + int r; + #pragma omp atomic capture // { dg-bogus "value computed is not used" } + { r = *p; (*p)++; } + return r; +} + +template +int +f5 (int *p) +{ + int r; + #pragma omp atomic capture // { dg-bogus "value computed is not used" } + { r = *p; (*p)++; } + return r; +} + +int +f6 (int *p) +{ + return f5 <0> (p); +} diff --git a/gcc/testsuite/gcc.dg/gomp/pr89796.c b/gcc/testsuite/gcc.dg/gomp/pr89796.c new file mode 100644 index 00000000000..14f509311fa --- /dev/null +++ b/gcc/testsuite/gcc.dg/gomp/pr89796.c @@ -0,0 +1,23 @@ +/* PR c++/89796 */ +/* { dg-do compile } */ +/* { dg-additional-options "-Wunused-value" } */ + +int +f1 (int *p) +{ + int r; + #pragma omp atomic capture /* { dg-bogus "value computed is not used" } */ + { r = *p; (*p)++; } + return r; +} + +int +f2 (int *p) +{ + int s + = ({ int r; + #pragma omp atomic capture /* { dg-bogus "value computed is not used" } */ + { r = *p; (*p)++; } + r; }); + return s; +}