Skip to content

[CIR] Change unreachable to diagnostic for ill-equipped clang #152614

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticFrontendKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ def err_fe_no_pch_in_dir : Error<
"no suitable precompiled header file found in directory '%0'">;
def err_fe_action_not_available : Error<
"action %0 not compiled in">;
def err_fe_cir_not_built : Error<"clang IR support not available, rebuild "
"clang with -DCLANG_ENABLE_CIR=ON">;
def err_fe_invalid_multiple_actions : Error<
"'%0' action ignored; '%1' action specified previously">;
def err_fe_invalid_alignment : Error<
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ CreateFrontendBaseAction(CompilerInstance &CI) {
#if CLANG_ENABLE_CIR
return std::make_unique<cir::EmitCIRAction>();
#else
llvm_unreachable("CIR suppport not built into clang");
CI.getDiagnostics().Report(diag::err_fe_cir_not_built);
return nullptr;
#endif
case EmitHTML: return std::make_unique<HTMLPrintAction>();
case EmitLLVM: {
Expand Down
12 changes: 12 additions & 0 deletions clang/test/Frontend/cir-not-built.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Test that using -emit-cir when clang is not built with CIR support gives a proper error message
// instead of crashing.

// This test should only run when CIR support is NOT enabled
// UNSUPPORTED: cir-support

// RUN: not %clang_cc1 -emit-cir %s 2>&1 | FileCheck %s
// CHECK: error: clang IR support not available, rebuild clang with -DCLANG_ENABLE_CIR=ON

int main(void) {
return 0;
}
4 changes: 4 additions & 0 deletions clang/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ def have_host_clang_repl_cuda():
)
)

# ClangIR support
if config.clang_enable_cir:
config.available_features.add("cir-support")

llvm_config.add_tool_substitutions(tools, tool_dirs)

config.substitutions.append(
Expand Down