From 3feaecd757241b7b5efd742108abe351ff8d497d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 17 Nov 2011 14:32:45 -0800 Subject: [PATCH] intrinsics: Move the call to upcall_fail out of rust_intrinsic_cast --- src/lib/unsafe.rs | 9 ++++++++- src/rt/intrinsics/intrinsics.cpp | 11 ++--------- src/rt/intrinsics/intrinsics.i386.ll.in | 20 +------------------- src/rt/intrinsics/intrinsics.x86_64.ll.in | 20 +------------------- 4 files changed, 12 insertions(+), 48 deletions(-) diff --git a/src/lib/unsafe.rs b/src/lib/unsafe.rs index 0162c10ea22b..22cce4956498 100644 --- a/src/lib/unsafe.rs +++ b/src/lib/unsafe.rs @@ -19,7 +19,14 @@ Function: reinterpret_cast Casts the value at `src` to U. The two types must have the same length. */ -unsafe fn reinterpret_cast(src: T) -> U { ret rusti::cast(src); } +unsafe fn reinterpret_cast(src: T) -> U { + let t1 = sys::get_type_desc::(); + let t2 = sys::get_type_desc::(); + if (*t1).size != (*t2).size { + fail "attempt to cast values of differing sizes"; + } + ret rusti::cast(src); +} /* Function: leak diff --git a/src/rt/intrinsics/intrinsics.cpp b/src/rt/intrinsics/intrinsics.cpp index 504fa0832485..82346948afdc 100644 --- a/src/rt/intrinsics/intrinsics.cpp +++ b/src/rt/intrinsics/intrinsics.cpp @@ -6,9 +6,6 @@ #include #include -extern "C" CDECL void -upcall_fail(char const *expr, char const *file, size_t line); - extern "C" CDECL void port_recv(uintptr_t *dptr, rust_port *port); @@ -41,12 +38,8 @@ rust_intrinsic_cast(void *retptr, type_desc *t2, void *src) { - if (t1->size != t2->size) { - upcall_fail("attempt to cast values of differing sizes", - __FILE__, __LINE__); - return; - } - + // assert t1->size == t2->size + // FIXME: This should be easily expressible in rust memmove(retptr, src, t1->size); } diff --git a/src/rt/intrinsics/intrinsics.i386.ll.in b/src/rt/intrinsics/intrinsics.i386.ll.in index b85b8e1e1016..47ac0bbd578b 100644 --- a/src/rt/intrinsics/intrinsics.i386.ll.in +++ b/src/rt/intrinsics/intrinsics.i386.ll.in @@ -57,9 +57,6 @@ target triple = "@CFG_TARGET_TRIPLE@" %"struct.hash_map::map_entry" = type opaque %class.circular_buffer = type { %class.rust_kernel*, i32, i32, i32, i32, i8* } -@.str = private unnamed_addr constant [42 x i8] c"attempt to cast values of differing sizes\00", align 1 -@.str1 = private unnamed_addr constant [33 x i8] c"src/rt/intrinsics/intrinsics.cpp\00", align 1 - define void @rust_intrinsic_vec_len(i32* nocapture %retptr, i8* nocapture %env, %struct.type_desc* nocapture %ty, %struct.rust_vec** nocapture %vp) nounwind { %1 = load %struct.rust_vec** %vp, align 4, !tbaa !0 %2 = getelementptr inbounds %struct.rust_vec* %1, i32 0, i32 0 @@ -80,28 +77,13 @@ define void @rust_intrinsic_ptr_offset(i8** nocapture %retptr, i8* nocapture %en ret void } -define void @rust_intrinsic_cast(i8* nocapture %retptr, i8* nocapture %env, %struct.type_desc* nocapture %t1, %struct.type_desc* nocapture %t2, i8* nocapture %src) { +define void @rust_intrinsic_cast(i8* nocapture %retptr, i8* nocapture %env, %struct.type_desc* nocapture %t1, %struct.type_desc* nocapture %t2, i8* nocapture %src) nounwind { %1 = getelementptr inbounds %struct.type_desc* %t1, i32 0, i32 1 %2 = load i32* %1, align 4, !tbaa !3 - %3 = getelementptr inbounds %struct.type_desc* %t2, i32 0, i32 1 - %4 = load i32* %3, align 4, !tbaa !3 - %5 = icmp eq i32 %2, %4 - br i1 %5, label %7, label %6 - -;