Skip to content

Commit 4d71712

Browse files
committed
Fix LLVM assert when handling bad intrinsic monomorphizations
1 parent 30a3849 commit 4d71712

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/librustc_trans/intrinsic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
658658
tcx.sess, span,
659659
&format!("invalid monomorphization of `{}` intrinsic: \
660660
expected basic integer type, found `{}`", name, sty));
661-
C_null(llret_ty)
661+
C_nil(ccx)
662662
}
663663
}
664664

@@ -681,7 +681,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
681681
tcx.sess, span,
682682
&format!("invalid monomorphization of `{}` intrinsic: \
683683
expected basic float type, found `{}`", name, sty));
684-
C_null(llret_ty)
684+
C_nil(ccx)
685685
}
686686
}
687687

@@ -1454,7 +1454,7 @@ fn generic_simd_intrinsic<'blk, 'tcx, 'a>
14541454
($cond: expr, $($fmt: tt)*) => {
14551455
if !$cond {
14561456
emit_error!($($fmt)*);
1457-
return C_null(llret_ty)
1457+
return C_nil(bcx.ccx())
14581458
}
14591459
}
14601460
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(repr_simd, platform_intrinsics, rustc_attrs, core_intrinsics)]
12+
#![allow(warnings)]
13+
14+
// Bad monomorphizations could previously cause LLVM asserts even though the
15+
// error was caught in the compiler.
16+
17+
extern "platform-intrinsic" {
18+
fn simd_add<T>(x: T, y: T) -> T;
19+
}
20+
21+
use std::intrinsics;
22+
23+
#[derive(Copy, Clone)]
24+
struct Foo(i64);
25+
26+
#[rustc_no_mir] // FIXME #27840 MIR doesn't provide precise spans for calls.
27+
unsafe fn test_cttz(v: Foo) -> Foo {
28+
intrinsics::cttz(v)
29+
//~^ ERROR `cttz` intrinsic: expected basic integer type, found `Foo`
30+
}
31+
32+
#[rustc_no_mir] // FIXME #27840 MIR doesn't provide precise spans for calls.
33+
unsafe fn test_fadd_fast(a: Foo, b: Foo) -> Foo {
34+
intrinsics::fadd_fast(a, b)
35+
//~^ ERROR `fadd_fast` intrinsic: expected basic float type, found `Foo`
36+
}
37+
38+
#[rustc_no_mir] // FIXME #27840 MIR doesn't provide precise spans for calls.
39+
unsafe fn test_simd_add(a: Foo, b: Foo) -> Foo {
40+
simd_add(a, b)
41+
//~^ ERROR `simd_add` intrinsic: expected SIMD input type, found non-SIMD `Foo`
42+
}
43+
44+
fn main() {}

0 commit comments

Comments
 (0)