Skip to content

Commit 5ece092

Browse files
committed
auto merge of #11033 : michaelwoerister/rust/byvalself, r=pcwalton
As the title says. The trans changes will lead to an auxiliary alloca being created that allows debug info to track the `self` argument. This alloca is only created in debug builds however. Otherwise very little had to be done after I managed to navigate to some degree the jungle that is self-argument handling `:P` Closes #10549
2 parents c335734 + 01fae5f commit 5ece092

10 files changed

+215
-197
lines changed

src/librustc/middle/trans/debuginfo.rs

+23-4
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,13 @@ use driver::session;
129129
use lib::llvm::llvm;
130130
use lib::llvm::{ModuleRef, ContextRef, ValueRef};
131131
use lib::llvm::debuginfo::*;
132+
use middle::trans::adt;
133+
use middle::trans::base;
134+
use middle::trans::build;
132135
use middle::trans::common::*;
133136
use middle::trans::machine;
134137
use middle::trans::type_of;
135138
use middle::trans::type_::Type;
136-
use middle::trans::adt;
137139
use middle::trans;
138140
use middle::ty;
139141
use middle::pat_util;
@@ -453,12 +455,29 @@ pub fn create_self_argument_metadata(bcx: @mut Block,
453455

454456
let address_operations = &[unsafe { llvm::LLVMDIBuilderCreateOpDeref(Type::i64().to_ref()) }];
455457

458+
// The self argument comes in one of two forms:
459+
// (1) For `&self`, `~self`, and `@self` it is an alloca containing a pointer to the data. That
460+
// is the `{&~@}self` pointer is contained by value in the alloca, and `type_of_self` will
461+
// be `{&~@}Self`
462+
// (2) For by-value `self`, `llptr` will not be an alloca, but a pointer to the self-value. That
463+
// is by-value `self` is always implicitly passed by reference (sic!). So we have a couple
464+
// of problems here:
465+
// (a) There is no alloca to give to `llvm.dbg.declare` and
466+
// (b) `type_of_self` is `Self`, but `llptr` is of type `*Self`
467+
// In order to solve this problem, the else branch below creates a helper alloca which
468+
// contains a copy of `llptr`. We then describe the `self` parameter by pointing
469+
// `llvm.dbg.declare` to this helper alloca and tell it that the pointer there needs to be
470+
// dereferenced once to get to the actual data (similar to non-immediate by-value args).
456471
let variable_access = if unsafe { llvm::LLVMIsAAllocaInst(llptr) } != ptr::null() {
457472
DirectVariable { alloca: llptr }
458473
} else {
459-
// This is not stable and may break with future LLVM versions. llptr should really always
460-
// be an alloca. Anything else is not supported and just works by chance.
461-
IndirectVariable { alloca: llptr, address_operations: address_operations }
474+
// Create a helper alloca that allows us to track the self-argument properly. The alloca
475+
// contains a pointer to the self-value.
476+
let ptr_type = ty::mk_mut_ptr(bcx.tcx(), type_of_self);
477+
let helper_alloca = base::alloc_ty(bcx, ptr_type, "__self");
478+
build::Store(bcx, llptr, helper_alloca);
479+
480+
IndirectVariable { alloca: helper_alloca, address_operations: address_operations }
462481
};
463482

464483
declare_local(bcx,

src/test/debug-info/by-value-self-argument-in-trait-impl.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-win32: FIXME (#10474)
1211
// xfail-android: FIXME(#10381)
1312

1413
#[feature(managed_boxes)];

src/test/debug-info/generic-method-on-generic-struct.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -26,72 +26,72 @@
2626

2727
// STACK BY VAL
2828
// debugger:finish
29-
// d ebugger:print self -- ignored for now because of issue #8512
30-
// c heck:$X = {x = {8888, -8888}}
29+
// debugger:print self
30+
// check:$4 = {x = {8888, -8888}}
3131
// debugger:print arg1
32-
// check:$4 = -3
32+
// check:$5 = -3
3333
// debugger:print arg2
34-
// check:$5 = -4
34+
// check:$6 = -4
3535
// debugger:continue
3636

3737
// OWNED BY REF
3838
// debugger:finish
3939
// debugger:print *self
40-
// check:$6 = {x = 1234.5}
40+
// check:$7 = {x = 1234.5}
4141
// debugger:print arg1
42-
// check:$7 = -5
42+
// check:$8 = -5
4343
// debugger:print arg2
44-
// check:$8 = -6
44+
// check:$9 = -6
4545
// debugger:continue
4646

4747
// OWNED BY VAL
4848
// debugger:finish
49-
// d ebugger:print self -- ignored for now because of issue #8512
50-
// c heck:$X = {x = 1234.5}
49+
// debugger:print self
50+
// check:$10 = {x = 1234.5}
5151
// debugger:print arg1
52-
// check:$9 = -7
52+
// check:$11 = -7
5353
// debugger:print arg2
54-
// check:$10 = -8
54+
// check:$12 = -8
5555
// debugger:continue
5656

5757
// OWNED MOVED
5858
// debugger:finish
5959
// debugger:print *self
60-
// check:$11 = {x = 1234.5}
60+
// check:$13 = {x = 1234.5}
6161
// debugger:print arg1
62-
// check:$12 = -9
62+
// check:$14 = -9
6363
// debugger:print arg2
64-
// check:$13 = -10.5
64+
// check:$15 = -10.5
6565
// debugger:continue
6666

6767
// MANAGED BY REF
6868
// debugger:finish
6969
// debugger:print *self
70-
// check:$14 = {x = -1}
70+
// check:$16 = {x = -1}
7171
// debugger:print arg1
72-
// check:$15 = -11
72+
// check:$17 = -11
7373
// debugger:print arg2
74-
// check:$16 = -12.5
74+
// check:$18 = -12.5
7575
// debugger:continue
7676

7777
// MANAGED BY VAL
7878
// debugger:finish
79-
// d ebugger:print self -- ignored for now because of issue #8512
80-
// c heck:$X = {x = -1}
79+
// debugger:print self
80+
// check:$19 = {x = -1}
8181
// debugger:print arg1
82-
// check:$17 = -13
82+
// check:$20 = -13
8383
// debugger:print *arg2
84-
// check:$18 = {-14, 14}
84+
// check:$21 = {-14, 14}
8585
// debugger:continue
8686

8787
// MANAGED SELF
8888
// debugger:finish
8989
// debugger:print self->val
90-
// check:$19 = {x = -1}
90+
// check:$22 = {x = -1}
9191
// debugger:print arg1
92-
// check:$20 = -15
92+
// check:$23 = -15
9393
// debugger:print *arg2
94-
// check:$21 = {-16, 16.5}
94+
// check:$24 = {-16, 16.5}
9595
// debugger:continue
9696

9797
#[feature(managed_boxes)];

src/test/debug-info/method-on-enum.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -26,72 +26,72 @@
2626

2727
// STACK BY VAL
2828
// debugger:finish
29-
// d ebugger:print self -- ignored for now because of issue #8512
30-
// c heck:$X = {{Variant2, [...]}, {Variant2, 117901063}}
29+
// debugger:print self
30+
// check:$4 = {{Variant2, [...]}, {Variant2, 117901063}}
3131
// debugger:print arg1
32-
// check:$4 = -3
32+
// check:$5 = -3
3333
// debugger:print arg2
34-
// check:$5 = -4
34+
// check:$6 = -4
3535
// debugger:continue
3636

3737
// OWNED BY REF
3838
// debugger:finish
3939
// debugger:print *self
40-
// check:$6 = {{Variant1, x = 1799, y = 1799}, {Variant1, [...]}}
40+
// check:$7 = {{Variant1, x = 1799, y = 1799}, {Variant1, [...]}}
4141
// debugger:print arg1
42-
// check:$7 = -5
42+
// check:$8 = -5
4343
// debugger:print arg2
44-
// check:$8 = -6
44+
// check:$9 = -6
4545
// debugger:continue
4646

4747
// OWNED BY VAL
4848
// debugger:finish
49-
// d ebugger:print self -- ignored for now because of issue #8512
50-
// c heck:$X = {{Variant1, x = 1799, y = 1799}, {Variant1, [...]}}
49+
// debugger:print self
50+
// check:$10 = {{Variant1, x = 1799, y = 1799}, {Variant1, [...]}}
5151
// debugger:print arg1
52-
// check:$9 = -7
52+
// check:$11 = -7
5353
// debugger:print arg2
54-
// check:$10 = -8
54+
// check:$12 = -8
5555
// debugger:continue
5656

5757
// OWNED MOVED
5858
// debugger:finish
5959
// debugger:print *self
60-
// check:$11 = {{Variant1, x = 1799, y = 1799}, {Variant1, [...]}}
60+
// check:$13 = {{Variant1, x = 1799, y = 1799}, {Variant1, [...]}}
6161
// debugger:print arg1
62-
// check:$12 = -9
62+
// check:$14 = -9
6363
// debugger:print arg2
64-
// check:$13 = -10
64+
// check:$15 = -10
6565
// debugger:continue
6666

6767
// MANAGED BY REF
6868
// debugger:finish
6969
// debugger:print *self
70-
// check:$14 = {{Variant2, [...]}, {Variant2, 117901063}}
70+
// check:$16 = {{Variant2, [...]}, {Variant2, 117901063}}
7171
// debugger:print arg1
72-
// check:$15 = -11
72+
// check:$17 = -11
7373
// debugger:print arg2
74-
// check:$16 = -12
74+
// check:$18 = -12
7575
// debugger:continue
7676

7777
// MANAGED BY VAL
7878
// debugger:finish
79-
// d ebugger:print self -- ignored for now because of issue #8512
80-
// c heck:$X = {{Variant2, [...]}, {Variant2, 117901063}}
79+
// debugger:print self
80+
// check:$19 = {{Variant2, [...]}, {Variant2, 117901063}}
8181
// debugger:print arg1
82-
// check:$17 = -13
82+
// check:$20 = -13
8383
// debugger:print arg2
84-
// check:$18 = -14
84+
// check:$21 = -14
8585
// debugger:continue
8686

8787
// MANAGED SELF
8888
// debugger:finish
8989
// debugger:print self->val
90-
// check:$19 = {{Variant2, [...]}, {Variant2, 117901063}}
90+
// check:$22 = {{Variant2, [...]}, {Variant2, 117901063}}
9191
// debugger:print arg1
92-
// check:$20 = -15
92+
// check:$23 = -15
9393
// debugger:print arg2
94-
// check:$21 = -16
94+
// check:$24 = -16
9595
// debugger:continue
9696

9797
#[feature(managed_boxes)];

src/test/debug-info/method-on-generic-struct.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -26,72 +26,72 @@
2626

2727
// STACK BY VAL
2828
// debugger:finish
29-
// d ebugger:print self -- ignored for now because of issue #8512
30-
// c heck:$X = {x = {8888, -8888}}
29+
// debugger:print self
30+
// check:$4 = {x = {8888, -8888}}
3131
// debugger:print arg1
32-
// check:$4 = -3
32+
// check:$5 = -3
3333
// debugger:print arg2
34-
// check:$5 = -4
34+
// check:$6 = -4
3535
// debugger:continue
3636

3737
// OWNED BY REF
3838
// debugger:finish
3939
// debugger:print *self
40-
// check:$6 = {x = 1234.5}
40+
// check:$7 = {x = 1234.5}
4141
// debugger:print arg1
42-
// check:$7 = -5
42+
// check:$8 = -5
4343
// debugger:print arg2
44-
// check:$8 = -6
44+
// check:$9 = -6
4545
// debugger:continue
4646

4747
// OWNED BY VAL
4848
// debugger:finish
49-
// d ebugger:print self -- ignored for now because of issue #8512
50-
// c heck:$X = {x = 1234.5}
49+
// debugger:print self
50+
// check:$10 = {x = 1234.5}
5151
// debugger:print arg1
52-
// check:$9 = -7
52+
// check:$11 = -7
5353
// debugger:print arg2
54-
// check:$10 = -8
54+
// check:$12 = -8
5555
// debugger:continue
5656

5757
// OWNED MOVED
5858
// debugger:finish
5959
// debugger:print *self
60-
// check:$11 = {x = 1234.5}
60+
// check:$13 = {x = 1234.5}
6161
// debugger:print arg1
62-
// check:$12 = -9
62+
// check:$14 = -9
6363
// debugger:print arg2
64-
// check:$13 = -10
64+
// check:$15 = -10
6565
// debugger:continue
6666

6767
// MANAGED BY REF
6868
// debugger:finish
6969
// debugger:print *self
70-
// check:$14 = {x = -1}
70+
// check:$16 = {x = -1}
7171
// debugger:print arg1
72-
// check:$15 = -11
72+
// check:$17 = -11
7373
// debugger:print arg2
74-
// check:$16 = -12
74+
// check:$18 = -12
7575
// debugger:continue
7676

7777
// MANAGED BY VAL
7878
// debugger:finish
79-
// d ebugger:print self -- ignored for now because of issue #8512
80-
// c heck:$X = {x = -1}
79+
// debugger:print self
80+
// check:$19 = {x = -1}
8181
// debugger:print arg1
82-
// check:$17 = -13
82+
// check:$20 = -13
8383
// debugger:print arg2
84-
// check:$18 = -14
84+
// check:$21 = -14
8585
// debugger:continue
8686

8787
// MANAGED SELF
8888
// debugger:finish
8989
// debugger:print self->val
90-
// check:$19 = {x = -1}
90+
// check:$22 = {x = -1}
9191
// debugger:print arg1
92-
// check:$20 = -15
92+
// check:$23 = -15
9393
// debugger:print arg2
94-
// check:$21 = -16
94+
// check:$24 = -16
9595
// debugger:continue
9696

9797
#[feature(managed_boxes)];

0 commit comments

Comments
 (0)