From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23831 invoked by alias); 23 Sep 2013 19:38:13 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 23822 invoked by uid 89); 23 Sep 2013 19:38:12 -0000 Received: from na3sys009aog128.obsmtp.com (HELO na3sys009aog128.obsmtp.com) (74.125.149.141) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) SMTP; Mon, 23 Sep 2013 19:38:12 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,RDNS_NONE autolearn=no version=3.3.2 X-HELO: na3sys009aog128.obsmtp.com Received: from mail-oa0-f50.google.com ([209.85.219.50]) (using TLSv1) by na3sys009aob128.postini.com ([74.125.148.12]) with SMTP ID DSNKUkCYoQlsBw5DZqqEHSoz++MTbJ/nzkt1@postini.com; Mon, 23 Sep 2013 12:38:11 PDT Received: by mail-oa0-f50.google.com with SMTP id j1so1072469oag.9 for ; Mon, 23 Sep 2013 12:38:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=aCH8ZJuKMolKDldxrYgQ84T+Tgw5ik0AALibiz5cmek=; b=XQGRSwDxYtO2z3YVejojiYZGJ1CvVJBrO4cVziIZer32ubOtT2dt7/jrMgnJGLaJkc 4G815R5keqLuHbAahPYQytOEgUIE3KD2l6DVb13ichWSNiZQaOSTKzIWM4YR77v2ZQFX 8OKnrjpUo8z1dKSqu9YwtS/aGNoBvV9wyAHGEEEjzVu6ZjdgiPKyn7AI4xLYoSSj41E2 W8fslcTiaVcP6iWVwOisEn8N8aqkpSEJmOOGNCWPgNTEmy62IIHuufGrlBByPUsbWqCd foy9y0CEb9UFEifTGTxpXGRWSZlbjf74EurScEKNufCaImdpEMIRK+U1NAReUCJ9lHRd 18sw== X-Gm-Message-State: ALoCoQmaKsghcnus4l7OS/SzSAHPdzOZEcX8JDBhpJTiCbCzKGyrZmWdVxdP3QdjHv7aVMr9JuLQ MIME-Version: 1.0 X-Received: by 10.182.166.40 with SMTP id zd8mr21075466obb.25.1379965089443; Mon, 23 Sep 2013 12:38:09 -0700 (PDT) Received: by 10.182.210.77 with HTTP; Mon, 23 Sep 2013 12:38:09 -0700 (PDT) In-Reply-To: <20130923000355.fa2a964c.jklowden@schemamania.org> References: <20130921164609.GC3086@a.lan> <20130921174229.GD3086@a.lan> <20130923000355.fa2a964c.jklowden@schemamania.org> Date: Mon, 23 Sep 2013 19:38:00 -0000 Message-ID: Subject: Re: how to make gcc warn about arithmetic signed overflow From: Dave Allured - NOAA Affiliate To: gcc-help@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes X-SW-Source: 2013-09/txt/msg00159.txt.bz2 On Sun, Sep 22, 2013 at 10:03 PM, James K. Lowden wrote: > Regarding the OP's query > >> > int r = ab * bc; > > although the provided example is simple enough, it's the compiler's > job is to generate object code, not to do static analysis. > > Even if the values are const, in the general case they could be > modified by another module or another thread. The compiler simply > doesn't have enough information to warn of every runtime overflow. I believe the CPU overflow flag is updated after most integer arithmetic instructions. Does GCC have any facility for checking this flag after each integer operation? This would be a runtime check, of course, not a compile time check. --Dave