auto merge of #13291 : thestinger/rust/no_null, r=alexcrichton
This was missed when dropping the null-termination from our string types. An explicit null byte can still be placed anywhere in a string if desired, but there's no reason to stick one at the end of every string constant.
This commit is contained in:
commit
37a9885429
src
librustc/middle/trans
test/debug-info
@ -565,7 +565,7 @@ pub fn C_u8(ccx: &CrateContext, i: uint) -> ValueRef {
|
|||||||
|
|
||||||
// This is a 'c-like' raw string, which differs from
|
// This is a 'c-like' raw string, which differs from
|
||||||
// our boxed-and-length-annotated strings.
|
// our boxed-and-length-annotated strings.
|
||||||
pub fn C_cstr(cx: &CrateContext, s: InternedString) -> ValueRef {
|
pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> ValueRef {
|
||||||
unsafe {
|
unsafe {
|
||||||
match cx.const_cstr_cache.borrow().find(&s) {
|
match cx.const_cstr_cache.borrow().find(&s) {
|
||||||
Some(&llval) => return llval,
|
Some(&llval) => return llval,
|
||||||
@ -575,7 +575,7 @@ pub fn C_cstr(cx: &CrateContext, s: InternedString) -> ValueRef {
|
|||||||
let sc = llvm::LLVMConstStringInContext(cx.llcx,
|
let sc = llvm::LLVMConstStringInContext(cx.llcx,
|
||||||
s.get().as_ptr() as *c_char,
|
s.get().as_ptr() as *c_char,
|
||||||
s.get().len() as c_uint,
|
s.get().len() as c_uint,
|
||||||
False);
|
!null_terminated as Bool);
|
||||||
|
|
||||||
let gsym = token::gensym("str");
|
let gsym = token::gensym("str");
|
||||||
let g = format!("str{}", gsym).with_c_str(|buf| {
|
let g = format!("str{}", gsym).with_c_str(|buf| {
|
||||||
@ -595,7 +595,7 @@ pub fn C_cstr(cx: &CrateContext, s: InternedString) -> ValueRef {
|
|||||||
pub fn C_str_slice(cx: &CrateContext, s: InternedString) -> ValueRef {
|
pub fn C_str_slice(cx: &CrateContext, s: InternedString) -> ValueRef {
|
||||||
unsafe {
|
unsafe {
|
||||||
let len = s.get().len();
|
let len = s.get().len();
|
||||||
let cs = llvm::LLVMConstPointerCast(C_cstr(cx, s), Type::i8p(cx).to_ref());
|
let cs = llvm::LLVMConstPointerCast(C_cstr(cx, s, false), Type::i8p(cx).to_ref());
|
||||||
C_struct(cx, [cs, C_uint(cx, len)], false)
|
C_struct(cx, [cs, C_uint(cx, len)], false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -900,7 +900,7 @@ pub fn filename_and_line_num_from_span(bcx: &Block, span: Span)
|
|||||||
-> (ValueRef, ValueRef) {
|
-> (ValueRef, ValueRef) {
|
||||||
let loc = bcx.sess().codemap().lookup_char_pos(span.lo);
|
let loc = bcx.sess().codemap().lookup_char_pos(span.lo);
|
||||||
let filename_cstr = C_cstr(bcx.ccx(),
|
let filename_cstr = C_cstr(bcx.ccx(),
|
||||||
token::intern_and_get_ident(loc.file.name));
|
token::intern_and_get_ident(loc.file.name), true);
|
||||||
let filename = build::PointerCast(bcx, filename_cstr, Type::i8p(bcx.ccx()));
|
let filename = build::PointerCast(bcx, filename_cstr, Type::i8p(bcx.ccx()));
|
||||||
let line = C_int(bcx.ccx(), loc.line as int);
|
let line = C_int(bcx.ccx(), loc.line as int);
|
||||||
(filename, line)
|
(filename, line)
|
||||||
|
@ -331,10 +331,10 @@ pub fn trans_fail<'a>(
|
|||||||
fail_str: InternedString)
|
fail_str: InternedString)
|
||||||
-> &'a Block<'a> {
|
-> &'a Block<'a> {
|
||||||
let ccx = bcx.ccx();
|
let ccx = bcx.ccx();
|
||||||
let v_fail_str = C_cstr(ccx, fail_str);
|
let v_fail_str = C_cstr(ccx, fail_str, true);
|
||||||
let _icx = push_ctxt("trans_fail_value");
|
let _icx = push_ctxt("trans_fail_value");
|
||||||
let loc = bcx.sess().codemap().lookup_char_pos(sp.lo);
|
let loc = bcx.sess().codemap().lookup_char_pos(sp.lo);
|
||||||
let v_filename = C_cstr(ccx, token::intern_and_get_ident(loc.file.name));
|
let v_filename = C_cstr(ccx, token::intern_and_get_ident(loc.file.name), true);
|
||||||
let v_line = loc.line as int;
|
let v_line = loc.line as int;
|
||||||
let v_str = PointerCast(bcx, v_fail_str, Type::i8p(ccx));
|
let v_str = PointerCast(bcx, v_fail_str, Type::i8p(ccx));
|
||||||
let v_filename = PointerCast(bcx, v_filename, Type::i8p(ccx));
|
let v_filename = PointerCast(bcx, v_filename, Type::i8p(ccx));
|
||||||
|
@ -2129,7 +2129,7 @@ fn type_metadata(cx: &CrateContext,
|
|||||||
let i8_t = ty::mk_i8();
|
let i8_t = ty::mk_i8();
|
||||||
match *vstore {
|
match *vstore {
|
||||||
ty::vstore_fixed(len) => {
|
ty::vstore_fixed(len) => {
|
||||||
fixed_vec_metadata(cx, i8_t, len + 1, usage_site_span)
|
fixed_vec_metadata(cx, i8_t, len, usage_site_span)
|
||||||
},
|
},
|
||||||
ty::vstore_uniq => {
|
ty::vstore_uniq => {
|
||||||
let vec_metadata = vec_metadata(cx, i8_t, usage_site_span);
|
let vec_metadata = vec_metadata(cx, i8_t, usage_site_span);
|
||||||
|
@ -58,7 +58,7 @@ impl<'a> Reflector<'a> {
|
|||||||
let str_ty = ty::mk_str(bcx.tcx(), str_vstore);
|
let str_ty = ty::mk_str(bcx.tcx(), str_vstore);
|
||||||
let scratch = rvalue_scratch_datum(bcx, str_ty, "");
|
let scratch = rvalue_scratch_datum(bcx, str_ty, "");
|
||||||
let len = C_uint(bcx.ccx(), s.get().len());
|
let len = C_uint(bcx.ccx(), s.get().len());
|
||||||
let c_str = PointerCast(bcx, C_cstr(bcx.ccx(), s), Type::i8p(bcx.ccx()));
|
let c_str = PointerCast(bcx, C_cstr(bcx.ccx(), s, false), Type::i8p(bcx.ccx()));
|
||||||
Store(bcx, c_str, GEPi(bcx, scratch.val, [ 0, 0 ]));
|
Store(bcx, c_str, GEPi(bcx, scratch.val, [ 0, 0 ]));
|
||||||
Store(bcx, len, GEPi(bcx, scratch.val, [ 0, 1 ]));
|
Store(bcx, len, GEPi(bcx, scratch.val, [ 0, 1 ]));
|
||||||
scratch.val
|
scratch.val
|
||||||
|
@ -272,7 +272,7 @@ pub fn trans_lit_str<'a>(
|
|||||||
unsafe {
|
unsafe {
|
||||||
let bytes = str_lit.get().len();
|
let bytes = str_lit.get().len();
|
||||||
let llbytes = C_uint(bcx.ccx(), bytes);
|
let llbytes = C_uint(bcx.ccx(), bytes);
|
||||||
let llcstr = C_cstr(bcx.ccx(), str_lit);
|
let llcstr = C_cstr(bcx.ccx(), str_lit, false);
|
||||||
let llcstr = llvm::LLVMConstPointerCast(llcstr, Type::i8p(bcx.ccx()).to_ref());
|
let llcstr = llvm::LLVMConstPointerCast(llcstr, Type::i8p(bcx.ccx()).to_ref());
|
||||||
Store(bcx, llcstr,
|
Store(bcx, llcstr,
|
||||||
GEPi(bcx, lldest, [0u, abi::slice_elt_base]));
|
GEPi(bcx, lldest, [0u, abi::slice_elt_base]));
|
||||||
@ -302,7 +302,7 @@ pub fn trans_uniq_vstore<'a>(bcx: &'a Block<'a>,
|
|||||||
ast::ExprLit(lit) => {
|
ast::ExprLit(lit) => {
|
||||||
match lit.node {
|
match lit.node {
|
||||||
ast::LitStr(ref s, _) => {
|
ast::LitStr(ref s, _) => {
|
||||||
let llptrval = C_cstr(bcx.ccx(), (*s).clone());
|
let llptrval = C_cstr(bcx.ccx(), (*s).clone(), false);
|
||||||
let llptrval = PointerCast(bcx,
|
let llptrval = PointerCast(bcx,
|
||||||
llptrval,
|
llptrval,
|
||||||
Type::i8p(bcx.ccx()));
|
Type::i8p(bcx.ccx()));
|
||||||
@ -376,7 +376,7 @@ pub fn write_content<'a>(
|
|||||||
SaveIn(lldest) => {
|
SaveIn(lldest) => {
|
||||||
let bytes = s.get().len();
|
let bytes = s.get().len();
|
||||||
let llbytes = C_uint(bcx.ccx(), bytes);
|
let llbytes = C_uint(bcx.ccx(), bytes);
|
||||||
let llcstr = C_cstr(bcx.ccx(), (*s).clone());
|
let llcstr = C_cstr(bcx.ccx(), (*s).clone(), false);
|
||||||
base::call_memcpy(bcx,
|
base::call_memcpy(bcx,
|
||||||
lldest,
|
lldest,
|
||||||
llcstr,
|
llcstr,
|
||||||
|
@ -14,12 +14,12 @@
|
|||||||
// debugger:rbreak zzz
|
// debugger:rbreak zzz
|
||||||
// debugger:run
|
// debugger:run
|
||||||
// debugger:finish
|
// debugger:finish
|
||||||
// debugger:print string1
|
// debugger:print string1.length
|
||||||
// check:$1 = [...]"some text to include in another file as string 1", length = 48}
|
// check:$1 = 48
|
||||||
// debugger:print string2
|
// debugger:print string2.length
|
||||||
// check:$2 = [...]"some text to include in another file as string 2", length = 48}
|
// check:$2 = 48
|
||||||
// debugger:print string3
|
// debugger:print string3.length
|
||||||
// check:$3 = [...]"some text to include in another file as string 3", length = 48}
|
// check:$3 = 48
|
||||||
// debugger:continue
|
// debugger:continue
|
||||||
|
|
||||||
#[allow(unused_variable)];
|
#[allow(unused_variable)];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user