Author Topic: Strange warning: Dword data exceeds bounds  (Read 7694 times)

Offline Serge

  • Jr. Member
  • *
  • Posts: 26
  • Country: ru
Strange warning: Dword data exceeds bounds
« on: July 23, 2011, 04:16:18 PM »
Compiled the following:
Code: [Select]
cpu 386
and eax, 1<<31
The result is OK.
Now compiled the following:
Code: [Select]
cpu 386
and eax, ~(1<<30)
The result is OK also.
Finally compiled the following:
Code: [Select]
cpu 386
and eax, ~(1<<31)
and received warning "dword data exceeds bounds".
I stuck upon this code for a long time being drawing the bit positions and shaking my head. All is OK, – the ~(1<<31) is the last bit cleared. The "~" operator is bitwise, so both initial data and the result are unsigned. All higher bits doesn't matter.
Please check that and remove that warning if no actual data loss.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2379
  • Country: us
Re: Strange warning: Dword data exceeds bounds
« Reply #1 on: July 23, 2011, 09:15:01 PM »
This is a legitimate bug. I've posted it to the bug-tracker. Thanks for the feedback!

Best,
Frank


Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2379
  • Country: us
Re: Strange warning: Dword data exceeds bounds
« Reply #2 on: July 23, 2011, 09:35:41 PM »
FYI, here's the feedback from the bug-tracker:

----------------------------------------------------------------------

> >Comment By: H. Peter Anvin (hpa)
Date: 2011-07-23 14:10

Message:
The right hand expression has the value of 0xFFFF_FFFF_7FFF_FFFF which is
correctly not either sign- or zero-extendable from the 32-bit truncated
value.  The issue here is the handling of - or ~ in these kinds of
expressions: they end up extending an expression theoretically "to
infinity", even though that is presumably not the intention of the
programmer.
----------------------------------------

I take this to mean: "Ignore the warning!"

Best,
Frank






Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2379
  • Country: us
Re: Strange warning: Dword data exceeds bounds
« Reply #3 on: July 23, 2011, 11:25:49 PM »
More feedback from the bug-tracker...

----------------------------------------------------------------------

Comment By: nasm64developer (nasm64developer)
Date: 2011-07-23 23:09

Message:
> > even though that is presumably not the
> > intention of the programmer.

The programmer's intent is not clear from
the code. Yes, EAX suggests 32 bits... but
no, it's not sufficient to suggest that there
should be no bounds warnings.

The programmer should explicitly specify
mov eax, 0xFFFFFFFF & (~(1<<31)) so that
the 32-bit intent becomes non-ambiguous
and the warning goes away.

----------------------------------------------------------------------

Best,
Frank


Offline Serge

  • Jr. Member
  • *
  • Posts: 26
  • Country: ru
Re: Strange warning: Dword data exceeds bounds
« Reply #4 on: July 23, 2011, 11:34:35 PM »
Yeah, I know about 0xFFFFFFFF & (~(1<<31))
The thing is that no one bit in upper 32 bits is actually meaningful after shift and inversion. So masking them out is just a "lotion" to get rid of warning.

Offline Cyrill Gorcunov

  • NASM Developer
  • Full Member
  • *****
  • Posts: 176
  • Country: 00
Re: Strange warning: Dword data exceeds bounds
« Reply #5 on: July 24, 2011, 05:20:53 PM »
Quote
The programmer should explicitly specify
mov eax, 0xFFFFFFFF & (~(1<<31)) so that
the 32-bit intent becomes non-ambiguous
and the warning goes away.

I don't agree with nasm64developer here, I didn't manage to look if we can do something with it but such constructions
look to me like I would have to type

Code: [Select]
int var = 0xFFFFFFFF & (~(1<<31))

in C code, this is somehow... inconvenient :)

Offline Serge

  • Jr. Member
  • *
  • Posts: 26
  • Country: ru
Re: Strange warning: Dword data exceeds bounds
« Reply #6 on: July 24, 2011, 08:29:45 PM »
Me too.
I think that there is slightly broken logic here. As far as I can get, the NASM sees that the sign bit is changed (from negative to positive) and not propagated to the upper half. But actually the same logic implies that (1<<31) without inversion also changes the sign bit (now from positive to negative) which is also not propagated to upper half. But in this case NASM doesn't warn about probable data loss. Why?
To be consistent, both cases (with and without inversion) should work identically. But removing warning seems to me more adequate.

Offline Cyrill Gorcunov

  • NASM Developer
  • Full Member
  • *****
  • Posts: 176
  • Country: 00
Re: Strange warning: Dword data exceeds bounds
« Reply #7 on: August 21, 2011, 06:06:26 PM »
It's not that simple from internal code structure. I hope we will fix it one day.