From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13650 invoked by alias); 24 Jul 2012 20:04:44 -0000 Received: (qmail 13639 invoked by uid 22791); 24 Jul 2012 20:04:42 -0000 X-SWARE-Spam-Status: No, hits=-8.0 required=5.0 tests=BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W X-Spam-Check-By: sourceware.org Received: from smail6.alcatel.fr (HELO smail6.alcatel.fr) (64.208.49.42) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 24 Jul 2012 20:04:22 +0000 Received: from FRMRSSXCHHUB02.dc-m.alcatel-lucent.com (FRMRSSXCHHUB02.dc-m.alcatel-lucent.com [135.120.45.62]) by smail6.alcatel.fr (8.14.3/8.14.3/ICT) with ESMTP id q6OK4JH8032750 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT); Tue, 24 Jul 2012 22:04:20 +0200 Received: from US70UWXCHHUB01.zam.alcatel-lucent.com (135.5.2.48) by FRMRSSXCHHUB02.dc-m.alcatel-lucent.com (135.120.45.62) with Microsoft SMTP Server (TLS) id 8.3.213.0; Tue, 24 Jul 2012 22:04:19 +0200 Received: from [135.244.0.117] (135.5.27.11) by US70UWXCHHUB01.zam.alcatel-lucent.com (135.5.2.48) with Microsoft SMTP Server (TLS) id 14.2.247.3; Tue, 24 Jul 2012 16:04:16 -0400 Message-ID: <500EFFBC.4000002@alcatel-lucent.com> Date: Tue, 24 Jul 2012 20:04:00 -0000 From: Jan Smets User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20120717 Thunderbird/15.0 MIME-Version: 1.0 To: =?ISO-8859-1?Q?=C1ngel_Gonz=E1lez?= CC: "gcc-help@gcc.gnu.org" Subject: Re: Wtype-limits and functional range checks References: <500D28F9.8050000@alcatel-lucent.com> <500D924C.4020904@gmail.com> In-Reply-To: <500D924C.4020904@gmail.com> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 8bit X-IsSubscribed: yes 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 X-SW-Source: 2012-07/txt/msg00171.txt.bz2 On 23/07/2012 20:05, Ángel González wrote: > On 23/07/12 12:35, Jan Smets wrote: >> Can anyone help me hacking this in or at least give me some hints how >> to do this. >> (e.g, how do I know if value is used twice in the if()?) I had a >> look at c-family/c-common.c but I don't see how this can be done. >> >> Any help is appreciated. >> >> Thanks >> >> - Jan > I would > a) Replace all such usages with a macro like: CHECK_RANGE(value, > tSomeType_MIN, tSomeType_MAX) (or you could have a macro per type and > the min & max hardcoded on each one). This makes easy to change the > implementation later or even disable it depending on the compilation. > > b) Instead of doing the check, convert it to a call to an inline > function. If ((foo < min) || (foo > max)) will give the warning, but > if (check_range(foo, min, max)) won't, even if it's defined as: > static inline int check_range(int value, int min, int max) { > return (value < min) || (value > max); > } > and thus completely optimized inline [you can also mark it as > __attribute__((always_inline)) if you want to force it, it still won't > warn... yet]. > || I did consider these options. But they're not user friendly IMHO. I can surely tell 300 devs about this macro/inlined function. But how many will remember this after a month? A year ? The result is that people start avoiding MIN checks in their code and functionality gets broken. So I still prefer a way to disable this checking when there is a larger-than and less-than compare of the same variables in the same if() block. Where do I start? I don't expect people to do this for me, but I could use some pointers to get started. Thanks - Jan