From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24294 invoked by alias); 30 Jun 2004 19:33:08 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 24287 invoked by uid 48); 30 Jun 2004 19:33:07 -0000 Date: Wed, 30 Jun 2004 19:38:00 -0000 From: "trt at acm dot org" To: gcc-bugs@gcc.gnu.org Message-ID: <20040630193304.16302.trt@acm.org> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c/16302] New: gcc fails to warn about some common logic errors X-Bugzilla-Reason: CC X-SW-Source: 2004-06/txt/msg03968.txt.bz2 List-Id: A "gcc -Wextra -O" misses the 4 bugs in this test program: int main (int argc, char *argv[]) { if (argc != 1 || argc != 2) return 1; if (argc < 0 && argc > 10) return 1; if (argc || !argc) return 1; if (argc && !argc) return 1; return 0; } With a tweak to fold-const.c (below), they will be caught: t.c:4: warning: `or' of collectively exhaustive tests is always 1 t.c:5: warning: `and' of mutually exclusive tests is always 0 t.c:6: warning: `or' of collectively exhaustive tests is always 1 t.c:7: warning: `and' of mutually exclusive tests is always 0 A bootstrap of gcc-3.5-20040627 reports such a warning in fold-const.c itself, the patch below includes the obvious fix. ==== Comment: The -O is needed due to this code in fold-const.c: /* We only do these simplifications if we are optimizing. */ if (!optimize) return t; This is probably from when fold-const.c was much simpler, but I think is no longer appropriate and recommend it be deleted. ==== *** fold-const.c.orig Sun Jun 27 11:23:44 2004 --- fold-const.c Wed Jun 30 12:43:39 2004 *************** *** 4377,4379 **** in_p, low, high)))) ! return or_op ? invert_truthvalue (tem) : tem; --- 4377,4388 ---- in_p, low, high)))) ! { ! if (TREE_CODE (tem) == INTEGER_CST && extra_warnings) ! { ! if (or_op) ! warning ("`or' of collectively exhaustive tests is always 1"); ! else ! warning ("`and' of mutually exclusive tests is always 0"); ! } ! return or_op ? invert_truthvalue (tem) : tem; ! } *************** *** 9998,10000 **** || (TREE_CODE (op0) == REAL_CST ! && TREE_CODE (op0) != REAL_CST)) { --- 10007,10009 ---- || (TREE_CODE (op0) == REAL_CST ! && TREE_CODE (op1) != REAL_CST)) { -- Summary: gcc fails to warn about some common logic errors 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=16302