Bug 98029 - [11 Regression] volatile triggers incorrect "warning: right-hand operand of comma expression has no effect [-Wunused-value]" since r11-5188-g32934a4f45a72144
Summary: [11 Regression] volatile triggers incorrect "warning: right-hand operand of c...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: 11.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2020-11-27 12:09 UTC by Vincent Lefèvre
Modified: 2021-01-04 21:55 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-11-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vincent Lefèvre 2020-11-27 12:09:45 UTC
With gcc (Debian 20201125-2) 11.0.0 20201125 (experimental) [master revision a4d9837ee4b:97273aee415:b13dacdfb315675803982ad5a3098f7b55e6357a]

double f1 (void)
{
  double d;
  int i;

  for (d = 2.0, i = 0; i < 5; i++, d *= d)
    ;

  return d;
}

double f2 (void)
{
  volatile double d;
  int i;

  for (d = 2.0, i = 0; i < 5; i++, d *= d)
    ;

  return d;
}

yields the following incorrect warning when using "-Wunused-value":

tst.c: In function 'f2':
tst.c:17:10: warning: right-hand operand of comma expression has no effect [-Wunused-value]
   17 |   for (d = 2.0, i = 0; i < 5; i++, d *= d)
      |        ~~^~~~~

Note that one gets a warning only for f2. The only difference is the "volatile".

I found this when testing GNU MPFR (a similar code occurs in tests/tset_ld.c).
Comment 1 Martin Liška 2020-11-27 13:12:04 UTC
Confirmed, started with r11-5188-g32934a4f45a72144.
Comment 2 Martin Uecker 2020-11-28 22:26:46 UTC
It seems with the changes to lvalue conversion the code

volatile int x;
int i;
(x = 1, i = 2);

gets rewritten to

((x = 1, 1), i = 2)

and then build_compound_expr introduces the spurious warning.


There is a another possible related issue:

volatile int x;
(x, 0);

warns about

warning: variable ‘x’ set but not used
Comment 3 Martin Uecker 2020-12-22 23:49:37 UTC
It seems this does not happen anymore after fixing PR98047.
Comment 5 Martin Liška 2020-12-23 11:12:29 UTC
I can confirm that.
Comment 6 CVS Commits 2021-01-04 21:55:12 UTC
The master branch has been updated by Martin Uecker <uecker@gcc.gnu.org>:

https://gcc.gnu.org/g:a000eb5918e09d28838ef572f4eea924d32db09b

commit r11-6450-ga000eb5918e09d28838ef572f4eea924d32db09b
Author: Martin Uecker <muecker@gwdg.de>
Date:   Mon Jan 4 22:53:58 2021 +0100

    C: Add test for incorrect warning for assignment of certain volatile expressions fixed by commit 58a45ce [PR98029]
    
    2021-01-04  Martin Uecker  <muecker@gwdg.de>
    
    gcc/testsuite/
            PR c/98029
            * gcc.dg/pr98029.c: New test.