Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0f7d73e

Browse files
committedApr 6, 2016
Rollup merge of rust-lang#32649 - Amanieu:intrinsic_monomorphization_assert, r=eddyb
Fix LLVM assert when handling bad intrinsic monomorphizations Passing an invalid type to certain intrinsics would trigger an LLVM assert even though the invalid type was caught by the compiler. r? @eddyb
2 parents e9774e7 + ecc0bd2 commit 0f7d73e

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-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

@@ -1475,7 +1475,7 @@ fn generic_simd_intrinsic<'blk, 'tcx, 'a>
14751475
($cond: expr, $($fmt: tt)*) => {
14761476
if !$cond {
14771477
emit_error!($($fmt)*);
1478-
return C_null(llret_ty)
1478+
return C_nil(bcx.ccx())
14791479
}
14801480
}
14811481
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
unsafe fn test_cttz(v: Foo) -> Foo {
27+
intrinsics::cttz(v)
28+
//~^ ERROR `cttz` intrinsic: expected basic integer type, found `Foo`
29+
}
30+
31+
unsafe fn test_fadd_fast(a: Foo, b: Foo) -> Foo {
32+
intrinsics::fadd_fast(a, b)
33+
//~^ ERROR `fadd_fast` intrinsic: expected basic float type, found `Foo`
34+
}
35+
36+
unsafe fn test_simd_add(a: Foo, b: Foo) -> Foo {
37+
simd_add(a, b)
38+
//~^ ERROR `simd_add` intrinsic: expected SIMD input type, found non-SIMD `Foo`
39+
}
40+
41+
fn main() {}

0 commit comments

Comments
 (0)
Please sign in to comment.