This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/16202] New: The -Wsequence-point warnng misses many important instances
- From: "trt at acm dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 25 Jun 2004 18:24:47 -0000
- Subject: [Bug c/16202] New: The -Wsequence-point warnng misses many important instances
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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