Skip to content

Commit a1358fb

Browse files
committed
---
yaml --- r: 34534 b: refs/heads/snap-stage3 c: f76e28a h: refs/heads/master v: v3
1 parent 13d5666 commit a1358fb

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 452642422dda045b89cbcb2b7d011c85c5202d5d
4+
refs/heads/snap-stage3: f76e28aa1c093c59671749006e1a7ae203d66b7c
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/middle/trans/base.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,16 +2308,21 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
23082308
let my_path = vec::append(/*bad*/copy *pth,
23092309
~[path_name(i.ident)]);
23102310
match i.node {
2311-
ast::item_const(_, _) => {
2311+
ast::item_const(_, expr) => {
23122312
let typ = ty::node_id_to_type(ccx.tcx, i.id);
23132313
let s = mangle_exported_name(ccx, my_path, typ);
2314-
let g = str::as_c_str(s, |buf| {
2315-
unsafe {
2316-
llvm::LLVMAddGlobal(ccx.llmod, type_of(ccx, typ), buf)
2317-
}
2318-
});
2319-
ccx.item_symbols.insert(i.id, s);
2320-
g
2314+
// We need the translated value here, because for enums the
2315+
// LLVM type is not fully determined by the Rust type.
2316+
let v = consts::const_expr(ccx, expr);
2317+
ccx.const_values.insert(id, v);
2318+
unsafe {
2319+
let llty = llvm::LLVMTypeOf(v);
2320+
let g = str::as_c_str(s, |buf| {
2321+
llvm::LLVMAddGlobal(ccx.llmod, llty, buf)
2322+
});
2323+
ccx.item_symbols.insert(i.id, s);
2324+
g
2325+
}
23212326
}
23222327
ast::item_fn(_, purity, _, _) => {
23232328
let llfn = if purity != ast::extern_fn {

branches/snap-stage3/src/librustc/middle/trans/consts.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,13 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
464464
}
465465
}
466466

467-
fn trans_const(ccx: @crate_ctxt, e: @ast::expr, id: ast::node_id) {
467+
fn trans_const(ccx: @crate_ctxt, _e: @ast::expr, id: ast::node_id) {
468468
unsafe {
469469
let _icx = ccx.insn_ctxt("trans_const");
470470
let g = base::get_item_val(ccx, id);
471-
let v = const_expr(ccx, e);
472-
ccx.const_values.insert(id, v);
471+
// At this point, get_item_val has already translated the
472+
// constant's initializer to determine its LLVM type.
473+
let v = ccx.const_values.get(id);
473474
llvm::LLVMSetInitializer(g, v);
474475
llvm::LLVMSetGlobalConstant(g, True);
475476
}

branches/snap-stage3/src/librustc/middle/trans/expr.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,11 @@ fn trans_def_lvalue(bcx: block,
798798
ast::def_const(did) => {
799799
let const_ty = expr_ty(bcx, ref_expr);
800800
let val = if did.crate == ast::local_crate {
801-
base::get_item_val(ccx, did.node)
801+
// The LLVM global has the type of its initializer,
802+
// which may not be equal to the enum's type for
803+
// non-C-like enums.
804+
PointerCast(bcx, base::get_item_val(ccx, did.node),
805+
T_ptr(type_of(bcx.ccx(), const_ty)))
802806
} else {
803807
base::trans_external_path(ccx, did, const_ty)
804808
};

0 commit comments

Comments
 (0)