ctxt_auto_deref_lval decides whether to autoderef the entire lval, not its base.
This commit is contained in:
parent
fde9ca0937
commit
ae515c017c
3 changed files with 43 additions and 17 deletions
|
@ -386,6 +386,7 @@ TEST_XFAILS_LLVM := $(addprefix test/run-pass/, \
|
||||||
acyclic-unwind.rs \
|
acyclic-unwind.rs \
|
||||||
alt-pattern-simple.rs \
|
alt-pattern-simple.rs \
|
||||||
alt-tag.rs \
|
alt-tag.rs \
|
||||||
|
autoderef-full-lval.rs \
|
||||||
autoderef-objfn.rs \
|
autoderef-objfn.rs \
|
||||||
basic.rs \
|
basic.rs \
|
||||||
bind-obj-ctor.rs \
|
bind-obj-ctor.rs \
|
||||||
|
|
|
@ -973,33 +973,40 @@ let trans_visitor
|
||||||
(lv:Ast.lval)
|
(lv:Ast.lval)
|
||||||
: (Il.cell * Ast.ty) =
|
: (Il.cell * Ast.ty) =
|
||||||
|
|
||||||
let rec trans_slot_lval_full (initializing:bool) lv =
|
let rec trans_slot_lval_full (initializing:bool) (outermost:bool) lv =
|
||||||
let (cell, ty) =
|
let (cell, ty) =
|
||||||
match lv with
|
match lv with
|
||||||
Ast.LVAL_ext (base, comp) ->
|
Ast.LVAL_ext (base, comp) ->
|
||||||
let (base_cell, base_ty) =
|
let (base_cell, base_ty) =
|
||||||
trans_slot_lval_full initializing base
|
trans_slot_lval_full initializing false base
|
||||||
in
|
in
|
||||||
trans_slot_lval_ext initializing base_ty base_cell comp
|
trans_slot_lval_ext initializing base_ty base_cell comp
|
||||||
|
|
||||||
| Ast.LVAL_base nbi ->
|
| Ast.LVAL_base _ ->
|
||||||
let sloti = lval_base_to_slot cx lv in
|
let sloti = lval_base_to_slot cx lv in
|
||||||
let cell = cell_of_block_slot sloti.id in
|
let cell = cell_of_block_slot sloti.id in
|
||||||
let ty = slot_ty sloti.node in
|
let ty = slot_ty sloti.node in
|
||||||
let cell = deref_slot initializing cell sloti.node in
|
let cell = deref_slot initializing cell sloti.node in
|
||||||
let dctrl =
|
(cell, ty)
|
||||||
(* If this fails, type didn't visit the lval, and we
|
in
|
||||||
* don't know whether to auto-deref its base. Crashing
|
let (cell, ty) =
|
||||||
* here is best. Compiler bug.
|
if outermost
|
||||||
*)
|
then
|
||||||
match htab_search cx.ctxt_auto_deref_lval nbi.id with
|
let id = lval_base_id lv in
|
||||||
None ->
|
let dctrl =
|
||||||
bugi cx nbi.id
|
(* If this fails, type didn't visit the lval, and we
|
||||||
"Lval without auto-deref info; bad typecheck?"
|
* don't know whether to auto-deref the entire lval.
|
||||||
| Some true -> DEREF_all_boxes
|
* Crashing here is best. Compiler bug.
|
||||||
| Some false -> DEREF_none
|
*)
|
||||||
in
|
match htab_search cx.ctxt_auto_deref_lval id with
|
||||||
deref_ty dctrl initializing cell ty
|
None ->
|
||||||
|
bugi cx id
|
||||||
|
"Lval without auto-deref info; bad typecheck?"
|
||||||
|
| Some true -> DEREF_all_boxes
|
||||||
|
| Some false -> DEREF_none
|
||||||
|
in
|
||||||
|
deref_ty dctrl initializing cell ty
|
||||||
|
else (cell, ty)
|
||||||
in
|
in
|
||||||
iflog
|
iflog
|
||||||
begin
|
begin
|
||||||
|
@ -1013,7 +1020,7 @@ let trans_visitor
|
||||||
|
|
||||||
in
|
in
|
||||||
if lval_is_slot cx lv
|
if lval_is_slot cx lv
|
||||||
then trans_slot_lval_full initializing lv
|
then trans_slot_lval_full initializing true lv
|
||||||
else
|
else
|
||||||
if initializing
|
if initializing
|
||||||
then err None "init item"
|
then err None "init item"
|
||||||
|
|
18
src/test/run-pass/autoderef-full-lval.rs
Normal file
18
src/test/run-pass/autoderef-full-lval.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
// -*- rust -*-
|
||||||
|
|
||||||
|
type clam = rec(@int x, @int y);
|
||||||
|
type fish = tup(@int);
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let clam a = rec(x=@1, y=@2);
|
||||||
|
let clam b = rec(x=@10, y=@20);
|
||||||
|
let int z = a.x + b.y;
|
||||||
|
log z;
|
||||||
|
check (z == 21);
|
||||||
|
|
||||||
|
let fish forty = tup(@40);
|
||||||
|
let fish two = tup(@2);
|
||||||
|
let int answer = forty._0 + two._0;
|
||||||
|
log answer;
|
||||||
|
check (answer == 42);
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue