-
Notifications
You must be signed in to change notification settings - Fork 64
Are statics confined to the size indicated by their type? #259
Copy link
Copy link
Open
rust-lang/reference
#2334Labels
A-memoryTopic: Related to memory accessesTopic: Related to memory accessesC-open-questionCategory: An open question that we should revisitCategory: An open question that we should revisitS-pending-team-decisionStatus: There is broad agreement on the answer to the question, but no official (FCP'd) decisionStatus: There is broad agreement on the answer to the question, but no official (FCP'd) decision
Description
Activity
Metadata
Metadata
Assignees
Labels
A-memoryTopic: Related to memory accessesTopic: Related to memory accessesC-open-questionCategory: An open question that we should revisitCategory: An open question that we should revisitS-pending-team-decisionStatus: There is broad agreement on the answer to the question, but no official (FCP'd) decisionStatus: There is broad agreement on the answer to the question, but no official (FCP'd) decision
Occasionally, people ask about a pattern where a program has
externstatics likeand the intention is not that these are two integers, but that these indicate an array of integers between the two addresses.
Is that legal, or may the compiler assume that accesses outside of the
u32are out-of-bounds and thus UB?That boils down to two questions:
The former is something that hopefully the LLVM docs can answer. If the answer is "yes", Rust would have to follow suit or lobby for changing LLVM. If the answer is "no", we can decide either way.
The pattern is also a bit weird in that it promises that there are at least 4 bytes of memory available at
beginandendeach. If the actual region of memory is smaller than that, I am fairly sure that at least any use of the static is UB --BEGINdenotes a place of size 4, and it is (currently) UB to create dangling places. If we wanted to change this we again need to start by figuring out what LLVM's rules are.