Skip to content

Commit fcc3279

Browse files
committed
Fix incorrect uses of str::buf()
1 parent 286be2d commit fcc3279

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/comp/middle/trans.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5993,9 +5993,11 @@ fn new_block_ctxt(cx: &@fn_ctxt, parent: &block_parent, kind: block_kind,
59935993
name: &str) -> @block_ctxt {
59945994
let cleanups: cleanup[] = ~[];
59955995
let s = str::buf("");
5996+
let held_name; //HACK for str::buf, which doesn't keep its value alive
59965997
if cx.lcx.ccx.sess.get_opts().save_temps ||
59975998
cx.lcx.ccx.sess.get_opts().debuginfo {
5998-
s = str::buf(cx.lcx.ccx.names.next(name));
5999+
held_name = cx.lcx.ccx.names.next(name);
6000+
s = str::buf(held_name);
59996001
}
60006002
let llbb: BasicBlockRef = llvm::LLVMAppendBasicBlock(cx.llfn, s);
60016003
ret @{llbb: llbb,
@@ -8001,11 +8003,14 @@ fn make_common_glue(sess: &session::session, output: &str) {
80018003
let llmod =
80028004
llvm::LLVMModuleCreateWithNameInContext(str::buf("rust_out"),
80038005
llvm::LLVMGetGlobalContext());
8004-
llvm::LLVMSetDataLayout(llmod, str::buf(x86::get_data_layout()));
8005-
llvm::LLVMSetTarget(llmod, str::buf(x86::get_target_triple()));
8006+
let dat_layt = x86::get_data_layout(); //HACK (buf lifetime issue)
8007+
llvm::LLVMSetDataLayout(llmod, str::buf(dat_layt));
8008+
let targ_trip = x86::get_target_triple(); //HACK (buf lifetime issue)
8009+
llvm::LLVMSetTarget(llmod, str::buf(targ_trip));
80068010
mk_target_data(x86::get_data_layout());
80078011
declare_intrinsics(llmod);
8008-
llvm::LLVMSetModuleInlineAsm(llmod, str::buf(x86::get_module_asm()));
8012+
let modl_asm = x86::get_module_asm(); //HACK (buf lifetime issue)
8013+
llvm::LLVMSetModuleInlineAsm(llmod, str::buf(modl_asm));
80098014
make_glues(llmod, taskptr_type);
80108015
link::write::run_passes(sess, llmod, output);
80118016
}
@@ -8035,10 +8040,9 @@ fn create_crate_map(ccx: &@crate_ctxt) -> ValueRef {
80358040
let i = 1;
80368041
let cstore = ccx.sess.get_cstore();
80378042
while cstore::have_crate_data(cstore, i) {
8038-
let name = cstore::get_crate_data(cstore, i).name;
8043+
let nm = "_rust_crate_map_" + cstore::get_crate_data(cstore, i).name;
80398044
let cr =
8040-
llvm::LLVMAddGlobal(ccx.llmod, T_int(),
8041-
str::buf("_rust_crate_map_" + name));
8045+
llvm::LLVMAddGlobal(ccx.llmod, T_int(), str::buf(nm));
80428046
subcrates += ~[p2i(cr)];
80438047
i += 1;
80448048
}
@@ -8067,7 +8071,8 @@ fn write_metadata(cx: &@crate_ctxt, crate: &@ast::crate) {
80678071
llvm::LLVMAddGlobal(cx.llmod, val_ty(llconst),
80688072
str::buf("rust_metadata"));
80698073
llvm::LLVMSetInitializer(llglobal, llconst);
8070-
llvm::LLVMSetSection(llglobal, str::buf(x86::get_meta_sect_name()));
8074+
let met_sct_nm = x86::get_meta_sect_name(); //HACK (buf lifetime issue)
8075+
llvm::LLVMSetSection(llglobal, str::buf(met_sct_nm));
80718076
llvm::LLVMSetLinkage(llglobal,
80728077
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
80738078

@@ -8086,9 +8091,11 @@ fn trans_crate(sess: &session::session, crate: &@ast::crate, tcx: &ty::ctxt,
80868091
let llmod =
80878092
llvm::LLVMModuleCreateWithNameInContext(str::buf("rust_out"),
80888093
llvm::LLVMGetGlobalContext());
8089-
llvm::LLVMSetDataLayout(llmod, str::buf(x86::get_data_layout()));
8090-
llvm::LLVMSetTarget(llmod, str::buf(x86::get_target_triple()));
8091-
let td = mk_target_data(x86::get_data_layout());
8094+
let dat_layt = x86::get_data_layout(); //HACK (buf lifetime issue)
8095+
llvm::LLVMSetDataLayout(llmod, str::buf(dat_layt));
8096+
let targ_trip = x86::get_target_triple(); //HACK (buf lifetime issue)
8097+
llvm::LLVMSetTarget(llmod, str::buf(targ_trip));
8098+
let td = mk_target_data(dat_layt);
80928099
let tn = mk_type_names();
80938100
let intrinsics = declare_intrinsics(llmod);
80948101
let task_type = T_task();

0 commit comments

Comments
 (0)