Skip to content

Passing references to std::hint::black_box triggers panics #11381

@vezenovm

Description

@vezenovm

Aim

Take this Noir code:

fn main() -> pub [u8; 2] {
    let x = &mut [1, 10];
    let _ = std::hint::black_box(x);
    *x
}

Expected Behavior

I would expect this either to be rejected with a clean error or compile.

Bug

We get the following panic:

The application panicked (crashed).
Message:  internal error: entered unreachable code: Load instruction exists before `array_set_optimization` pass
Location: compiler/noirc_evaluator/src/ssa/opt/array_set.rs:244

Even after #11380 the panic just happens earlier on the Store:

The application panicked (crashed).
Message:  internal error: entered unreachable code: Store instruction exists before `array_set_optimization` pass
Location: compiler/noirc_evaluator/src/ssa/opt/array_set.rs:248

It would most likely be simplest to ban reference inputs to black_box. We can make the requirement that black_box must be passed arguments value.

To Reproduce

  1. Compile the snippet above using nargo

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

nargo version = 1.0.0-beta.18 noirc version = 1.0.0-beta.18+f00ead976b22b35a2746c6db06fd77609cabe6ea (git version hash: 6b9f690, is dirty: true)

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions