Bug 89796 - Incorrect warning generated with OpenMP atomic capture
Summary: Incorrect warning generated with OpenMP atomic capture
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.2.1
: P3 normal
Target Milestone: 7.5
Assignee: Jakub Jelinek
URL:
Keywords: diagnostic, openmp
Depends on:
Blocks:
 
Reported: 2019-03-22 15:58 UTC by Arsène Pérard-Gayot
Modified: 2019-08-30 13:34 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-03-25 00:00:00


Attachments
Sample code that reproduces the issue (312 bytes, text/x-csrc)
2019-03-22 15:58 UTC, Arsène Pérard-Gayot
Details
gcc9-pr89796.patch (852 bytes, patch)
2019-03-25 16:10 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Arsène Pérard-Gayot 2019-03-22 15:58:01 UTC
Created attachment 46012 [details]
Sample code that reproduces the issue

Hello,

I get the warning "warning: value computed is not used [-Wunused-value]" when compiling the attached code snippet with:

    g++ test.cpp -fopenmp -Wall -o test

This warning is incorrect, as the value referred to by the warning is in fact used. Moreover, the warning does not show up when OpenMP is disabled (by omitting -fopenmp from the command line).
Comment 1 Nicholas Krause 2019-03-24 15:47:19 UTC
I just compiled this like so:
./bin/g++ test.cpp -fopenmp -Wall -fconcepts -o name test2.cpp 
and got this on a build from yesterday:

g++: internal compiler error: Segmentation fault signal terminated program cc1plus
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.

This code is linked to another version of this https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88395 as it crashes before your warning issue. I posted to
the list here about a possible fix yesterday for it:

https://gcc.gnu.org/ml/gcc/2019-03/msg00185.html
Comment 2 Arsène Pérard-Gayot 2019-03-24 19:35:58 UTC
(In reply to Nicholas Krause from comment #1)
> I just compiled this like so:
> ./bin/g++ test.cpp -fopenmp -Wall -fconcepts -o name test2.cpp 
> and got this on a build from yesterday:
> 
> g++: internal compiler error: Segmentation fault signal terminated program
> cc1plus
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See <https://gcc.gnu.org/bugs/> for instructions.
> 
> This code is linked to another version of this
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88395 as it crashes before your
> warning issue. I posted to
> the list here about a possible fix yesterday for it:
> 
> https://gcc.gnu.org/ml/gcc/2019-03/msg00185.html

Could you please explain the connection with this bug? From what I see, what you are reporting here is unrelated to the warning issue, and the segmentation fault only occurs because of your use of the "-fconcepts" flag. Please correct me if I am wrong.
Comment 3 Nicholas Krause 2019-03-25 04:03:54 UTC
(In reply to Arsène Pérard-Gayot from comment #2)
> (In reply to Nicholas Krause from comment #1)
> > I just compiled this like so:
> > ./bin/g++ test.cpp -fopenmp -Wall -fconcepts -o name test2.cpp 
> > and got this on a build from yesterday:
> > 
> > g++: internal compiler error: Segmentation fault signal terminated program
> > cc1plus
> > Please submit a full bug report,
> > with preprocessed source if appropriate.
> > See <https://gcc.gnu.org/bugs/> for instructions.
> > 
> > This code is linked to another version of this
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88395 as it crashes before your
> > warning issue. I posted to
> > the list here about a possible fix yesterday for it:
> > 
> > https://gcc.gnu.org/ml/gcc/2019-03/msg00185.html
> 
> Could you please explain the connection with this bug? From what I see, what
> you are reporting here is unrelated to the warning issue, and the
> segmentation fault only occurs because of your use of the "-fconcepts" flag.
> Please correct me if I am wrong.

Yes that's correct. However the problem is that it needs to compile and you would get this:
test.cpp:2:5: error: ‘concept’ does not name a type
    2 |     concept bool Concept2 = requires (T t, U u)
      |     ^~~~~~~
test.cpp:2:5: note: ‘concept’ only available with ‘-fconcepts’
test.cpp:8:5: error: ‘concept’ does not name a type
    8 |     concept bool Concept = Concept2 <T, T>;
      |     ^~~~~~~
test.cpp:8:5: note: ‘concept’ only available with ‘-fconcepts’
test.cpp:12:19: error: ‘Concept’ has not been declared
   12 |         template <Concept T>
      |                   ^~~~~~~
test.cpp:13:35: error: ‘T’ was not declared in this scope
   13 |         constexpr S& operator += (T o);
      |                                   ^
test.cpp:13:38: error: declaration of ‘operator+=’ as non-function
   13 |         constexpr S& operator += (T o);
      |                                      ^
test.cpp: In function ‘constexpr S operator*(S, S)’:
test.cpp:17:18: error: no match for ‘operator+=’ (operand types are ‘S’ and ‘S’)
   17 |         return a += b;
      |                ~~^~~~
test2.cpp: In member function ‘void S::test(size_t&)’:
test2.cpp:21:21: warning: value computed is not used [-Wunused-value]
   21 |             #pragma omp atomic capture
      |                     ^~~
Therefore it must be build must and that bug fixed first before we take on this bug unless you can send me a example without concepts required and just openmp code.
Comment 4 Nicholas Krause 2019-03-25 05:33:33 UTC
(In reply to Nicholas Krause from comment #3)
> (In reply to Arsène Pérard-Gayot from comment #2)
> > (In reply to Nicholas Krause from comment #1)
> > > I just compiled this like so:
> > > ./bin/g++ test.cpp -fopenmp -Wall -fconcepts -o name test2.cpp 
> > > and got this on a build from yesterday:
> > > 
> > > g++: internal compiler error: Segmentation fault signal terminated program
> > > cc1plus
> > > Please submit a full bug report,
> > > with preprocessed source if appropriate.
> > > See <https://gcc.gnu.org/bugs/> for instructions.
> > > 
> > > This code is linked to another version of this
> > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88395 as it crashes before your
> > > warning issue. I posted to
> > > the list here about a possible fix yesterday for it:
> > > 
> > > https://gcc.gnu.org/ml/gcc/2019-03/msg00185.html
> > 
> > Could you please explain the connection with this bug? From what I see, what
> > you are reporting here is unrelated to the warning issue, and the
> > segmentation fault only occurs because of your use of the "-fconcepts" flag.
> > Please correct me if I am wrong.
> 
> Yes that's correct. However the problem is that it needs to compile and you
> would get this:
> test.cpp:2:5: error: ‘concept’ does not name a type
>     2 |     concept bool Concept2 = requires (T t, U u)
>       |     ^~~~~~~
> test.cpp:2:5: note: ‘concept’ only available with ‘-fconcepts’
> test.cpp:8:5: error: ‘concept’ does not name a type
>     8 |     concept bool Concept = Concept2 <T, T>;
>       |     ^~~~~~~
> test.cpp:8:5: note: ‘concept’ only available with ‘-fconcepts’
> test.cpp:12:19: error: ‘Concept’ has not been declared
>    12 |         template <Concept T>
>       |                   ^~~~~~~
> test.cpp:13:35: error: ‘T’ was not declared in this scope
>    13 |         constexpr S& operator += (T o);
>       |                                   ^
> test.cpp:13:38: error: declaration of ‘operator+=’ as non-function
>    13 |         constexpr S& operator += (T o);
>       |                                      ^
> test.cpp: In function ‘constexpr S operator*(S, S)’:
> test.cpp:17:18: error: no match for ‘operator+=’ (operand types are ‘S’ and
> ‘S’)
>    17 |         return a += b;
>       |                ~~^~~~
> test2.cpp: In member function ‘void S::test(size_t&)’:
> test2.cpp:21:21: warning: value computed is not used [-Wunused-value]
>    21 |             #pragma omp atomic capture
>       |                     ^~~
> Therefore it must be build must and that bug fixed first before we take on
> this bug unless you can send me a example without concepts required and just
> openmp code.

Sorry I was compiling a incorrect program your code is fine and this is now confirmed.
Comment 5 Jakub Jelinek 2019-03-25 16:10:39 UTC
Created attachment 46018 [details]
gcc9-pr89796.patch

Untested fix.

You could have used simpler
#pragma omp atomic capture
prev = c++;
that wouldn't warn (so, if you want a workaround, use that).
Comment 6 Arsène Pérard-Gayot 2019-03-25 17:15:27 UTC
(In reply to Jakub Jelinek from comment #5)
> Created attachment 46018 [details]
> gcc9-pr89796.patch
> 
> Untested fix.
> 
> You could have used simpler
> #pragma omp atomic capture
> prev = c++;
> that wouldn't warn (so, if you want a workaround, use that).

Thank you for the workaround. Sadly, I cannot apply it to my problem, because in my original code, the increment is not one. I need to do something like:

  #pragma omp atomic capture
  { prev = counter; counter += K; }
Comment 7 Jakub Jelinek 2019-03-26 07:54:33 UTC
Author: jakub
Date: Tue Mar 26 07:54:02 2019
New Revision: 269933

URL: https://gcc.gnu.org/viewcvs?rev=269933&root=gcc&view=rev
Log:
	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.

Added:
    trunk/gcc/testsuite/g++.dg/gomp/pr89796.C
    trunk/gcc/testsuite/gcc.dg/gomp/pr89796.c
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog
Comment 8 Jakub Jelinek 2019-04-30 20:54:48 UTC
Author: jakub
Date: Tue Apr 30 20:54:16 2019
New Revision: 270741

URL: https://gcc.gnu.org/viewcvs?rev=270741&root=gcc&view=rev
Log:
	Backported from mainline
	2019-03-26  Jakub Jelinek  <jakub@redhat.com>

	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.

Added:
    branches/gcc-8-branch/gcc/testsuite/g++.dg/gomp/pr89796.C
    branches/gcc-8-branch/gcc/testsuite/gcc.dg/gomp/pr89796.c
Modified:
    branches/gcc-8-branch/gcc/cp/ChangeLog
    branches/gcc-8-branch/gcc/cp/semantics.c
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
Comment 9 Jakub Jelinek 2019-05-01 07:15:52 UTC
Fixed for 9.1+ and 8.4+ so far.
Comment 10 Jakub Jelinek 2019-08-30 12:32:48 UTC
Author: jakub
Date: Fri Aug 30 12:32:15 2019
New Revision: 275142

URL: https://gcc.gnu.org/viewcvs?rev=275142&root=gcc&view=rev
Log:
	Backported from mainline
	2019-03-26  Jakub Jelinek  <jakub@redhat.com>

	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.

Added:
    branches/gcc-7-branch/gcc/testsuite/g++.dg/gomp/pr89796.C
    branches/gcc-7-branch/gcc/testsuite/gcc.dg/gomp/pr89796.c
Modified:
    branches/gcc-7-branch/gcc/cp/ChangeLog
    branches/gcc-7-branch/gcc/cp/semantics.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog
Comment 11 Jakub Jelinek 2019-08-30 13:34:40 UTC
Fixed.