public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ada/102078] New: ffinity.c:59:19: error: Signed integer overflow ?
@ 2021-08-26 12:31 dcb314 at hotmail dot com
  2021-08-26 12:53 ` [Bug ada/102078] affinity.c:59:19: " marxin at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: dcb314 at hotmail dot com @ 2021-08-26 12:31 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102078
           Summary: ffinity.c:59:19: error: Signed integer overflow ?
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcb314 at hotmail dot com
  Target Milestone: ---

Source code is

  for (index = 0; index < sizeof (unsigned) * 8; index++)
    if (mask & (1 << index))
      CPUSET_SET(cpuset, index);

maybe better code:

  for (index = 0; index < sizeof (unsigned) * 8; index++)
    if (mask & (1UL << index))
      CPUSET_SET(cpuset, index);

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

* [Bug ada/102078] affinity.c:59:19: error: Signed integer overflow ?
  2021-08-26 12:31 [Bug ada/102078] New: ffinity.c:59:19: error: Signed integer overflow ? dcb314 at hotmail dot com
@ 2021-08-26 12:53 ` marxin at gcc dot gnu.org
  2021-08-30  7:21 ` marxin at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-08-26 12:53 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-08-26
             Status|UNCONFIRMED                 |NEW
                 CC|                            |marxin at gcc dot gnu.org
     Ever confirmed|0                           |1

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

* [Bug ada/102078] affinity.c:59:19: error: Signed integer overflow ?
  2021-08-26 12:31 [Bug ada/102078] New: ffinity.c:59:19: error: Signed integer overflow ? dcb314 at hotmail dot com
  2021-08-26 12:53 ` [Bug ada/102078] affinity.c:59:19: " marxin at gcc dot gnu.org
@ 2021-08-30  7:21 ` marxin at gcc dot gnu.org
  2021-08-30  7:31 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-08-30  7:21 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
@Jakub: Can you please take a look?

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

* [Bug ada/102078] affinity.c:59:19: error: Signed integer overflow ?
  2021-08-26 12:31 [Bug ada/102078] New: ffinity.c:59:19: error: Signed integer overflow ? dcb314 at hotmail dot com
  2021-08-26 12:53 ` [Bug ada/102078] affinity.c:59:19: " marxin at gcc dot gnu.org
  2021-08-30  7:21 ` marxin at gcc dot gnu.org
@ 2021-08-30  7:31 ` jakub at gcc dot gnu.org
  2021-08-30  7:35 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-08-30  7:31 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ebotcazou at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This is about gcc/ada/affinity.c, not about libgomp/affinity.c nor
libgomp/config/linux/affinity.c.
I don't see a need to change anything, while the file extension is .c, we are
compiling it with C++, and in C++ 1 << 31 is well defined in all versions I
believe.
1UL would be confusing when mask is unsigned, 1U << index might be ok.

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

* [Bug ada/102078] affinity.c:59:19: error: Signed integer overflow ?
  2021-08-26 12:31 [Bug ada/102078] New: ffinity.c:59:19: error: Signed integer overflow ? dcb314 at hotmail dot com
                   ` (2 preceding siblings ...)
  2021-08-30  7:31 ` jakub at gcc dot gnu.org
@ 2021-08-30  7:35 ` jakub at gcc dot gnu.org
  2021-08-30 16:27 ` dcb314 at hotmail dot com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-08-30  7:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Actually no, it is in libada and built only for VxWorks, maybe it is built with
C rather than C++.  In that case it would indeed be UB.

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

* [Bug ada/102078] affinity.c:59:19: error: Signed integer overflow ?
  2021-08-26 12:31 [Bug ada/102078] New: ffinity.c:59:19: error: Signed integer overflow ? dcb314 at hotmail dot com
                   ` (3 preceding siblings ...)
  2021-08-30  7:35 ` jakub at gcc dot gnu.org
@ 2021-08-30 16:27 ` dcb314 at hotmail dot com
  2021-08-30 16:35 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: dcb314 at hotmail dot com @ 2021-08-30 16:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from David Binderman <dcb314 at hotmail dot com> ---
Full cppcheck error message is

gcc/ada/affinity.c:59:19: error: Signed integer overflow for expression
'1<<index'. [integerOverflow]

I think cppcheck is worried if index runs up to 64, i.e. when sizeof( unsigned)
is 8, hence my suggestion.

AFAIK, 1 << 31 loses the sign bit and so cppcheck likes to grumble, but 
I've long since forgotten if it is actually UB or not.

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

* [Bug ada/102078] affinity.c:59:19: error: Signed integer overflow ?
  2021-08-26 12:31 [Bug ada/102078] New: ffinity.c:59:19: error: Signed integer overflow ? dcb314 at hotmail dot com
                   ` (4 preceding siblings ...)
  2021-08-30 16:27 ` dcb314 at hotmail dot com
@ 2021-08-30 16:35 ` jakub at gcc dot gnu.org
  2021-08-31  7:21 ` dcb314 at hotmail dot com
  2021-08-31  7:26 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-08-30 16:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
index doesn't go to 32, just to 31.
And whether 1 << 31 or -1 << 31 etc. is or isn't UB heavily depends on the
language and standard version, C++20 and later accepts both, C89 and C++98 were
fuzzy, 1 << 31 is well defined in C++11..17 but -1 << 31 is UB, and both are UB
in C99/11/17.
1 << 32 or 1 << -1 is UB in all language versions.

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

* [Bug ada/102078] affinity.c:59:19: error: Signed integer overflow ?
  2021-08-26 12:31 [Bug ada/102078] New: ffinity.c:59:19: error: Signed integer overflow ? dcb314 at hotmail dot com
                   ` (5 preceding siblings ...)
  2021-08-30 16:35 ` jakub at gcc dot gnu.org
@ 2021-08-31  7:21 ` dcb314 at hotmail dot com
  2021-08-31  7:26 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: dcb314 at hotmail dot com @ 2021-08-31  7:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from David Binderman <dcb314 at hotmail dot com> ---
(In reply to David Binderman from comment #4)
> Full cppcheck error message is
> 
> gcc/ada/affinity.c:59:19: error: Signed integer overflow for expression
> '1<<index'. [integerOverflow]
> 
> I think cppcheck is worried if index runs up to 64, i.e. when sizeof(
> unsigned)
> is 8, hence my suggestion.
> 
> AFAIK, 1 << 31 loses the sign bit and so cppcheck likes to grumble, but 
> I've long since forgotten if it is actually UB or not.

Changing the 1 to 1UL seems to shut up cppcheck, so it looks like a
32/64 bit issue.

I guess there are some machines where unsigned int is 64 bit.

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

* [Bug ada/102078] affinity.c:59:19: error: Signed integer overflow ?
  2021-08-26 12:31 [Bug ada/102078] New: ffinity.c:59:19: error: Signed integer overflow ? dcb314 at hotmail dot com
                   ` (6 preceding siblings ...)
  2021-08-31  7:21 ` dcb314 at hotmail dot com
@ 2021-08-31  7:26 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-08-31  7:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to David Binderman from comment #6)
> I guess there are some machines where unsigned int is 64 bit.

Even if there are (not aware of any such target), 1U << index would be enough
for that.  The code is non-portable only in hardcoding 8 as number of bits in a
byte.

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

end of thread, other threads:[~2021-08-31  7:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-26 12:31 [Bug ada/102078] New: ffinity.c:59:19: error: Signed integer overflow ? dcb314 at hotmail dot com
2021-08-26 12:53 ` [Bug ada/102078] affinity.c:59:19: " marxin at gcc dot gnu.org
2021-08-30  7:21 ` marxin at gcc dot gnu.org
2021-08-30  7:31 ` jakub at gcc dot gnu.org
2021-08-30  7:35 ` jakub at gcc dot gnu.org
2021-08-30 16:27 ` dcb314 at hotmail dot com
2021-08-30 16:35 ` jakub at gcc dot gnu.org
2021-08-31  7:21 ` dcb314 at hotmail dot com
2021-08-31  7:26 ` jakub 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).