]> git.lizzy.rs Git - rust.git/commit
Auto merge of #44060 - taleks:issue-43205, r=arielb1
authorbors <bors@rust-lang.org>
Sun, 27 Aug 2017 12:53:48 +0000 (12:53 +0000)
committerbors <bors@rust-lang.org>
Sun, 27 Aug 2017 12:53:48 +0000 (12:53 +0000)
commiteb8f2586ebd842dec49d3d7f50e49a985ab31493
tree226a99001cbff7d8aabda31213b640ba3a5f1b38
parent78e95bb7ac92f8f92654705a47cef652b6a0b259
parente13090e8b2f8adce9277f2ebfa37efa75c8837a8
Auto merge of #44060 - taleks:issue-43205, r=arielb1

Fixes issue #43205: ICE in Rvalue::Len evaluation.

- fixes evaluation of array length for zero-sized type referenced by rvalue operand.
- adds test to verify fix.

*Cause of the issue*.

Zero-sized aggregates are handled as operands, not lvalues. Therefore while visiting `Assign` statement by `LocalAnalyser`, `mark_as_lvalue()` is not called for related `Local`. This behaviour is controlled by `rvalue_creates_operand()` method.

As result it causes error later, when rvalue operand is evaluated in `trans_rvalue_operand()` while handling `Rvalue::Len` case. Array length evaluation invokes `trans_lvalue()` which expects referenced `Local` to be value, not operand.

*How it is fixed*.

In certain cases result of `Rvalue::Len` can be evaluated without calling
`trans_lvalue()`. Method `evaluate_array_len()` is introduced to handle length
evaluation for zero-sized types referenced by Locals.

*Some concerns*.

- `trans_lvalue()` has two other entry points in `rvalue.rs`: it is invoked while handling `Rvalue::Ref` and `Rvalue::Discriminant`. There is a chance those may produce the same issue, but I've failed to write a specific test that leads to this.
- `evaluate_array_len()` performs the same check (matches lvalue and `Local`), which is performed again in `trans_lvalue()`. Without changing `trans_lvalue()` signature to make it aware that caller deals with rvalue, it seems there is no cheap solution to avoid this check.