@@ -14,16 +14,15 @@ use middle::lang_items::{FailFnLangItem, FailBoundsCheckFnLangItem};
1414use middle:: trans:: base:: * ;
1515use middle:: trans:: build:: * ;
1616use middle:: trans:: callee;
17+ use middle:: trans:: cleanup:: CleanupMethods ;
18+ use middle:: trans:: cleanup;
1719use middle:: trans:: common:: * ;
1820use middle:: trans:: debuginfo;
19- use middle:: trans:: cleanup;
20- use middle:: trans:: cleanup:: CleanupMethods ;
2121use middle:: trans:: expr;
22+ use middle:: trans:: type_of;
2223use middle:: ty;
2324use util:: ppaux:: Repr ;
2425
25- use middle:: trans:: type_:: Type ;
26-
2726use syntax:: ast;
2827use syntax:: ast:: Ident ;
2928use syntax:: ast_util;
@@ -337,23 +336,31 @@ pub fn trans_ret<'a>(bcx: &'a Block<'a>,
337336 return bcx;
338337}
339338
339+ fn str_slice_arg < ' a > ( bcx : & ' a Block < ' a > , s : InternedString ) -> ValueRef {
340+ let ccx = bcx. ccx ( ) ;
341+ let t = ty:: mk_str_slice ( bcx. tcx ( ) , ty:: ReStatic , ast:: MutImmutable ) ;
342+ let s = C_str_slice ( ccx, s) ;
343+ let slot = alloca ( bcx, val_ty ( s) , "__temp" ) ;
344+ Store ( bcx, s, slot) ;
345+
346+ // The type of C_str_slice is { i8*, i64 }, but the type of the &str is
347+ // %str_slice, so we do a bitcast here to the right type.
348+ BitCast ( bcx, slot, type_of:: type_of ( ccx, t) . ptr_to ( ) )
349+ }
350+
340351pub fn trans_fail < ' a > (
341352 bcx : & ' a Block < ' a > ,
342353 sp : Span ,
343354 fail_str : InternedString )
344355 -> & ' a Block < ' a > {
345356 let ccx = bcx. ccx ( ) ;
346- let v_fail_str = C_cstr ( ccx, fail_str, true ) ;
347357 let _icx = push_ctxt ( "trans_fail_value" ) ;
358+
359+ let v_str = str_slice_arg ( bcx, fail_str) ;
348360 let loc = bcx. sess ( ) . codemap ( ) . lookup_char_pos ( sp. lo ) ;
349- let v_filename = C_cstr ( ccx,
350- token:: intern_and_get_ident ( loc. file
351- . name
352- . as_slice ( ) ) ,
353- true ) ;
361+ let filename = token:: intern_and_get_ident ( loc. file . name . as_slice ( ) ) ;
362+ let v_filename = str_slice_arg ( bcx, filename) ;
354363 let v_line = loc. line as int ;
355- let v_str = PointerCast ( bcx, v_fail_str, Type :: i8p ( ccx) ) ;
356- let v_filename = PointerCast ( bcx, v_filename, Type :: i8p ( ccx) ) ;
357364 let args = vec ! ( v_str, v_filename, C_int ( ccx, v_line) ) ;
358365 let did = langcall ( bcx, Some ( sp) , "" , FailFnLangItem ) ;
359366 let bcx = callee:: trans_lang_call ( bcx,
@@ -371,7 +378,14 @@ pub fn trans_fail_bounds_check<'a>(
371378 len : ValueRef )
372379 -> & ' a Block < ' a > {
373380 let _icx = push_ctxt ( "trans_fail_bounds_check" ) ;
374- let ( filename, line) = filename_and_line_num_from_span ( bcx, sp) ;
381+
382+ // Extract the file/line from the span
383+ let loc = bcx. sess ( ) . codemap ( ) . lookup_char_pos ( sp. lo ) ;
384+ let filename = token:: intern_and_get_ident ( loc. file . name . as_slice ( ) ) ;
385+
386+ // Invoke the lang item
387+ let filename = str_slice_arg ( bcx, filename) ;
388+ let line = C_int ( bcx. ccx ( ) , loc. line as int ) ;
375389 let args = vec ! ( filename, line, index, len) ;
376390 let did = langcall ( bcx, Some ( sp) , "" , FailBoundsCheckFnLangItem ) ;
377391 let bcx = callee:: trans_lang_call ( bcx,
0 commit comments