From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12937 invoked by alias); 12 Dec 2010 10:20:11 -0000 Received: (qmail 12928 invoked by uid 22791); 12 Dec 2010 10:20:10 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 12 Dec 2010 10:20:06 +0000 From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/46899] compiler optimization X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: minor X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Status Resolution Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Sun, 12 Dec 2010 10:20:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-12/txt/msg01258.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46899 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |INVALID --- Comment #4 from Andrew Pinski 2010-12-12 10:20:03 UTC --- >Sorry it underflows. No, conversion does not have any overflow/underflow in it. >void my_func(unsigned short a, unsigned short c) >{ > unsigned int b; > > b = a * c; There is no overflow here since this unsigned integers wrap and don't overflow. > Yes, but the doesn't the C spec define the overflow as undefined, rather > then the entire program? No it is a runtime undefined behavior rather than the result being undefined. > rather that gcc makes assumptions about this behavior that _can_ turn out to > be not true. But assumptions? Since it is undefined behavior, it does not matter because GCC can make different assumptions in when it feels like. Unless you can give a testcase that does not depend on undefined behavior, it is hard to prove GCC is doing something wrong. -fwrapv can be used to define signed integer overflow as wrapping. See http://gcc.gnu.org/onlinedocs/gcc-4.5.1/gcc/Integers-implementation.html for how the conversion is implementation defined behavior: > # The result of, or the signal raised by, converting an integer to a signed > integer type when the value cannot be represented in an object of that type > (C90 6.2.1.2, C99 6.3.1.3). > For conversion to a type of width N, the value is reduced modulo 2^N to be > within range of the type; no signal is raised. Conversions are never causes an overflow rather it causes an implementation defined behavior in some cases.