@@ -14,16 +14,15 @@ use middle::lang_items::{FailFnLangItem, FailBoundsCheckFnLangItem};
14
14
use middle:: trans:: base:: * ;
15
15
use middle:: trans:: build:: * ;
16
16
use middle:: trans:: callee;
17
+ use middle:: trans:: cleanup:: CleanupMethods ;
18
+ use middle:: trans:: cleanup;
17
19
use middle:: trans:: common:: * ;
18
20
use middle:: trans:: debuginfo;
19
- use middle:: trans:: cleanup;
20
- use middle:: trans:: cleanup:: CleanupMethods ;
21
21
use middle:: trans:: expr;
22
+ use middle:: trans:: type_of;
22
23
use middle:: ty;
23
24
use util:: ppaux:: Repr ;
24
25
25
- use middle:: trans:: type_:: Type ;
26
-
27
26
use syntax:: ast;
28
27
use syntax:: ast:: Ident ;
29
28
use syntax:: ast_util;
@@ -337,23 +336,31 @@ pub fn trans_ret<'a>(bcx: &'a Block<'a>,
337
336
return bcx;
338
337
}
339
338
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
+
340
351
pub fn trans_fail < ' a > (
341
352
bcx : & ' a Block < ' a > ,
342
353
sp : Span ,
343
354
fail_str : InternedString )
344
355
-> & ' a Block < ' a > {
345
356
let ccx = bcx. ccx ( ) ;
346
- let v_fail_str = C_cstr ( ccx, fail_str, true ) ;
347
357
let _icx = push_ctxt ( "trans_fail_value" ) ;
358
+
359
+ let v_str = str_slice_arg ( bcx, fail_str) ;
348
360
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) ;
354
363
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) ) ;
357
364
let args = vec ! ( v_str, v_filename, C_int ( ccx, v_line) ) ;
358
365
let did = langcall ( bcx, Some ( sp) , "" , FailFnLangItem ) ;
359
366
let bcx = callee:: trans_lang_call ( bcx,
@@ -371,7 +378,14 @@ pub fn trans_fail_bounds_check<'a>(
371
378
len : ValueRef )
372
379
-> & ' a Block < ' a > {
373
380
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 ) ;
375
389
let args = vec ! ( filename, line, index, len) ;
376
390
let did = langcall ( bcx, Some ( sp) , "" , FailBoundsCheckFnLangItem ) ;
377
391
let bcx = callee:: trans_lang_call ( bcx,
0 commit comments