public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "trt at acm dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/16202] New: The -Wsequence-point warnng misses many important instances
Date: Fri, 25 Jun 2004 18:25:00 -0000	[thread overview]
Message-ID: <20040625182443.16202.trt@acm.org> (raw)

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


             reply	other threads:[~2004-06-25 18:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-25 18:25 trt at acm dot org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040625182443.16202.trt@acm.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).