diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 8a8db27490f06..89bca11540147 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -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< diff --git a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp index 443eb4f1a29bf..67372a37c05f7 100644 --- a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -81,7 +81,8 @@ CreateFrontendBaseAction(CompilerInstance &CI) { #if CLANG_ENABLE_CIR return std::make_unique(); #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(); case EmitLLVM: { diff --git a/clang/test/Frontend/cir-not-built.c b/clang/test/Frontend/cir-not-built.c new file mode 100644 index 0000000000000..57fbd280c6a45 --- /dev/null +++ b/clang/test/Frontend/cir-not-built.c @@ -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; +} diff --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py index 1957bb1715eb6..4b2ecb0a6ca4c 100644 --- a/clang/test/lit.cfg.py +++ b/clang/test/lit.cfg.py @@ -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(