-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Memory corruption/read from uninitialized memory with {.noinit.}
in refc
in Nim 2.0/2.2/devel
, also triggers gcc
UBSAN
#24332
Comments
It's not the compiler's fault if you get |
How is this wrong?
|
Notably, this has nothing to do with the case object feature - it applies equally to all types - |
I cannot reproduce the failure: devel/2.2.0 and gcc 14 on Linux |
It depends a lot on the specific constants. The basic issue is still there in the code structure -- it's reading garbage/unitialized memory. For reference I'm using Debian
The entire |
And then you can disable the warning message effectively introducing |
Description
Compile with
nim c -r --mm:refc -d:release --passC="-fsanitize=undefined" --passL="-fsanitize=undefined"
In particular, what appears to happen is that the
{.noinit.}
in a local sense as expected, but what doesn't happen is the assignment overwritingc
with a completely initialized object.From the compiled C, this manifest as this
s()
proc being translated into:and
u()
ass()
properly declaresbut indeed does not initialize it. So far, it's correct. The error is that
u()
, because it uses thisreturn style where it outputs directly to
Result
, reads from effectively uninitialized memory when determining what to do with thecase
object:rather than writing to it.
This
*Result
has never been initialized bys()
so it's garbage.Nim Version
Current Output
Expected Output
Known Workarounds
No response
Additional Information
Example
gdb
session (without UBSAN, i.e. it's not a UBSAN artifact, but with--debuginfo:on
):The exact alignment varies a bit depending on how it's run, but this
Result->w.r.w
is fromu()
per the description:s.nim.c.txt
i.e. it's supposed to be one of
NIM_TRUE
orNIM_FALSE
because it's abool
discriminator for theK[T]
type.The text was updated successfully, but these errors were encountered: