Skip to content

Commit

Permalink
Add librustc_trans error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Sep 19, 2015
1 parent 7badafa commit 1adcfb8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/librustc_borrowck/diagnostics.rs
Expand Up @@ -289,7 +289,7 @@ let mut x = &mut i; // ok!
let mut i = 0;
let a = &i; // ok!
let b = &i; // still ok!
let c = &i; // super still ok!
let c = &i; // still ok!
```
"##,

Expand Down
21 changes: 21 additions & 0 deletions src/librustc_trans/diagnostics.rs
@@ -0,0 +1,21 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![allow(non_snake_case)]

register_long_diagnostics! {

}

register_diagnostics! {
E0510, // invalid use of `return_address` intrinsic: function does not use out pointer
E0511, // invalid monomorphization of `{}` intrinsic
E0512, // transmute called on types with potentially different sizes...
}
2 changes: 2 additions & 0 deletions src/librustc_trans/lib.rs
Expand Up @@ -80,6 +80,8 @@ pub mod back {
pub mod msvc;
}

pub mod diagnostics;

pub mod trans;
pub mod save;

Expand Down
32 changes: 21 additions & 11 deletions src/librustc_trans/trans/intrinsic.rs
Expand Up @@ -44,6 +44,9 @@ use syntax::ast;
use syntax::ptr::P;
use syntax::parse::token;

use rustc::session::Session;
use syntax::codemap::Span;

use std::cmp::Ordering;

pub fn get_simple_intrinsic(ccx: &CrateContext, item: &hir::ForeignItem) -> Option<ValueRef> {
Expand Down Expand Up @@ -99,6 +102,10 @@ pub fn get_simple_intrinsic(ccx: &CrateContext, item: &hir::ForeignItem) -> Opti
Some(ccx.get_intrinsic(&name))
}

pub fn span_transmute_size_error(a: &Session, b: Span, msg: &str) {
span_err!(a, b, E0512, "{}", msg);
}

/// Performs late verification that intrinsics are used correctly. At present,
/// the only intrinsic that needs such verification is `transmute`.
pub fn check_intrinsics(ccx: &CrateContext) {
Expand Down Expand Up @@ -127,8 +134,7 @@ pub fn check_intrinsics(ccx: &CrateContext) {
last_failing_id = Some(transmute_restriction.id);

if transmute_restriction.original_from != transmute_restriction.substituted_from {
ccx.sess().span_err(
transmute_restriction.span,
span_transmute_size_error(ccx.sess(), transmute_restriction.span,
&format!("transmute called on types with potentially different sizes: \
{} (could be {} bit{}) to {} (could be {} bit{})",
transmute_restriction.original_from,
Expand All @@ -138,8 +144,7 @@ pub fn check_intrinsics(ccx: &CrateContext) {
to_type_size as usize,
if to_type_size == 1 {""} else {"s"}));
} else {
ccx.sess().span_err(
transmute_restriction.span,
span_transmute_size_error(ccx.sess(), transmute_restriction.span,
&format!("transmute called on types with different sizes: \
{} ({} bit{}) to {} ({} bit{})",
transmute_restriction.original_from,
Expand Down Expand Up @@ -798,9 +803,9 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,

(_, "return_address") => {
if !fcx.caller_expects_out_pointer {
tcx.sess.span_err(call_info.span,
"invalid use of `return_address` intrinsic: function \
does not use out pointer");
span_err!(tcx.sess, call_info.span, E0510,
"invalid use of `return_address` intrinsic: function \
does not use out pointer");
C_null(Type::i8p(ccx))
} else {
PointerCast(bcx, llvm::get_param(fcx.llfn, 0), Type::i8p(ccx))
Expand Down Expand Up @@ -1439,6 +1444,10 @@ fn get_rust_try_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>,
return rust_try
}

fn span_invalid_monomorphization_error(a: &Session, b: Span, c: &str) {
span_err!(a, b, E0511, "{}", c);
}

fn generic_simd_intrinsic<'blk, 'tcx, 'a>
(bcx: Block<'blk, 'tcx>,
name: &str,
Expand All @@ -1457,10 +1466,11 @@ fn generic_simd_intrinsic<'blk, 'tcx, 'a>
emit_error!($msg, )
};
($msg: tt, $($fmt: tt)*) => {
bcx.sess().span_err(call_info.span,
&format!(concat!("invalid monomorphization of `{}` intrinsic: ",
$msg),
name, $($fmt)*));
span_invalid_monomorphization_error(
bcx.sess(), call_info.span,
&format!(concat!("invalid monomorphization of `{}` intrinsic: ",
$msg),
name, $($fmt)*));
}
}
macro_rules! require {
Expand Down

0 comments on commit 1adcfb8

Please sign in to comment.