-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
syntax errors for unsigned literals longer than 128 bits #11105
Comments
I agree this should be a syntax error. |
@JeffBezanson Error, or warning (or do you not do warnings in Julia?) |
|
|
@pao big"0xfffff....." works just fine, so people have an out if they really understand it will be signed... thx |
@ihnorton Thanks! Now I just need to figure out where to put the warn! |
I try to avoid warnings. I think it's better to be decisive and make it an error, or allow it. Warnings just mean you later need to add |
+1 for syntax error, bigints from literals make it harder to deploy a Julia runtime without needing gmp. |
@JeffBezanson Good point... can somebody please either tell me (at least in the general direction) where I'd fix this to give a syntax error, or else fix it themselves? (I'd rather just fix it myself, I'll learn more, and you can do more important stuff) |
@JeffBezanson I noticed this problem also occurs for octal literals? Shall I add an error there as well? I've found where the problem is in julia-parser.scm, and will fix and submit a PR shortly |
@JeffBezanson I see that it is also for binary literals, but I ran into a problem... any help would be appreciated... ;; n is #f for integers > typemax(UInt64)
(cond (is-hex-float-literal (double n))
((eq? pred char-hex?) (fix-uint-neg neg (sized-uint-literal n s 4)))
((eq? pred char-oct?) (fix-uint-neg neg (sized-uint-oct-literal n s)))
((eq? pred char-bin?) (fix-uint-neg neg (sized-uint-literal n s 1)))
(is-float32-literal (float n))
(n (if (and (integer? n) (> n 9223372036854775807))
`(macrocall @int128_str ,s)
n))
((within-int128? s) `(macrocall @int128_str ,s))
(else `(macrocall @big_str ,s))))))
(define (fix-uint-neg neg n)
(if neg
(if (large-number? n)
`(call - ,(maybe-negate '- n))
`(call - ,n))
n))
(define (sized-uint-literal n s b)
(let* ((i (if (eqv? (string.char s 0) #\-) 3 2))
(l (* (- (length s) i) b)))
(cond ((<= l 8) (uint8 n))
((<= l 16) (uint16 n))
((<= l 32) (uint32 n))
((<= l 64) (uint64 n))
((<= l 128) `(macrocall @uint128_str ,s))
(else (error "Hex or binary literal too large for UInt128"))))) I think the problem is that it is trying to always do: `(call - ,n)` but it doesn't like the error call... I get this: julia> 0x123412341234123412341234123413241234214123412342341234
julia(38321,0x7fff7c1d3300) malloc: *** mach_vm_map(size=237494511603712) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
ERROR: syntax: Hex or binary literal too large for UInt128 Thanks in advance for help from anybody! |
This issue is also for binary literals, going from unsigned to signed...
|
… get promoted to signed
#11105 Add syntax errors for unsigned literals > UInt128
… get promoted to signed
… get promoted to signed
If you have hexadecimal literal, normally it produces an unsigned value, whose size is dependent on the length of the literal.
However, if you go past 128 bits (32 hex digits), then it will switch to a signed number, which could possibly lead to hard to find bugs.
For example:
I believe this at least deserves a warning from the compiler (a point I tried to raise in #11081, only to have the title of my issue changed out from under me and then have it closed)
The text was updated successfully, but these errors were encountered: