@@ -2362,9 +2362,8 @@ fn make_cmp_glue(&@block_ctxt cx, ValueRef lhs0, ValueRef rhs0, &ty::t t,
2362
2362
rhs_fill = vec_fill( scx, rhs) ;
2363
2363
bcx = scx;
2364
2364
}
2365
- r =
2366
- compare_numerical_values( bcx, lhs_fill, rhs_fill,
2367
- unsigned_int, llop) ;
2365
+ r = compare_scalar_values( bcx, lhs_fill, rhs_fill,
2366
+ unsigned_int, llop) ;
2368
2367
r. bcx. build. Store ( r. val, flag) ;
2369
2368
} else {
2370
2369
// == and <= default to true if they find == all the way. <
@@ -2441,18 +2440,18 @@ fn make_cmp_glue(&@block_ctxt cx, ValueRef lhs0, ValueRef rhs0, &ty::t t,
2441
2440
2442
2441
2443
2442
// Used only for creating scalar comparsion glue.
2444
- tag numerical_type { signed_int; unsigned_int; floating_point; }
2443
+ tag scalar_type { nil_type ; signed_int; unsigned_int; floating_point; }
2445
2444
2446
2445
2447
2446
fn compare_scalar_types( @block_ctxt cx, ValueRef lhs, ValueRef rhs, & ty:: t t,
2448
2447
ValueRef llop) -> result {
2449
2448
// FIXME: this could be a lot shorter if we could combine multiple cases
2450
2449
// of alt expressions (issue #449).
2451
2450
2452
- auto f = bind compare_numerical_values ( cx, lhs, rhs, _, llop) ;
2451
+ auto f = bind compare_scalar_values ( cx, lhs, rhs, _, llop) ;
2453
2452
2454
2453
alt ( ty:: struct ( cx. fcx. lcx. ccx. tcx, t) ) {
2455
- case ( ty:: ty_nil) { ret rslt ( cx , C_bool ( true ) ) ; }
2454
+ case ( ty:: ty_nil) { ret f ( nil_type ) ; }
2456
2455
case ( ty:: ty_bool) { ret f( unsigned_int) ; }
2457
2456
case ( ty:: ty_int) { ret f( signed_int) ; }
2458
2457
case ( ty:: ty_float) { ret f( floating_point) ; }
@@ -2514,13 +2513,20 @@ fn make_scalar_cmp_glue(&@block_ctxt cx, ValueRef lhs, ValueRef rhs, &ty::t t,
2514
2513
}
2515
2514
2516
2515
2517
- // A helper function to compare numerical values.
2518
- fn compare_numerical_values ( & @block_ctxt cx, ValueRef lhs, ValueRef rhs,
2519
- numerical_type nt, ValueRef llop) -> result {
2516
+ // A helper function to do the actual comparison of scalar values.
2517
+ fn compare_scalar_values ( & @block_ctxt cx, ValueRef lhs, ValueRef rhs,
2518
+ scalar_type nt, ValueRef llop) -> result {
2520
2519
auto eq_cmp;
2521
2520
auto lt_cmp;
2522
2521
auto le_cmp;
2523
2522
alt ( nt) {
2523
+ case ( nil_type) {
2524
+ // We don't need to do actual comparisons for nil.
2525
+ // () == () holds but () < () does not.
2526
+ eq_cmp = 1 u;
2527
+ lt_cmp = 0 u;
2528
+ le_cmp = 1 u;
2529
+ }
2524
2530
case ( floating_point) {
2525
2531
eq_cmp = lib:: llvm:: LLVMRealUEQ ;
2526
2532
lt_cmp = lib:: llvm:: LLVMRealULT ;
@@ -2543,10 +2549,12 @@ fn compare_numerical_values(&@block_ctxt cx, ValueRef lhs, ValueRef rhs,
2543
2549
// the above, and "auto eq_result = cmp_fn(eq_cmp, lhs, rhs);" in the
2544
2550
// below.
2545
2551
2546
- fn generic_cmp( & @block_ctxt cx, numerical_type nt, uint op, ValueRef lhs,
2552
+ fn generic_cmp( & @block_ctxt cx, scalar_type nt, uint op, ValueRef lhs,
2547
2553
ValueRef rhs) -> ValueRef {
2548
2554
let ValueRef r;
2549
- if ( nt == floating_point) {
2555
+ if ( nt == nil_type) {
2556
+ r = C_bool ( op != 0 u) ;
2557
+ } else if ( nt == floating_point) {
2550
2558
r = cx. build. FCmp ( op, lhs, rhs) ;
2551
2559
} else { r = cx. build. ICmp ( op, lhs, rhs) ; }
2552
2560
ret r;
@@ -2573,16 +2581,6 @@ fn compare_numerical_values(&@block_ctxt cx, ValueRef lhs, ValueRef rhs,
2573
2581
ret rslt( last_cx, last_result) ;
2574
2582
}
2575
2583
2576
-
2577
- // A helper function to create numerical comparison glue.
2578
- fn make_numerical_cmp_glue( & @block_ctxt cx, ValueRef lhs, ValueRef rhs,
2579
- numerical_type nt, ValueRef llop) {
2580
- auto r = compare_numerical_values( cx, lhs, rhs, nt, llop) ;
2581
- r. bcx. build. Store ( r. val, r. bcx. fcx. llretptr) ;
2582
- r. bcx. build. RetVoid ( ) ;
2583
- }
2584
-
2585
-
2586
2584
type val_pair_fn = fn ( & @block_ctxt, ValueRef , ValueRef ) -> result ;
2587
2585
2588
2586
type val_and_ty_fn = fn ( & @block_ctxt, ValueRef , ty:: t) -> result ;
0 commit comments