Move "no asm" check into AST validation

This commit is contained in:
Vadim Petrochenkov 2018-01-13 23:13:49 +03:00
parent e6072a7b38
commit 318cf22bd1
4 changed files with 4 additions and 53 deletions

View file

@ -37,7 +37,7 @@ use rustc_typeck as typeck;
use rustc_privacy;
use rustc_plugin::registry::Registry;
use rustc_plugin as plugin;
use rustc_passes::{self, ast_validation, no_asm, loops, consts, static_recursion, hir_stats};
use rustc_passes::{self, ast_validation, loops, consts, static_recursion, hir_stats};
use rustc_const_eval::{self, check_match};
use super::Compilation;
use ::DefaultTransCrate;
@ -856,10 +856,6 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
println!("{}", json::as_json(&krate));
}
time(time_passes,
"checking for inline asm in case the target doesn't support it",
|| no_asm::check_crate(sess, &krate));
time(time_passes,
"AST validation",
|| ast_validation::check_crate(sess, &krate));

View file

@ -149,6 +149,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
ExprKind::Continue(Some(ident)) => {
self.check_label(ident.node, ident.span);
}
ExprKind::InlineAsm(..) if !self.session.target.target.options.allow_asm => {
span_err!(self.session, expr.span, E0472, "asm! is unsupported on this target");
}
_ => {}
}

View file

@ -42,7 +42,6 @@ pub mod consts;
pub mod hir_stats;
pub mod loops;
mod mir_stats;
pub mod no_asm;
pub mod static_recursion;
#[cfg(not(stage0))] // remove after the next snapshot

View file

@ -1,47 +0,0 @@
// 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.
/// Run over the whole crate and check for ExprInlineAsm.
/// Inline asm isn't allowed on virtual ISA based targets, so we reject it
/// here.
use rustc::session::Session;
use syntax::ast;
use syntax::visit::Visitor;
use syntax::visit;
pub fn check_crate(sess: &Session, krate: &ast::Crate) {
if sess.target.target.options.allow_asm {
return;
}
visit::walk_crate(&mut CheckNoAsm { sess: sess }, krate);
}
#[derive(Copy, Clone)]
struct CheckNoAsm<'a> {
sess: &'a Session,
}
impl<'a> Visitor<'a> for CheckNoAsm<'a> {
fn visit_expr(&mut self, e: &'a ast::Expr) {
match e.node {
ast::ExprKind::InlineAsm(_) => {
span_err!(self.sess,
e.span,
E0472,
"asm! is unsupported on this target")
}
_ => {}
}
visit::walk_expr(self, e)
}
}