Skip to content

Commit

Permalink
C backend: fix GCC warning due to INT_MIN/LLONG_MIN emitting as unsig…
Browse files Browse the repository at this point in the history
…ned values

&h8000000000000000ll (eg. FB_ARRAYDIM_UNKNOWN in fbc's source) was compiled to
-9223372036854775808ull which is an unsigned value. Need to add a cast to make
it signed to avoid a warning if comparing to an int64.
  • Loading branch information
rversteegen authored and jayrm committed Dec 31, 2023
1 parent 98f20ec commit 4d80821
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/compiler/ir-hlc.bas
Expand Up @@ -2073,16 +2073,17 @@ private function hEmitInt _

'' Prevent GCC warnings for INT_MIN/LLONG_MIN:
'' The '-' minus sign doesn't count as part of the number
'' literal, and 2147483648 is too big for a 32bit integer,
'' so it must be marked as unsigned.
'' literal, and 2147483648 is too big to fit into a signed int,
'' so according to C99 it is an unsigned int. We must add a cast
'' to make it signed.
if( typeGetSize( dtype ) = 8 ) then
if( value = -9223372036854775808ull ) then
s += "u"
s = "(int64)" + s + "u"
end if
s += "ll"
else
if( value = -2147483648u ) then
s += "u"
s = "(int32)" + s + "u"
end if
end if
else
Expand Down

0 comments on commit 4d80821

Please sign in to comment.