public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/23113] New: The -Wunused (value computed is not used) option missed an important case
@ 2005-07-28 17:27 trt at acm dot org
  2005-07-28 17:55 ` [Bug c/23113] " pinskia at gcc dot gnu dot org
                   ` (12 more replies)
  0 siblings, 13 replies; 15+ messages in thread
From: trt at acm dot org @ 2005-07-28 17:27 UTC (permalink / raw)
  To: gcc-bugs

The following program, compiled with gcc -Wunused, issues no warnings

  int foo (void);
   
  void
  bar (int *p)
  {
     *p++;  /* perhaps (*p)++ was intended? */
     foo () + foo ();
     foo () + foo (), foo ();
  }

(gcc 2.9.6 issues warnings for all three lines)
I have found *p++; to be a fairly common error.
When sizeof(*p) == 1 or (*p)++ is illegal this is usually a superfluous `*',
but otherwise it is quite often a real bug and so there should be a warning.

I don't care much about things like 3+foo(), but mention them
because of this inoperative comment in c-typeck.c

  /* With -Wunused, we should also warn if the left-hand operand does have
     side-effects, but computes a value which is not used.  For example, in
     `foo() + bar(), baz()' the result of the `+' operator is not used,
     so we should issue a warning.  */

It looks like this code in stmt.c needs yet more tweaking:

    maybe_warn:
      /* If this is an expression with side effects, don't warn.  */
      if (TREE_SIDE_EFFECTS (exp))
        return 0;

-- 
           Summary: The -Wunused (value computed is not used) option missed
                    an important case
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: trt at acm dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23113


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c/23113] The -Wunused (value computed is not used) option missed an important case
  2005-07-28 17:27 [Bug c/23113] New: The -Wunused (value computed is not used) option missed an important case trt at acm dot org
@ 2005-07-28 17:55 ` pinskia at gcc dot gnu dot org
  2005-07-28 22:46   ` Neil Booth
  2005-07-28 19:32 ` trt at acm dot org
                   ` (11 subsequent siblings)
  12 siblings, 1 reply; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-28 17:55 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-07-28 17:28 -------
foo() has side effects.
*p++ has the side effect of increasing p by 1.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23113


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c/23113] The -Wunused (value computed is not used) option missed an important case
  2005-07-28 17:27 [Bug c/23113] New: The -Wunused (value computed is not used) option missed an important case trt at acm dot org
  2005-07-28 17:55 ` [Bug c/23113] " pinskia at gcc dot gnu dot org
@ 2005-07-28 19:32 ` trt at acm dot org
  2005-07-28 22:48 ` neil at daikokuya dot co dot uk
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: trt at acm dot org @ 2005-07-28 19:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From trt at acm dot org  2005-07-28 19:27 -------
In what sense is this bug "invalid"?  The comment I noted in c-typeck.c does not
match the current implementation, so one or both of those must be incorrect.

Older versions of gcc issued a warning for "*p++;" and so should  newer
versions. Yes it has a side-effect of increasing p by sizeof(int), but that is
not a reason to suppress the warning, it is the reason that the warning should
be issued!

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23113


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Bug c/23113] The -Wunused (value computed is not used) option missed an important case
  2005-07-28 17:55 ` [Bug c/23113] " pinskia at gcc dot gnu dot org
@ 2005-07-28 22:46   ` Neil Booth
  0 siblings, 0 replies; 15+ messages in thread
From: Neil Booth @ 2005-07-28 22:46 UTC (permalink / raw)
  To: pinskia at gcc dot gnu dot org; +Cc: gcc-bugs

pinskia at gcc dot gnu dot org wrote:-

> 
> ------- Additional Comments From pinskia at gcc dot gnu dot org  2005-07-28 17:28 -------
> foo() has side effects.
> *p++ has the side effect of increasing p by 1.
> 
> -- 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>              Status|UNCONFIRMED                 |RESOLVED
>          Resolution|                            |INVALID

Um, did you read the PR Andrew?


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c/23113] The -Wunused (value computed is not used) option missed an important case
  2005-07-28 17:27 [Bug c/23113] New: The -Wunused (value computed is not used) option missed an important case trt at acm dot org
  2005-07-28 17:55 ` [Bug c/23113] " pinskia at gcc dot gnu dot org
  2005-07-28 19:32 ` trt at acm dot org
@ 2005-07-28 22:48 ` neil at daikokuya dot co dot uk
  2005-07-28 23:44 ` bangerth at dealii dot org
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: neil at daikokuya dot co dot uk @ 2005-07-28 22:48 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From neil at daikokuya dot co dot uk  2005-07-28 22:46 -------
Subject: Re:  The -Wunused (value computed is not used) option missed an important case

pinskia at gcc dot gnu dot org wrote:-

> 
> ------- Additional Comments From pinskia at gcc dot gnu dot org  2005-07-28 17:28 -------
> foo() has side effects.
> *p++ has the side effect of increasing p by 1.
> 
> -- 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>              Status|UNCONFIRMED                 |RESOLVED
>          Resolution|                            |INVALID

Um, did you read the PR Andrew?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23113


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c/23113] The -Wunused (value computed is not used) option missed an important case
  2005-07-28 17:27 [Bug c/23113] New: The -Wunused (value computed is not used) option missed an important case trt at acm dot org
                   ` (2 preceding siblings ...)
  2005-07-28 22:48 ` neil at daikokuya dot co dot uk
@ 2005-07-28 23:44 ` bangerth at dealii dot org
  2005-07-29  0:14 ` [Bug c/23113] [3.4/4.0/4.1 regression] " bangerth at dealii dot org
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: bangerth at dealii dot org @ 2005-07-28 23:44 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2005-07-28 23:42 -------
Confirmed. These are all regressions. 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23113


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c/23113] [3.4/4.0/4.1 regression] The -Wunused (value computed is not used) option missed an important case
  2005-07-28 17:27 [Bug c/23113] New: The -Wunused (value computed is not used) option missed an important case trt at acm dot org
                   ` (3 preceding siblings ...)
  2005-07-28 23:44 ` bangerth at dealii dot org
@ 2005-07-29  0:14 ` bangerth at dealii dot org
  2005-07-29  5:58 ` pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: bangerth at dealii dot org @ 2005-07-29  0:14 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |diagnostic
      Known to fail|                            |3.3 4.0.0 4.1.0 3.2.3 3.4.5
      Known to work|                            |2.95
   Last reconfirmed|0000-00-00 00:00:00         |2005-07-28 23:44:16
               date|                            |
            Summary|The -Wunused (value computed|[3.4/4.0/4.1 regression] The
                   |is not used) option missed  |-Wunused (value computed is
                   |an important case           |not used) option missed an
                   |                            |important case
   Target Milestone|---                         |4.0.2


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23113


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c/23113] [3.4/4.0/4.1 regression] The -Wunused (value computed is not used) option missed an important case
  2005-07-28 17:27 [Bug c/23113] New: The -Wunused (value computed is not used) option missed an important case trt at acm dot org
                   ` (4 preceding siblings ...)
  2005-07-29  0:14 ` [Bug c/23113] [3.4/4.0/4.1 regression] " bangerth at dealii dot org
@ 2005-07-29  5:58 ` pinskia at gcc dot gnu dot org
  2005-08-01  0:44 ` jsm28 at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-29  5:58 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |minor


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23113


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c/23113] [3.4/4.0/4.1 regression] The -Wunused (value computed is not used) option missed an important case
  2005-07-28 17:27 [Bug c/23113] New: The -Wunused (value computed is not used) option missed an important case trt at acm dot org
                   ` (5 preceding siblings ...)
  2005-07-29  5:58 ` pinskia at gcc dot gnu dot org
@ 2005-08-01  0:44 ` jsm28 at gcc dot gnu dot org
  2005-08-01 16:48 ` trt at acm dot org
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2005-08-01  0:44 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jsm28 at gcc dot gnu dot org  2005-08-01 00:44 -------
Working on a fix.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jsm28 at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2005-07-28 23:44:16         |2005-08-01 00:44:01
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23113


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c/23113] [3.4/4.0/4.1 regression] The -Wunused (value computed is not used) option missed an important case
  2005-07-28 17:27 [Bug c/23113] New: The -Wunused (value computed is not used) option missed an important case trt at acm dot org
                   ` (6 preceding siblings ...)
  2005-08-01  0:44 ` jsm28 at gcc dot gnu dot org
@ 2005-08-01 16:48 ` trt at acm dot org
  2005-08-02  6:14 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: trt at acm dot org @ 2005-08-01 16:48 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From trt at acm dot org  2005-08-01 16:48 -------
Thanks!  I did a grep of the gcc sources:

  find . -name '*.c' -print | xargs grep '^[      ]*\*[a-zA-Z_]*++;'

and found 3 harmless cases of *p++ (* superfluous, sizeof(*p)==1), but also:

   ./libobjc/gc.c:      *current++;

I'm fairly sure that (*current)++; was intended.
I'm not familiar with objective C, does it share warning messages with C?

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23113


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c/23113] [3.4/4.0/4.1 regression] The -Wunused (value computed is not used) option missed an important case
  2005-07-28 17:27 [Bug c/23113] New: The -Wunused (value computed is not used) option missed an important case trt at acm dot org
                   ` (7 preceding siblings ...)
  2005-08-01 16:48 ` trt at acm dot org
@ 2005-08-02  6:14 ` pinskia at gcc dot gnu dot org
  2005-08-02  6:26 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-08-02  6:14 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-08-02 06:14 -------
*** Bug 23193 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |phython at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23113


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c/23113] [3.4/4.0/4.1 regression] The -Wunused (value computed is not used) option missed an important case
  2005-07-28 17:27 [Bug c/23113] New: The -Wunused (value computed is not used) option missed an important case trt at acm dot org
                   ` (8 preceding siblings ...)
  2005-08-02  6:14 ` pinskia at gcc dot gnu dot org
@ 2005-08-02  6:26 ` pinskia at gcc dot gnu dot org
  2005-08-03  2:21 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-08-02  6:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-08-02 06:25 -------
(In reply to comment #6)
> I'm not familiar with objective C, does it share warning messages with C?
Yes but this is in C code, the problem with that code is that well it is not turned on by default and I 
have not time to work on the GC in libobjc that much.  I think it should be what you recommended but I 
still have to look into it (as libobjc maintainer).

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23113


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c/23113] [3.4/4.0/4.1 regression] The -Wunused (value computed is not used) option missed an important case
  2005-07-28 17:27 [Bug c/23113] New: The -Wunused (value computed is not used) option missed an important case trt at acm dot org
                   ` (9 preceding siblings ...)
  2005-08-02  6:26 ` pinskia at gcc dot gnu dot org
@ 2005-08-03  2:21 ` pinskia at gcc dot gnu dot org
  2005-08-06 11:32 ` cvs-commit at gcc dot gnu dot org
  2005-08-06 13:35 ` pinskia at gcc dot gnu dot org
  12 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-08-03  2:21 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-08-03 02:21 -------
This is related to the C++ PR 11224 which had the same issue but has already been fixed in 4.0.0.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23113


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c/23113] [3.4/4.0/4.1 regression] The -Wunused (value computed is not used) option missed an important case
  2005-07-28 17:27 [Bug c/23113] New: The -Wunused (value computed is not used) option missed an important case trt at acm dot org
                   ` (10 preceding siblings ...)
  2005-08-03  2:21 ` pinskia at gcc dot gnu dot org
@ 2005-08-06 11:32 ` cvs-commit at gcc dot gnu dot org
  2005-08-06 13:35 ` pinskia at gcc dot gnu dot org
  12 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-08-06 11:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-08-06 11:32 -------
Subject: Bug 23113

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jsm28@gcc.gnu.org	2005-08-06 11:31:49

Modified files:
	gcc            : ChangeLog c-typeck.c stmt.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: Wunused-value-1.c 

Log message:
	PR c/23113
	* stmt.c (warn_if_unused_value): Check TREE_NO_WARNING at start.
	Don't handle NOP_EXPR, CONVERT_EXPR and NON_LVALUE_EXPR
	specially.  Check for side effects only for COND_EXPR.
	* c-typeck.c (c_finish_stmt_expr): Mark statement expression
	return with TREE_NO_WARNING.
	
	testsuite:
	* gcc.dg/Wunused-value-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.9667&r2=2.9668
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&r1=1.473&r2=1.474
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/stmt.c.diff?cvsroot=gcc&r1=1.425&r2=1.426
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5886&r2=1.5887
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/Wunused-value-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23113


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c/23113] [3.4/4.0/4.1 regression] The -Wunused (value computed is not used) option missed an important case
  2005-07-28 17:27 [Bug c/23113] New: The -Wunused (value computed is not used) option missed an important case trt at acm dot org
                   ` (11 preceding siblings ...)
  2005-08-06 11:32 ` cvs-commit at gcc dot gnu dot org
@ 2005-08-06 13:35 ` pinskia at gcc dot gnu dot org
  12 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-08-06 13:35 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-08-06 13:35 -------
Fixed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|4.0.2                       |4.1.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23113


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2005-08-06 13:35 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-28 17:27 [Bug c/23113] New: The -Wunused (value computed is not used) option missed an important case trt at acm dot org
2005-07-28 17:55 ` [Bug c/23113] " pinskia at gcc dot gnu dot org
2005-07-28 22:46   ` Neil Booth
2005-07-28 19:32 ` trt at acm dot org
2005-07-28 22:48 ` neil at daikokuya dot co dot uk
2005-07-28 23:44 ` bangerth at dealii dot org
2005-07-29  0:14 ` [Bug c/23113] [3.4/4.0/4.1 regression] " bangerth at dealii dot org
2005-07-29  5:58 ` pinskia at gcc dot gnu dot org
2005-08-01  0:44 ` jsm28 at gcc dot gnu dot org
2005-08-01 16:48 ` trt at acm dot org
2005-08-02  6:14 ` pinskia at gcc dot gnu dot org
2005-08-02  6:26 ` pinskia at gcc dot gnu dot org
2005-08-03  2:21 ` pinskia at gcc dot gnu dot org
2005-08-06 11:32 ` cvs-commit at gcc dot gnu dot org
2005-08-06 13:35 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).