public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/102291] New: dubious overflow warning
@ 2021-09-11 15:43 hv at crypt dot org
  2021-09-11 19:33 ` [Bug c/102291] [9/10/11/12 Regression] wrong overflow warning for compound expression conversion and bit_and expressions pinskia at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: hv at crypt dot org @ 2021-09-11 15:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102291

            Bug ID: 102291
           Summary: dubious overflow warning
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hv at crypt dot org
  Target Milestone: ---

The following code warns with gcc-11.2.0 (but not with 9.2.1-17ubuntu1~18.04.1)
in testera(), but not in testerb() which differs only by the removal of an
assert. I don't understand this, and cannot see what is overflowing.

This is reduced from a report against the UTF8_ACCUMULATE macro in perl source.
This build of gcc was configured as follows (including the error in prefix):
  ../gcc/configure --prefix=/opt/gcc-12 --disable-gcov --disable-multilib
--enable-languages=c --disable-nls --disable-decimal-float


% uname -a
Linux zen2 5.4.0-73-generic #82~18.04.1-Ubuntu SMP Fri Apr 16 15:10:02 UTC 2021
x86_64 x86_64 x86_64 GNU/Linux

% gcc --version | head -1
gcc (GCC) 11.2.0

% cat test.c
/* #include <assert.h> */
extern void __assert_fail (const char *__assertion, const char *__file,
      unsigned int __line, const char *__function)
    __attribute__ ((__nothrow__ , __leaf__))
            __attribute__ ((__noreturn__));
#define assert(expr)                          \
  ((void) sizeof ((expr) ? 1 : 0), __extension__ ({         \
      if (expr)                             \
        ; /* empty */                           \
      else                              \
        __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION);   \
    }))
#define __ASSERT_FUNCTION    __extension__ __PRETTY_FUNCTION__
/* end assert.h */

typedef unsigned long ulong;
typedef unsigned char uchar;

#define FIT8(c) assert(((sizeof(c) == 1) || (((ulong) (c)) >> 8) == 0))
#define BE8a(c) (FIT8(c), ((uchar) (c)))
#define BE8b(c) (         ((uchar) (c)))
#define NUM(c) ((c) | 0)

#define TESTER(old, new) ((((ulong)(old)) << 6) | (((uchar) NUM(new)) & 0x3f))

ulong testera(ulong ul) {
    return TESTER(ul, BE8a(0x80));
}

ulong testerb(ulong ul) {
    return TESTER(ul, BE8b(0x80));
}

% gcc -c test.c 
test.c: In function 'testera':
test.c:24:49: warning: overflow in conversion from 'int' to 'long unsigned int'
changes value from '((((void)4, (({...}))), 128)) & 63' to '0' [-Woverflow]
   24 | #define TESTERa(old, new) ((((ulong)(old)) << 6) | (((uchar) NUM(new))
& 0x3f))
      |                                                  ^
test.c:27:12: note: in expansion of macro 'TESTERa'
   27 |     return TESTERa(ul, BE8a(0x80));
      |            ^~~~~~~
%

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-07-07 10:40 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-11 15:43 [Bug c/102291] New: dubious overflow warning hv at crypt dot org
2021-09-11 19:33 ` [Bug c/102291] [9/10/11/12 Regression] wrong overflow warning for compound expression conversion and bit_and expressions pinskia at gcc dot gnu.org
2021-09-11 19:33 ` pinskia at gcc dot gnu.org
2021-09-11 19:36 ` pinskia at gcc dot gnu.org
2021-12-06 12:46 ` jakub at gcc dot gnu.org
2021-12-06 14:07 ` jakub at gcc dot gnu.org
2021-12-06 16:03 ` jakub at gcc dot gnu.org
2021-12-06 16:09 ` jakub at gcc dot gnu.org
2021-12-06 22:44 ` joseph at codesourcery dot com
2022-01-20 10:02 ` rguenth at gcc dot gnu.org
2022-05-27  9:46 ` [Bug c/102291] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:46 ` jakub at gcc dot gnu.org
2023-07-07 10:40 ` [Bug c/102291] [11/12/13/14 " rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).