-
-
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
Semantics of Expr(:new)
underspecified
#26764
Comments
We should move towards initializing to zero, unless the cost is prohibitive. I suspect in these cases it's not. |
Or just disallow incomplete construction of immutable structs. |
At least for the isbits fields, see #24943. I have hit that twice when I have forgotten updating my |
It would be very difficult to define a type like |
Opt in to it by enforcing putting |
If only we had thought to add optimizations to make it more performant to explicitly mark undef by describing the field as having a Union of multiple possible types, rather than to define a type like |
Not the same as undef, since the value can propagate. |
It is exactly the same behavior as the |
We might be talking about different things. I'm talking about undefined references that throw errors on access, as opposed to It would be ok to have some syntax inside |
I was talking about what @KristofferC proposed. But I actually don't like that either since if |
You don't since that is a useless construct :). But yes, |
We could use |
That would be ok, but I'd be rather worried that we have |
Not to mention |
Related to #9147 xref |
In the time since the creation of issue #26764, there _is_ now 'a way to say to llvm "I don't care what this value is, but it always has to be the same"', so we can use that to instruct LLVM to not give us undefined behavior when users are using uninitialized memory. There should not be an impact if users were already avoiding this paradigm and are fully initializing their structs. Fixes #26764
In the time since the creation of issue #26764, there _is_ now 'a way to say to llvm "I don't care what this value is, but it always has to be the same"' using the `freeze` instruction, so we can use that to instruct LLVM to not give us undefined behavior when users are using uninitialized memory. There should not be an impact if users were already avoiding this paradigm and are fully initializing their structs. Fixes #26764
The semantics of
Expr(:new)
with missing parameters for immutables are underspecified.In particular, we need to decide whether the value is undefined or merely possibly uninitialized.
The primary difference between the two is how we represent this to LLVM. In particular undefined values may change on every access. As an illustrative example, consider:
What happens when you call
bar()
depends on LLVM versions and other considerations, but on my local copy, it prints nothing. However, any actualUInt8
value would print either "Hello" or "World". Unfortunately, there isn't really a way to say to llvm "I don't care what this value is, but it always has to be the same". If we decide we do not like the above behavior, we'll have to initialize all (stack? - will have to check what assumptions LLVM makes) allocations visible to LLVM.The text was updated successfully, but these errors were encountered: