Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: -fstrict-overflow and -Wstrict-overflow



(2012/10/13 3:29), SAITOH Masanobu wrote:
> (2012/10/13 3:13), Alan Barrett wrote:
>> On Fri, 12 Oct 2012, Masanobu SAITOH wrote:
>>> One of (serious) problem that we can't use -Wstrict-overflow by default
>>> is that gcc sometimes misundestand it :-<
>>>
>>> How should we use it?
>>
>> Do you have an example where gcc does the wrong thing with 
>> -Wstrict-overflow?  (The example in your message, which I am not quoting 
>> here, showed gcc doing the right thing: that is, drawing attention to a case 
>> where the program invoked undefined behaviour.)
> 
>  One of example is src/lib/libm/src/e_jn.c
> 
>> five(msaitoh)% env USETOOLS=no make e_jn.o
>> #   compile  libm/e_jn.o
>> gcc -O2 -Wstrict-overflow -std=gnu99  -Wall -Wstrict-prototypes 
>> -Wmissing-prototypes -Wpointer-arith -Wno-sign-compare  -Wno-traditional  
>> -Wa,--fatal-warnings -Wreturn-type -Wswitch -Wshadow -Wcast-qual 
>> -Wwrite-strings -Wextra -Wno-unused-parameter -Wno-sign-compare 
>> -Wold-style-definition -Wsign-compare -Wformat=2   -Wno-format-zero-length  
>> -Werror   -fno-strict-aliasing  -D_MULTI_LIBM -D_POSIX_MODE -DLIBM_SCCS 
>> -I/disk/sources/4NetBSD-current/src/lib/libm/gen  -c    
>> /disk/sources/4NetBSD-current/src/lib/libm/src/e_jn.c -o e_jn.o
>> cc1: warnings being treated as errors
>> /disk/sources/4NetBSD-current/src/lib/libm/src/e_jn.c: In function 
>> '__ieee754_jn':
>> /disk/sources/4NetBSD-current/src/lib/libm/src/e_jn.c:75:4: error: assuming 
>> signed overflow does not occur when simplifying conditional to constant
>> /disk/sources/4NetBSD-current/src/lib/libm/src/e_jn.c:107:10: error: 
>> assuming signed overflow does not occur when simplifying conditional to 
>> constant
>> /disk/sources/4NetBSD-current/src/lib/libm/src/e_jn.c:184:11: error: 
>> assuming signed overflow does not occur when simplifying conditional to 
>> constant
>> /disk/sources/4NetBSD-current/src/lib/libm/src/e_jn.c:192:11: error: 
>> assuming signed overflow does not occur when simplifying conditional to 
>> constant
>> /disk/sources/4NetBSD-current/src/lib/libm/src/e_jn.c: In function 
>> '__ieee754_yn':
>> /disk/sources/4NetBSD-current/src/lib/libm/src/e_jn.c:236:4: error: assuming 
>> signed overflow does not occur when simplifying conditional to constant
>> /disk/sources/4NetBSD-current/src/lib/libm/src/e_jn.c:266:6: error: assuming 
>> signed overflow does not occur when simplifying conditional to constant
>> *** Error code 1
>>
>> Stop.
> 
>  I have not confident that e_jn.c has no bug though...

 I remembered that one of other example was src/lib/libc/nls/catopen.c

> cc1: warnings being treated as errors
> /disk/sources/4NetBSD-current/src/lib/libc/nls/catopen.c: In function 
> '_catopen':
> /disk/sources/4NetBSD-current/src/lib/libc/nls/catopen.c:127:9: error: 
> assuming pointer wraparound does not occur when comparing P +- C1 with P +- C2
> /disk/sources/4NetBSD-current/src/lib/libc/nls/catopen.c:131:8: error: 
> assuming pointer wraparound does not occur when comparing P +- C1 with P +- C2
> /disk/sources/4NetBSD-current/src/lib/libc/nls/catopen.c:119:16: error: 
> assuming pointer wraparound does not occur when comparing P +- C1 with P +- C2
> /disk/sources/4NetBSD-current/src/lib/libc/nls/catopen.c:114:16: error: 
> assuming pointer wraparound does not occur when comparing P +- C1 with P +- C2
> *** Error code 1
> 
> Stop.


The code is as follows:
>         s = nlspath;
>         t = tmppath;
>         do {
>                 while (*s && *s != ':') {
>                         if (*s == '%') {
>                                 switch (*(++s)) {
>                                 case 'L':       /* locale */
>                                         u = reallang;
>                                         while (*u && t < tmppath + PATH_MAX)
>                                                 *t++ = *u++;
>                                         break;
>                                 case 'N':       /* name */
>                                         u = name;
>                                         while (*u && t < tmppath + PATH_MAX)
>                                                 *t++ = *u++;
>                                         break;
>                                 case 'l':       /* lang */
>                                 case 't':       /* territory */
>                                 case 'c':       /* codeset */
>                                         break;
>                                 default:
>                                         if (t < tmppath + PATH_MAX) <=== line 
> 127
>                                                 *t++ = *s;
>                                 }
>                         } else {
>                                 if (t < tmppath + PATH_MAX)
>                                         *t++ = *s;
>                         }
>                         s++;
>                 }
> 
>                 *t = '\0';
>                 catd = load_msgcat(tmppath);
>                 if (catd != (nl_catd)-1)
>                         return catd;
> 
>                 if (*s)
>                         s++;
>                 t = tmppath;
>         } while (*s);

I think gcc misundersand about line 127.

-- 
-----------------------------------------------
                SAITOH Masanobu (msaitoh%execsw.org@localhost
                                 msaitoh%netbsd.org@localhost)


Home | Main Index | Thread Index | Old Index