Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rustllvm] Use report_fatal_error over llvm_unreachable #46124

Merged
merged 1 commit into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/rustllvm/ArchiveWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static Archive::Kind fromRust(LLVMRustArchiveKind Kind) {
case LLVMRustArchiveKind::COFF:
return Archive::K_COFF;
default:
llvm_unreachable("Bad ArchiveKind.");
report_fatal_error("Bad ArchiveKind.");
}
}

Expand Down
32 changes: 16 additions & 16 deletions src/rustllvm/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static CodeModel::Model fromRust(LLVMRustCodeModel Model) {
case LLVMRustCodeModel::Large:
return CodeModel::Large;
default:
llvm_unreachable("Bad CodeModel.");
report_fatal_error("Bad CodeModel.");
}
}

Expand All @@ -258,7 +258,7 @@ static CodeGenOpt::Level fromRust(LLVMRustCodeGenOptLevel Level) {
case LLVMRustCodeGenOptLevel::Aggressive:
return CodeGenOpt::Aggressive;
default:
llvm_unreachable("Bad CodeGenOptLevel.");
report_fatal_error("Bad CodeGenOptLevel.");
}
}

Expand Down Expand Up @@ -302,7 +302,7 @@ static Optional<Reloc::Model> fromRust(LLVMRustRelocMode RustReloc) {
break;
#endif
}
llvm_unreachable("Bad RelocModel.");
report_fatal_error("Bad RelocModel.");
}

#if LLVM_RUSTLLVM
Expand Down Expand Up @@ -511,7 +511,7 @@ static TargetMachine::CodeGenFileType fromRust(LLVMRustFileType Type) {
case LLVMRustFileType::ObjectFile:
return TargetMachine::CGFT_ObjectFile;
default:
llvm_unreachable("Bad FileType.");
report_fatal_error("Bad FileType.");
}
}

Expand Down Expand Up @@ -1197,7 +1197,7 @@ extern "C" bool
LLVMRustWriteThinBitcodeToFile(LLVMPassManagerRef PMR,
LLVMModuleRef M,
const char *BcFile) {
llvm_unreachable("ThinLTO not available");
report_fatal_error("ThinLTO not available");
}

struct LLVMRustThinLTOData {
Expand All @@ -1211,62 +1211,62 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
int num_modules,
const char **preserved_symbols,
int num_symbols) {
llvm_unreachable("ThinLTO not available");
report_fatal_error("ThinLTO not available");
}

extern "C" bool
LLVMRustPrepareThinLTORename(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
llvm_unreachable("ThinLTO not available");
report_fatal_error("ThinLTO not available");
}

extern "C" bool
LLVMRustPrepareThinLTOResolveWeak(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
llvm_unreachable("ThinLTO not available");
report_fatal_error("ThinLTO not available");
}

extern "C" bool
LLVMRustPrepareThinLTOInternalize(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
llvm_unreachable("ThinLTO not available");
report_fatal_error("ThinLTO not available");
}

extern "C" bool
LLVMRustPrepareThinLTOImport(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
llvm_unreachable("ThinLTO not available");
report_fatal_error("ThinLTO not available");
}

extern "C" void
LLVMRustFreeThinLTOData(LLVMRustThinLTOData *Data) {
llvm_unreachable("ThinLTO not available");
report_fatal_error("ThinLTO not available");
}

struct LLVMRustThinLTOBuffer {
};

extern "C" LLVMRustThinLTOBuffer*
LLVMRustThinLTOBufferCreate(LLVMModuleRef M) {
llvm_unreachable("ThinLTO not available");
report_fatal_error("ThinLTO not available");
}

extern "C" void
LLVMRustThinLTOBufferFree(LLVMRustThinLTOBuffer *Buffer) {
llvm_unreachable("ThinLTO not available");
report_fatal_error("ThinLTO not available");
}

extern "C" const void*
LLVMRustThinLTOBufferPtr(const LLVMRustThinLTOBuffer *Buffer) {
llvm_unreachable("ThinLTO not available");
report_fatal_error("ThinLTO not available");
}

extern "C" size_t
LLVMRustThinLTOBufferLen(const LLVMRustThinLTOBuffer *Buffer) {
llvm_unreachable("ThinLTO not available");
report_fatal_error("ThinLTO not available");
}

extern "C" LLVMModuleRef
LLVMRustParseBitcodeForThinLTO(LLVMContextRef Context,
const char *data,
size_t len,
const char *identifier) {
llvm_unreachable("ThinLTO not available");
report_fatal_error("ThinLTO not available");
}
#endif // LLVM_VERSION_GE(4, 0)
22 changes: 11 additions & 11 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static AtomicOrdering fromRust(LLVMAtomicOrdering Ordering) {
return AtomicOrdering::SequentiallyConsistent;
}

llvm_unreachable("Invalid LLVMAtomicOrdering value!");
report_fatal_error("Invalid LLVMAtomicOrdering value!");
}

static LLVM_THREAD_LOCAL char *LastError;
Expand Down Expand Up @@ -161,7 +161,7 @@ static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) {
case SanitizeMemory:
return Attribute::SanitizeMemory;
}
llvm_unreachable("bad AttributeKind");
report_fatal_error("bad AttributeKind");
}

extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned Index,
Expand Down Expand Up @@ -356,7 +356,7 @@ static SyncScope::ID fromRust(LLVMRustSynchronizationScope Scope) {
case LLVMRustSynchronizationScope::CrossThread:
return SyncScope::System;
default:
llvm_unreachable("bad SynchronizationScope.");
report_fatal_error("bad SynchronizationScope.");
}
}
#else
Expand All @@ -367,7 +367,7 @@ static SynchronizationScope fromRust(LLVMRustSynchronizationScope Scope) {
case LLVMRustSynchronizationScope::CrossThread:
return CrossThread;
default:
llvm_unreachable("bad SynchronizationScope.");
report_fatal_error("bad SynchronizationScope.");
}
}
#endif
Expand Down Expand Up @@ -397,7 +397,7 @@ static InlineAsm::AsmDialect fromRust(LLVMRustAsmDialect Dialect) {
case LLVMRustAsmDialect::Intel:
return InlineAsm::AD_Intel;
default:
llvm_unreachable("bad AsmDialect.");
report_fatal_error("bad AsmDialect.");
}
}

Expand Down Expand Up @@ -748,7 +748,7 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariable(
unwrapDI<DIType>(Ty), AlwaysPreserve, fromRust(Flags)
#if LLVM_VERSION_GE(4, 0)
,
AlignInBits
AlignInBits
#endif
));
} else {
Expand Down Expand Up @@ -1149,7 +1149,7 @@ extern "C" LLVMTypeKind LLVMRustGetTypeKind(LLVMTypeRef Ty) {
return LLVMTokenTypeKind;
#endif
}
llvm_unreachable("Unhandled TypeID.");
report_fatal_error("Unhandled TypeID.");
}

extern "C" void LLVMRustWriteDebugLocToString(LLVMContextRef C,
Expand Down Expand Up @@ -1370,7 +1370,7 @@ static LLVMRustLinkage toRust(LLVMLinkage Linkage) {
case LLVMCommonLinkage:
return LLVMRustLinkage::CommonLinkage;
default:
llvm_unreachable("Invalid LLVMRustLinkage value!");
report_fatal_error("Invalid LLVMRustLinkage value!");
}
}

Expand Down Expand Up @@ -1399,7 +1399,7 @@ static LLVMLinkage fromRust(LLVMRustLinkage Linkage) {
case LLVMRustLinkage::CommonLinkage:
return LLVMCommonLinkage;
}
llvm_unreachable("Invalid LLVMRustLinkage value!");
report_fatal_error("Invalid LLVMRustLinkage value!");
}

extern "C" LLVMRustLinkage LLVMRustGetLinkage(LLVMValueRef V) {
Expand Down Expand Up @@ -1447,7 +1447,7 @@ static LLVMRustVisibility toRust(LLVMVisibility Vis) {
case LLVMProtectedVisibility:
return LLVMRustVisibility::Protected;
}
llvm_unreachable("Invalid LLVMRustVisibility value!");
report_fatal_error("Invalid LLVMRustVisibility value!");
}

static LLVMVisibility fromRust(LLVMRustVisibility Vis) {
Expand All @@ -1459,7 +1459,7 @@ static LLVMVisibility fromRust(LLVMRustVisibility Vis) {
case LLVMRustVisibility::Protected:
return LLVMProtectedVisibility;
}
llvm_unreachable("Invalid LLVMRustVisibility value!");
report_fatal_error("Invalid LLVMRustVisibility value!");
}

extern "C" LLVMRustVisibility LLVMRustGetVisibility(LLVMValueRef V) {
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion src/tools/tidy/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down