[rustllvm] Use report_fatal_error over llvm_unreachable
This makes it more robust when assertions are disabled, crashing instead of causing UB. Also introduces a tidy check to enforce this rule, which in turn necessitated making tidy run on src/rustllvm. Fixes #44020
This commit is contained in:
parent
26e881d00f
commit
296aa96deb
5 changed files with 37 additions and 30 deletions
|
|
@ -57,7 +57,6 @@ fn filter_dirs(path: &Path) -> bool {
|
|||
"src/libbacktrace",
|
||||
"src/libcompiler_builtins",
|
||||
"src/compiler-rt",
|
||||
"src/rustllvm",
|
||||
"src/liblibc",
|
||||
"src/vendor",
|
||||
"src/rt/hoedown",
|
||||
|
|
|
|||
|
|
@ -50,6 +50,11 @@ const UNEXPLAINED_IGNORE_DOCTEST_INFO: &str = r#"unexplained "```ignore" doctest
|
|||
|
||||
"#;
|
||||
|
||||
const LLVM_UNREACHABLE_INFO: &str = r"\
|
||||
C++ code used llvm_unreachable, which triggers undefined behavior
|
||||
when executed when assertions are disabled.
|
||||
Use llvm::report_fatal_error for increased robustness.";
|
||||
|
||||
/// Parser states for line_is_url.
|
||||
#[derive(PartialEq)]
|
||||
#[allow(non_camel_case_types)]
|
||||
|
|
@ -108,7 +113,7 @@ pub fn check(path: &Path, bad: &mut bool) {
|
|||
let mut contents = String::new();
|
||||
super::walk(path, &mut super::filter_dirs, &mut |file| {
|
||||
let filename = file.file_name().unwrap().to_string_lossy();
|
||||
let extensions = [".rs", ".py", ".js", ".sh", ".c", ".h"];
|
||||
let extensions = [".rs", ".py", ".js", ".sh", ".c", ".cpp", ".h"];
|
||||
if extensions.iter().all(|e| !filename.ends_with(e)) ||
|
||||
filename.starts_with(".#") {
|
||||
return
|
||||
|
|
@ -153,6 +158,9 @@ pub fn check(path: &Path, bad: &mut bool) {
|
|||
if line.ends_with("```ignore") || line.ends_with("```rust,ignore") {
|
||||
err(UNEXPLAINED_IGNORE_DOCTEST_INFO);
|
||||
}
|
||||
if filename.ends_with(".cpp") && line.contains("llvm_unreachable") {
|
||||
err(LLVM_UNREACHABLE_INFO);
|
||||
}
|
||||
}
|
||||
if !licenseck(file, &contents) {
|
||||
tidy_error!(bad, "{}: incorrect license", file.display());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue