public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/16202] New: The -Wsequence-point warnng misses many important instances
@ 2004-06-25 18:25 trt at acm dot org
  2004-06-25 21:02 ` [Bug c/16202] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: trt at acm dot org @ 2004-06-25 18:25 UTC (permalink / raw)
  To: gcc-bugs

The current -Wsequence-point handles only simple variables,
so it misses the three bugs in this test program:

    struct s { struct s *nxt; int v; } q;
     
    int x[10];
     
    void foo(int **p)
    {
       (*p) = (*p)++;
       x[3] = x[3]++;
       q.nxt->nxt->v = q.nxt->nxt->v++;
    }

With an obvious tweak to c-common.c (below), they will be caught:

    opundef.c:7: warning: operation on '*p' may be undefined
    opundef.c:8: warning: operation on 'x[3]' may be undefined
    opundef.c:9: warning: operation on 'q.nxt->nxt->v' may be undefined

I added this to gcc after it failed to catch a nasty bug,
and then it found a dozen more latent ones (in a 35Mloc source code base).

This patch to c-common.c assumes that warning ("....%E ...") works,
but unfortunately it does not.  See bugzilla # 16119

*** c-common.c.orig     Sat Jun 19 15:34:18 2004
--- c-common.c  Mon Jun 21 13:53:05 2004
***************
*** 1246,1247 ****
--- 1246,1248 ----
  static int warning_candidate_p (tree);
+ static int candidate_equal_p (tree, tree);
  static void warn_for_collisions (struct tlist *);
***************
*** 1274,1276 ****
        add->next = *to;
!       if (! exclude_writer || add->writer != exclude_writer)
        *to = copy ? new_tlist (*to, add->expr, add->writer) : add;
--- 1275,1277 ----
        add->next = *to;
!       if (! exclude_writer || ! candidate_equal_p (add->writer, exclude_writer))
        *to = copy ? new_tlist (*to, add->expr, add->writer) : add;
***************
*** 1301,1303 ****
        for (tmp2 = *to; tmp2; tmp2 = tmp2->next)
!       if (tmp2->expr == add->expr)
          {
--- 1302,1304 ----
        for (tmp2 = *to; tmp2; tmp2 = tmp2->next)
!       if (candidate_equal_p (tmp2->expr, add->expr))
          {
***************
*** 1329,1331 ****
    for (tmp = warned_ids; tmp; tmp = tmp->next)
!     if (tmp->expr == written)
        return;
--- 1330,1332 ----
    for (tmp = warned_ids; tmp; tmp = tmp->next)
!     if (candidate_equal_p (tmp->expr, written))
        return;
***************
*** 1334,1337 ****
      {
!       if (list->expr == written
!         && list->writer != writer
          && (! only_writes || list->writer))
--- 1335,1338 ----
      {
!       if (candidate_equal_p (list->expr, written)
!         && ! candidate_equal_p (list->writer, writer)
          && (! only_writes || list->writer))
***************
*** 1339,1342 ****
          warned_ids = new_tlist (warned_ids, written, NULL_TREE);
!         warning ("operation on `%s' may be undefined",
!                  IDENTIFIER_POINTER (DECL_NAME (list->expr)));
        }
--- 1340,1342 ----
          warned_ids = new_tlist (warned_ids, written, NULL_TREE);
!         warning ("operation on %qE may be undefined", written);
        }
***************
*** 1366,1368 ****
  {
!   return TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == PARM_DECL;
  }
--- 1366,1375 ----
  {
!   return lvalue_p (x);
! }
!
! /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
! static int
! candidate_equal_p (tree x, tree y)
! {
!   return (x == y) || (x && y && operand_equal_p (x, y, 0));
  }
***************
*** 1412,1417 ****
    if (warning_candidate_p (x))
!     {
!       *pno_sp = new_tlist (*pno_sp, x, writer);
!       return;
!     }
   
--- 1419,1421 ----
    if (warning_candidate_p (x))
!     *pno_sp = new_tlist (*pno_sp, x, writer);
   
***************
*** 1521,1523 ****
        for (t = save_expr_cache; t; t = t->next)
!         if (t->expr == x)
            break;
--- 1525,1527 ----
        for (t = save_expr_cache; t; t = t->next)
!         if (candidate_equal_p (t->expr, x))
            break;

-- 
           Summary: The -Wsequence-point warnng misses many important
                    instances
           Product: gcc
           Version: 3.5.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=16202


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

* [Bug c/16202] The -Wsequence-point warnng misses many important instances
  2004-06-25 18:25 [Bug c/16202] New: The -Wsequence-point warnng misses many important instances trt at acm dot org
@ 2004-06-25 21:02 ` pinskia at gcc dot gnu dot org
  2004-09-25 16:48 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-25 21:02 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-06-25 21:01 -------
Confirmed, Patches goto gcc-patches@.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rth at gcc dot gnu dot org
  BugsThisDependsOn|                            |16119
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2004-06-25 21:01:27
               date|                            |


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


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

* [Bug c/16202] The -Wsequence-point warnng misses many important instances
  2004-06-25 18:25 [Bug c/16202] New: The -Wsequence-point warnng misses many important instances trt at acm dot org
  2004-06-25 21:02 ` [Bug c/16202] " pinskia at gcc dot gnu dot org
@ 2004-09-25 16:48 ` pinskia at gcc dot gnu dot org
  2004-10-03  2:59 ` gdr at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-25 16:48 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
   Last reconfirmed|2004-06-25 21:01:27         |2004-09-25 16:48:14
               date|                            |


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


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

* [Bug c/16202] The -Wsequence-point warnng misses many important instances
  2004-06-25 18:25 [Bug c/16202] New: The -Wsequence-point warnng misses many important instances trt at acm dot org
  2004-06-25 21:02 ` [Bug c/16202] " pinskia at gcc dot gnu dot org
  2004-09-25 16:48 ` pinskia at gcc dot gnu dot org
@ 2004-10-03  2:59 ` gdr at gcc dot gnu dot org
  2004-10-03  3:02 ` gdr at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: gdr at gcc dot gnu dot org @ 2004-10-03  2:59 UTC (permalink / raw)
  To: gcc-bugs



-- 
Bug 16202 depends on bug 16119, which changed state.

Bug 16119 Summary: In C language diagnostic messages, %E should but cannot display general expressions
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16119

           What    |Old Value                   |New Value
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

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


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

* [Bug c/16202] The -Wsequence-point warnng misses many important instances
  2004-06-25 18:25 [Bug c/16202] New: The -Wsequence-point warnng misses many important instances trt at acm dot org
                   ` (2 preceding siblings ...)
  2004-10-03  2:59 ` gdr at gcc dot gnu dot org
@ 2004-10-03  3:02 ` gdr at gcc dot gnu dot org
  2004-10-04 12:07 ` giovannibajo at libero dot it
  2004-10-04 12:44 ` jsm at polyomino dot org dot uk
  5 siblings, 0 replies; 7+ messages in thread
From: gdr at gcc dot gnu dot org @ 2004-10-03  3:02 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From gdr at gcc dot gnu dot org  2004-10-03 03:02 -------
silly bugzilla.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|16119                       |


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


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

* [Bug c/16202] The -Wsequence-point warnng misses many important instances
  2004-06-25 18:25 [Bug c/16202] New: The -Wsequence-point warnng misses many important instances trt at acm dot org
                   ` (3 preceding siblings ...)
  2004-10-03  3:02 ` gdr at gcc dot gnu dot org
@ 2004-10-04 12:07 ` giovannibajo at libero dot it
  2004-10-04 12:44 ` jsm at polyomino dot org dot uk
  5 siblings, 0 replies; 7+ messages in thread
From: giovannibajo at libero dot it @ 2004-10-04 12:07 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2004-10-04 12:07 -------
JSM, can you have a look at this patch? It is said to be fully functional 
already, so it would be a shame if it did not make it into 4.0 just for lack of 
attention.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |giovannibajo at libero dot
                   |                            |it, jsm28 at gcc dot gnu dot
                   |                            |org


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


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

* [Bug c/16202] The -Wsequence-point warnng misses many important instances
  2004-06-25 18:25 [Bug c/16202] New: The -Wsequence-point warnng misses many important instances trt at acm dot org
                   ` (4 preceding siblings ...)
  2004-10-04 12:07 ` giovannibajo at libero dot it
@ 2004-10-04 12:44 ` jsm at polyomino dot org dot uk
  5 siblings, 0 replies; 7+ messages in thread
From: jsm at polyomino dot org dot uk @ 2004-10-04 12:44 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jsm at polyomino dot org dot uk  2004-10-04 12:44 -------
Subject: Re:  The -Wsequence-point warnng misses many important
 instances

On Mon, 4 Oct 2004, giovannibajo at libero dot it wrote:

> JSM, can you have a look at this patch? It is said to be fully 
> functional already, so it would be a shame if it did not make it into 
> 4.0 just for lack of attention.

I don't see either a testcase or a patch to the existing 
gcc.dg/sequence-pt-1.c to remove XFAILs in this patch.  A complete 
submission including tests should be sent to gcc-patches.



-- 


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


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

end of thread, other threads:[~2004-10-04 12:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-25 18:25 [Bug c/16202] New: The -Wsequence-point warnng misses many important instances trt at acm dot org
2004-06-25 21:02 ` [Bug c/16202] " pinskia at gcc dot gnu dot org
2004-09-25 16:48 ` pinskia at gcc dot gnu dot org
2004-10-03  2:59 ` gdr at gcc dot gnu dot org
2004-10-03  3:02 ` gdr at gcc dot gnu dot org
2004-10-04 12:07 ` giovannibajo at libero dot it
2004-10-04 12:44 ` jsm at polyomino dot org dot uk

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).