Skip to content

Commit 132b766

Browse files
nikomatsakisbrson
authored andcommitted
---
yaml --- r: 5793 b: refs/heads/master c: d4d7eb0 h: refs/heads/master i: 5791: 21d98f3 v: v3
1 parent 5f3220b commit 132b766

File tree

8 files changed

+129
-77
lines changed

8 files changed

+129
-77
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: c1cefa52d01bb9a1ff55e76da8320641040d79cc
2+
refs/heads/master: d4d7eb069b1a9299605bdfd513917fa9a0981702

trunk/src/comp/back/link.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ tag output_type {
3535
}
3636

3737
fn llvm_err(sess: session::session, msg: str) {
38-
let buf = llvm::LLVMRustGetLastError();
39-
if buf == std::ptr::null() {
40-
sess.fatal(msg);
41-
} else { sess.fatal(msg + ": " + str::str_from_cstr(buf)); }
38+
unsafe {
39+
let buf = llvm::LLVMRustGetLastError();
40+
if buf == std::ptr::null() {
41+
sess.fatal(msg);
42+
} else { sess.fatal(msg + ": " + str::str_from_cstr(buf)); }
43+
}
4244
}
4345

4446
fn link_intrinsics(sess: session::session, llmod: ModuleRef) {

trunk/src/comp/lib/llvm.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,9 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
961961
let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
962962
let n_args: uint = llvm::LLVMCountParamTypes(ty);
963963
let args: [TypeRef] = vec::init_elt::<TypeRef>(0 as TypeRef, n_args);
964-
llvm::LLVMGetParamTypes(ty, vec::to_ptr(args));
964+
unsafe {
965+
llvm::LLVMGetParamTypes(ty, vec::to_ptr(args));
966+
}
965967
s += tys_str(names, outer, args);
966968
s += ") -> ";
967969
s += type_to_str_inner(names, outer, out_ty);
@@ -971,7 +973,9 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
971973
let s: str = "{";
972974
let n_elts: uint = llvm::LLVMCountStructElementTypes(ty);
973975
let elts: [TypeRef] = vec::init_elt::<TypeRef>(0 as TypeRef, n_elts);
974-
llvm::LLVMGetStructElementTypes(ty, vec::to_ptr(elts));
976+
unsafe {
977+
llvm::LLVMGetStructElementTypes(ty, vec::to_ptr(elts));
978+
}
975979
s += tys_str(names, outer, elts);
976980
s += "}";
977981
ret s;
@@ -1011,7 +1015,9 @@ fn float_width(llt: TypeRef) -> uint {
10111015

10121016
fn fn_ty_param_tys(fn_ty: TypeRef) -> [TypeRef] {
10131017
let args = vec::init_elt(0 as TypeRef, llvm::LLVMCountParamTypes(fn_ty));
1014-
llvm::LLVMGetParamTypes(fn_ty, vec::to_ptr(args));
1018+
unsafe {
1019+
llvm::LLVMGetParamTypes(fn_ty, vec::to_ptr(args));
1020+
}
10151021
ret args;
10161022
}
10171023

trunk/src/comp/metadata/creader.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,26 @@ fn find_library_crate_aux(nn: {prefix: str, suffix: str}, crate_name: str,
170170
}
171171

172172
fn get_metadata_section(filename: str) -> option::t<@[u8]> {
173-
let mb = str::as_buf(filename, {|buf|
174-
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
175-
});
176-
if mb as int == 0 { ret option::none::<@[u8]>; }
177-
let of = mk_object_file(mb);
178-
let si = mk_section_iter(of.llof);
179-
while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
180-
let name_buf = llvm::LLVMGetSectionName(si.llsi);
181-
let name = str::str_from_cstr(name_buf);
182-
if str::eq(name, x86::get_meta_sect_name()) {
183-
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
184-
let csz = llvm::LLVMGetSectionSize(si.llsi);
185-
let cvbuf: *u8 = std::unsafe::reinterpret_cast(cbuf);
186-
ret option::some::<@[u8]>(@vec::unsafe::from_buf(cvbuf, csz));
173+
unsafe {
174+
let mb = str::as_buf(filename, {|buf|
175+
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
176+
});
177+
if mb as int == 0 { ret option::none::<@[u8]>; }
178+
let of = mk_object_file(mb);
179+
let si = mk_section_iter(of.llof);
180+
while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
181+
let name_buf = llvm::LLVMGetSectionName(si.llsi);
182+
let name = str::str_from_cstr(name_buf);
183+
if str::eq(name, x86::get_meta_sect_name()) {
184+
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
185+
let csz = llvm::LLVMGetSectionSize(si.llsi);
186+
let cvbuf: *u8 = std::unsafe::reinterpret_cast(cbuf);
187+
ret option::some::<@[u8]>(@vec::unsafe::from_buf(cvbuf, csz));
188+
}
189+
llvm::LLVMMoveToNextSection(si.llsi);
187190
}
188-
llvm::LLVMMoveToNextSection(si.llsi);
191+
ret option::none::<@[u8]>;
189192
}
190-
ret option::none::<@[u8]>;
191193
}
192194

193195
fn load_library_crate(sess: session::session, span: span, ident: ast::ident,

trunk/src/comp/middle/trans_build.rs

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ fn AggregateRet(cx: @block_ctxt, RetVals: [ValueRef]) {
3737
if cx.unreachable { ret; }
3838
assert (!cx.terminated);
3939
cx.terminated = true;
40-
llvm::LLVMBuildAggregateRet(B(cx), vec::to_ptr(RetVals),
41-
vec::len(RetVals));
40+
unsafe {
41+
llvm::LLVMBuildAggregateRet(B(cx), vec::to_ptr(RetVals),
42+
vec::len(RetVals));
43+
}
4244
}
4345

4446
fn Br(cx: @block_ctxt, Dest: BasicBlockRef) {
@@ -88,18 +90,22 @@ fn Invoke(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef],
8890
if cx.unreachable { ret; }
8991
assert (!cx.terminated);
9092
cx.terminated = true;
91-
llvm::LLVMBuildInvoke(B(cx), Fn, vec::to_ptr(Args),
92-
vec::len(Args), Then, Catch, noname());
93+
unsafe {
94+
llvm::LLVMBuildInvoke(B(cx), Fn, vec::to_ptr(Args),
95+
vec::len(Args), Then, Catch, noname());
96+
}
9397
}
9498

9599
fn FastInvoke(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef],
96100
Then: BasicBlockRef, Catch: BasicBlockRef) {
97101
if cx.unreachable { ret; }
98102
assert (!cx.terminated);
99103
cx.terminated = true;
100-
let v = llvm::LLVMBuildInvoke(B(cx), Fn, vec::to_ptr(Args),
101-
vec::len(Args), Then, Catch, noname());
102-
llvm::LLVMSetInstructionCallConv(v, lib::llvm::LLVMFastCallConv);
104+
unsafe {
105+
let v = llvm::LLVMBuildInvoke(B(cx), Fn, vec::to_ptr(Args),
106+
vec::len(Args), Then, Catch, noname());
107+
llvm::LLVMSetInstructionCallConv(v, lib::llvm::LLVMFastCallConv);
108+
}
103109
}
104110

105111
fn Unreachable(cx: @block_ctxt) {
@@ -311,15 +317,19 @@ fn Store(cx: @block_ctxt, Val: ValueRef, Ptr: ValueRef) {
311317

312318
fn GEP(cx: @block_ctxt, Pointer: ValueRef, Indices: [ValueRef]) -> ValueRef {
313319
if cx.unreachable { ret llvm::LLVMGetUndef(T_ptr(T_nil())); }
314-
ret llvm::LLVMBuildGEP(B(cx), Pointer, vec::to_ptr(Indices),
315-
vec::len(Indices), noname());
320+
unsafe {
321+
ret llvm::LLVMBuildGEP(B(cx), Pointer, vec::to_ptr(Indices),
322+
vec::len(Indices), noname());
323+
}
316324
}
317325

318326
fn InBoundsGEP(cx: @block_ctxt, Pointer: ValueRef, Indices: [ValueRef]) ->
319327
ValueRef {
320328
if cx.unreachable { ret llvm::LLVMGetUndef(T_ptr(T_nil())); }
321-
ret llvm::LLVMBuildInBoundsGEP(B(cx), Pointer, vec::to_ptr(Indices),
322-
vec::len(Indices), noname());
329+
unsafe {
330+
ret llvm::LLVMBuildInBoundsGEP(B(cx), Pointer, vec::to_ptr(Indices),
331+
vec::len(Indices), noname());
332+
}
323333
}
324334

325335
fn StructGEP(cx: @block_ctxt, Pointer: ValueRef, Idx: uint) -> ValueRef {
@@ -460,9 +470,11 @@ fn Phi(cx: @block_ctxt, Ty: TypeRef, vals: [ValueRef], bbs: [BasicBlockRef])
460470
if cx.unreachable { ret llvm::LLVMGetUndef(Ty); }
461471
assert (vec::len::<ValueRef>(vals) == vec::len::<BasicBlockRef>(bbs));
462472
let phi = EmptyPhi(cx, Ty);
463-
llvm::LLVMAddIncoming(phi, vec::to_ptr(vals), vec::to_ptr(bbs),
464-
vec::len(vals));
465-
ret phi;
473+
unsafe {
474+
llvm::LLVMAddIncoming(phi, vec::to_ptr(vals), vec::to_ptr(bbs),
475+
vec::len(vals));
476+
ret phi;
477+
}
466478
}
467479

468480
fn AddIncomingToPhi(phi: ValueRef, val: ValueRef, bb: BasicBlockRef) {
@@ -480,26 +492,32 @@ fn _UndefReturn(Fn: ValueRef) -> ValueRef {
480492
}
481493

482494
fn Call(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef]) -> ValueRef {
483-
if cx.unreachable { ret _UndefReturn(Fn); }
484-
ret llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
485-
vec::len(Args), noname());
495+
unsafe {
496+
if cx.unreachable { ret _UndefReturn(Fn); }
497+
ret llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
498+
vec::len(Args), noname());
499+
}
486500
}
487501

488502
fn FastCall(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef]) -> ValueRef {
489-
if cx.unreachable { ret _UndefReturn(Fn); }
490-
let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
491-
vec::len(Args), noname());
492-
llvm::LLVMSetInstructionCallConv(v, lib::llvm::LLVMFastCallConv);
493-
ret v;
503+
unsafe {
504+
if cx.unreachable { ret _UndefReturn(Fn); }
505+
let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
506+
vec::len(Args), noname());
507+
llvm::LLVMSetInstructionCallConv(v, lib::llvm::LLVMFastCallConv);
508+
ret v;
509+
}
494510
}
495511

496512
fn CallWithConv(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef], Conv: uint)
497513
-> ValueRef {
498-
if cx.unreachable { ret _UndefReturn(Fn); }
499-
let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
500-
vec::len(Args), noname());
501-
llvm::LLVMSetInstructionCallConv(v, Conv);
502-
ret v;
514+
unsafe {
515+
if cx.unreachable { ret _UndefReturn(Fn); }
516+
let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
517+
vec::len(Args), noname());
518+
llvm::LLVMSetInstructionCallConv(v, Conv);
519+
ret v;
520+
}
503521
}
504522

505523
fn Select(cx: @block_ctxt, If: ValueRef, Then: ValueRef, Else: ValueRef) ->
@@ -568,7 +586,10 @@ fn Trap(cx: @block_ctxt) {
568586
});
569587
assert (T as int != 0);
570588
let Args: [ValueRef] = [];
571-
llvm::LLVMBuildCall(b, T, vec::to_ptr(Args), vec::len(Args), noname());
589+
unsafe {
590+
llvm::LLVMBuildCall(b, T, vec::to_ptr(Args),
591+
vec::len(Args), noname());
592+
}
572593
}
573594

574595
fn LandingPad(cx: @block_ctxt, Ty: TypeRef, PersFn: ValueRef,

trunk/src/comp/middle/trans_common.rs

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,10 @@ fn T_size_t() -> TypeRef {
518518
}
519519

520520
fn T_fn(inputs: [TypeRef], output: TypeRef) -> TypeRef {
521-
ret llvm::LLVMFunctionType(output, to_ptr(inputs),
522-
std::vec::len::<TypeRef>(inputs), False);
521+
unsafe {
522+
ret llvm::LLVMFunctionType(output, to_ptr(inputs),
523+
std::vec::len::<TypeRef>(inputs), False);
524+
}
523525
}
524526

525527
fn T_fn_pair(cx: crate_ctxt, tfn: TypeRef) -> TypeRef {
@@ -529,7 +531,9 @@ fn T_fn_pair(cx: crate_ctxt, tfn: TypeRef) -> TypeRef {
529531
fn T_ptr(t: TypeRef) -> TypeRef { ret llvm::LLVMPointerType(t, 0u); }
530532

531533
fn T_struct(elts: [TypeRef]) -> TypeRef {
532-
ret llvm::LLVMStructType(to_ptr(elts), std::vec::len(elts), False);
534+
unsafe {
535+
ret llvm::LLVMStructType(to_ptr(elts), std::vec::len(elts), False);
536+
}
533537
}
534538

535539
fn T_named_struct(name: str) -> TypeRef {
@@ -538,7 +542,9 @@ fn T_named_struct(name: str) -> TypeRef {
538542
}
539543

540544
fn set_struct_body(t: TypeRef, elts: [TypeRef]) {
541-
llvm::LLVMStructSetBody(t, to_ptr(elts), std::vec::len(elts), False);
545+
unsafe {
546+
llvm::LLVMStructSetBody(t, to_ptr(elts), std::vec::len(elts), False);
547+
}
542548
}
543549

544550
fn T_empty_struct() -> TypeRef { ret T_struct([]); }
@@ -578,12 +584,15 @@ fn T_task() -> TypeRef {
578584
fn T_tydesc_field(cx: crate_ctxt, field: int) -> TypeRef {
579585
// Bit of a kludge: pick the fn typeref out of the tydesc..
580586

581-
let tydesc_elts: [TypeRef] =
582-
std::vec::init_elt::<TypeRef>(T_nil(), abi::n_tydesc_fields as uint);
583-
llvm::LLVMGetStructElementTypes(cx.tydesc_type,
584-
to_ptr::<TypeRef>(tydesc_elts));
585-
let t = llvm::LLVMGetElementType(tydesc_elts[field]);
586-
ret t;
587+
unsafe {
588+
let tydesc_elts: [TypeRef] =
589+
std::vec::init_elt::<TypeRef>(T_nil(),
590+
abi::n_tydesc_fields as uint);
591+
llvm::LLVMGetStructElementTypes(cx.tydesc_type,
592+
to_ptr::<TypeRef>(tydesc_elts));
593+
let t = llvm::LLVMGetElementType(tydesc_elts[field]);
594+
ret t;
595+
}
587596
}
588597

589598
fn T_glue_fn(cx: crate_ctxt) -> TypeRef {
@@ -790,30 +799,42 @@ fn C_postr(s: str) -> ValueRef {
790799
}
791800

792801
fn C_zero_byte_arr(size: uint) -> ValueRef {
793-
let i = 0u;
794-
let elts: [ValueRef] = [];
795-
while i < size { elts += [C_u8(0u)]; i += 1u; }
796-
ret llvm::LLVMConstArray(T_i8(), std::vec::to_ptr(elts),
797-
std::vec::len(elts));
802+
unsafe {
803+
let i = 0u;
804+
let elts: [ValueRef] = [];
805+
while i < size { elts += [C_u8(0u)]; i += 1u; }
806+
ret llvm::LLVMConstArray(T_i8(), std::vec::to_ptr(elts),
807+
std::vec::len(elts));
808+
}
798809
}
799810

800811
fn C_struct(elts: [ValueRef]) -> ValueRef {
801-
ret llvm::LLVMConstStruct(std::vec::to_ptr(elts), std::vec::len(elts),
802-
False);
812+
unsafe {
813+
ret llvm::LLVMConstStruct(std::vec::to_ptr(elts), std::vec::len(elts),
814+
False);
815+
}
803816
}
804817

805818
fn C_named_struct(T: TypeRef, elts: [ValueRef]) -> ValueRef {
806-
ret llvm::LLVMConstNamedStruct(T, std::vec::to_ptr(elts),
807-
std::vec::len(elts));
819+
unsafe {
820+
ret llvm::LLVMConstNamedStruct(T, std::vec::to_ptr(elts),
821+
std::vec::len(elts));
822+
}
808823
}
809824

810825
fn C_array(ty: TypeRef, elts: [ValueRef]) -> ValueRef {
811-
ret llvm::LLVMConstArray(ty, std::vec::to_ptr(elts), std::vec::len(elts));
826+
unsafe {
827+
ret llvm::LLVMConstArray(ty, std::vec::to_ptr(elts),
828+
std::vec::len(elts));
829+
}
812830
}
813831

814832
fn C_bytes(bytes: [u8]) -> ValueRef {
815-
ret llvm::LLVMConstString(unsafe::reinterpret_cast(vec::to_ptr(bytes)),
816-
vec::len(bytes), False);
833+
unsafe {
834+
ret llvm::LLVMConstString(
835+
unsafe::reinterpret_cast(vec::to_ptr(bytes)),
836+
vec::len(bytes), False);
837+
}
817838
}
818839

819840
fn C_shape(ccx: @crate_ctxt, bytes: [u8]) -> ValueRef {

trunk/src/test/stdtest/str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ fn unsafe_from_bytes() {
256256
}
257257

258258
#[test]
259-
fn str_from_cstr() {
259+
unsafe fn str_from_cstr() {
260260
let a = [65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8];
261261
let b = vec::to_ptr(a);
262262
let c = str::str_from_cstr(b);
@@ -278,7 +278,7 @@ fn as_buf_small() {
278278
}
279279

280280
#[test]
281-
fn as_buf2() {
281+
unsafe fn as_buf2() {
282282
let s = "hello";
283283
let sb = str::as_buf(s, {|b| b });
284284
let s_cstr = str::str_from_cstr(sb);

trunk/src/test/stdtest/vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn square_if_odd(&&n: uint) -> option::t<uint> {
2121
fn add(&&x: uint, &&y: uint) -> uint { ret x + y; }
2222

2323
#[test]
24-
fn test_unsafe_ptrs() {
24+
unsafe fn test_unsafe_ptrs() {
2525
// Test on-stack copy-from-buf.
2626
let a = [1, 2, 3];
2727
let ptr = vec::to_ptr(a);

0 commit comments

Comments
 (0)