Open fw-immunant opened 1 year ago
I don't know whether in the example above the alloc1 (static: FOO, size: 0, align: 1) {}
bit indicates that the AllocMap
has a GlobalAlloc::Static
entry (containing a DefId
) for alloc1
, or if there would actually be a GlobalAlloc::ConstAllocation
entry for it. My mental model says that the linker "allocates" here and rustc has to reason in terms of symbols, but I don't know what this looks like from the MIR world. Maybe DefId
is close enough to a symbol for middle-end purposes.
We don't handle this yet.
This basically amounts to finding the
AllocId
for aConst
and then looking up that ID. This isn't completely trivial, because we need to look through the guts of theConst
(which is an interning wrapper aroundConstS
, which annotates the type for aConstKind
, which wrapsValtree
while accounting for lazy-evaluation and generics).A
ValTree
holding a reference will give up itsAllocId
viatry_to_scalar
. We can then look up this id in the context'sAllocMap
viatcxt.global_alloc
, which will point us to what the const actually is: a function, static, or const-eval allocation.For reference/comparison,
rustc --emit=mir
on this file:gives the following MIR:
where the important line is
_4 = const {alloc1: &()};
. This assignStatement
has theOperand::Constant
Rvalue
that we care about.This bug isn't necessarily a high priority, depending on whether we need to implement this to demonstrate real-world usefulness of the dynamic instrumentation and subsequent refactoring.