diff --git a/src/asm/lexer.c b/src/asm/lexer.c index 96b0204c..20d846a0 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -1179,7 +1179,7 @@ static uint32_t readFractionalPart(uint32_t integer) precision = fixPrecision; } - if (integer >= ((uint32_t)1 << (precision - 1))) + if (integer >= ((uint64_t)1 << precision)) warning(WARNING_LARGE_CONSTANT, "Magnitude of fixed-point constant is too large\n"); // Cast to unsigned avoids undefined overflow behavior diff --git a/test/asm/fixed-point-magnitude.asm b/test/asm/fixed-point-magnitude.asm new file mode 100644 index 00000000..6e05c726 --- /dev/null +++ b/test/asm/fixed-point-magnitude.asm @@ -0,0 +1,13 @@ +OPT Q.4 +println 1.0 +println -1.0 +println 0.0625 +println -0.0625 +println 7.25 +println -7.25 +println 12.25 +println -12.25 +println 15.9375 +println -15.9375 +println 20.0 +println -20.0 diff --git a/test/asm/fixed-point-magnitude.err b/test/asm/fixed-point-magnitude.err new file mode 100644 index 00000000..753e8fbb --- /dev/null +++ b/test/asm/fixed-point-magnitude.err @@ -0,0 +1,4 @@ +warning: fixed-point-magnitude.asm(12): [-Wlarge-constant] + Magnitude of fixed-point constant is too large +warning: fixed-point-magnitude.asm(13): [-Wlarge-constant] + Magnitude of fixed-point constant is too large diff --git a/test/asm/fixed-point-magnitude.out b/test/asm/fixed-point-magnitude.out new file mode 100644 index 00000000..faa3c50e --- /dev/null +++ b/test/asm/fixed-point-magnitude.out @@ -0,0 +1,12 @@ +$10 +$FFFFFFF0 +$1 +$FFFFFFFF +$74 +$FFFFFF8C +$C4 +$FFFFFF3C +$FF +$FFFFFF01 +$140 +$FFFFFEC0 diff --git a/test/asm/opt-Q.err b/test/asm/opt-Q.err index 58e656cc..ee7501ff 100644 --- a/test/asm/opt-Q.err +++ b/test/asm/opt-Q.err @@ -1,5 +1,3 @@ -warning: opt-Q.asm(10) -> opt-Q.asm::REPT~1(12) -> opt-Q.asm::test(5): [-Wlarge-constant] - Magnitude of fixed-point constant is too large error: opt-Q.asm(17) -> opt-Q.asm::test(3): Argument for option 'Q' must be between 1 and 31 error: opt-Q.asm(18) -> opt-Q.asm::test(3):