ISLE: fix compile fuzz target, and fix a simple error-reporting bug. (#3845)

It seems our `compile` fuzz target for ISLE has not been regularly
tested, as it was never updated for the `isle` -> `cranelift_isle` crate
renaming. This PR fixes it to compile again.

This also includes a simple fix in the typechecking: when verifying that
a term decl is valid, we might insert a term ID into the name->ID map
before fully checking that all of the types exist, and then skipping
(for error recovery purposes) the actual push onto the term-signature
vector if one of the types does have an error. This phantom TID can
later cause a panic. The fix is to avoid adding to the map until we have
fully verified the term decl.
This commit is contained in:
Chris Fallin
2022-02-23 14:34:32 -08:00
committed by GitHub
parent 9dbb8c25c5
commit 56236fb58e
3 changed files with 7 additions and 5 deletions

View File

@@ -185,6 +185,8 @@ jobs:
- run: cargo fetch - run: cargo fetch
working-directory: ./fuzz working-directory: ./fuzz
- run: cargo fuzz build --dev - run: cargo fuzz build --dev
# Check that the ISLE fuzz targets build too.
- run: cargo fuzz build --dev --fuzz-dir ./cranelift/isle/fuzz
rebuild_isle: rebuild_isle:
name: Rebuild ISLE name: Rebuild ISLE

View File

@@ -5,21 +5,21 @@ use libfuzzer_sys::fuzz_target;
fuzz_target!(|s: &str| { fuzz_target!(|s: &str| {
let _ = env_logger::try_init(); let _ = env_logger::try_init();
let lexer = isle::lexer::Lexer::from_str(s, "fuzz-input.isle"); let lexer = cranelift_isle::lexer::Lexer::from_str(s, "fuzz-input.isle");
log::debug!("lexer = {:?}", lexer); log::debug!("lexer = {:?}", lexer);
let lexer = match lexer { let lexer = match lexer {
Ok(l) => l, Ok(l) => l,
Err(_) => return, Err(_) => return,
}; };
let defs = isle::parser::parse(lexer); let defs = cranelift_isle::parser::parse(lexer);
log::debug!("defs = {:?}", defs); log::debug!("defs = {:?}", defs);
let defs = match defs { let defs = match defs {
Ok(d) => d, Ok(d) => d,
Err(_) => return, Err(_) => return,
}; };
let code = isle::compile::compile(&defs); let code = cranelift_isle::compile::compile(&defs);
log::debug!("code = {:?}", code); log::debug!("code = {:?}", code);
let code = match code { let code = match code {
Ok(c) => c, Ok(c) => c,

View File

@@ -805,7 +805,6 @@ impl TermEnv {
for def in &defs.defs { for def in &defs.defs {
match def { match def {
&ast::Def::Decl(ref decl) => { &ast::Def::Decl(ref decl) => {
let tid = TermId(self.terms.len());
let name = tyenv.intern_mut(&decl.term); let name = tyenv.intern_mut(&decl.term);
if let Some(tid) = self.term_map.get(&name) { if let Some(tid) = self.term_map.get(&name) {
tyenv.report_error( tyenv.report_error(
@@ -817,7 +816,6 @@ impl TermEnv {
format!("Duplicate decl for '{}'", decl.term.0), format!("Duplicate decl for '{}'", decl.term.0),
); );
} }
self.term_map.insert(name, tid);
let arg_tys = decl let arg_tys = decl
.arg_tys .arg_tys
@@ -850,6 +848,8 @@ impl TermEnv {
} }
}; };
let tid = TermId(self.terms.len());
self.term_map.insert(name, tid);
self.terms.push(Term { self.terms.push(Term {
id: tid, id: tid,
decl_pos: decl.pos, decl_pos: decl.pos,