Skip to content

recursive static initialization is broken #120

Closed
@solson

Description

@solson

I investigated the only "tried to modify constant memory" in #55 and it's due to the fact that Miri can't properly initialize statics that recursively refer to each other. This would be low priority since it only affects the unstable #![feature(static_recursion)], but the feature looks like it will be stable soon.

E.g.

struct S(&'static S);
static S1: S = S(&S2);
static S2: S = S(&S1);

When you start initializing S1:

  1. you'll start initializing S2 because it's required (ConstantExtractor)
  2. write the final result for S2
  3. freeze S2 and all allocations it references (this freezes S1)
  4. pick up where you left off initializing S1
  5. write the final result for S1 (fails because it's frozen)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions