Skip to content
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
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,9 @@ def warn_missing_include_dirs : Warning<
def err_drv_malformed_warning_suppression_mapping : Error<
"failed to process suppression mapping file '%0': %1">;

def err_drv_emit_cir_without_fclangir : Error<
"-emit-cir is only valid with -fclangir">;

def warn_drv_openacc_without_cir
: Warning<"OpenACC directives will result in no runtime behavior; use "
"-fclangir to enable runtime effect">,
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticFrontendKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ 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_cir_disabled : Error<
"trying to compile CIR module %0 with clang IR disabled; use "
"-fclangir to enable CIR pipeline">;
def err_fe_invalid_multiple_actions : Error<
"'%0' action ignored; '%1' action specified previously">;
def err_fe_invalid_alignment : Error<
Expand Down
10 changes: 9 additions & 1 deletion clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3139,9 +3139,17 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
if (Opts.ProgramAction != frontend::GenerateModule && Opts.IsSystemModule)
Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
<< "-emit-module";
if (Args.hasArg(OPT_fclangir) || Args.hasArg(OPT_emit_cir))
if (Args.hasArg(OPT_fclangir))
Opts.UseClangIRPipeline = true;

#if CLANG_ENABLE_CIR
if (!Args.hasArg(OPT_fclangir) && Args.hasArg(OPT_emit_cir))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of hasArg, should this check UseClangIRPipeline? It seems our ACTUAL error isn't the mix, its attempting to emit CIR without also having the ClangIR pipeline enabled.

Diags.Report(diag::err_drv_emit_cir_without_fclangir);
#else
if (Args.hasArg(OPT_emit_cir))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also report an error if -fclangir is used in this case. Currently, we silently do nothing.

Diags.Report(diag::err_fe_cir_not_built);
#endif

#if CLANG_ENABLE_CIR
if (Args.hasArg(OPT_clangir_disable_passes))
Opts.ClangIRDisablePasses = true;
Expand Down
16 changes: 12 additions & 4 deletions clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,20 @@ CreateFrontendBaseAction(CompilerInstance &CI) {
StringRef Action("unknown");
(void)Action;

#if CLANG_ENABLE_CIR
unsigned UseCIR = CI.getFrontendOpts().UseClangIRPipeline;
frontend::ActionKind Act = CI.getFrontendOpts().ProgramAction;
bool EmitsCIR = Act == EmitCIR;

if (!UseCIR && EmitsCIR)
llvm::report_fatal_error("-emit-cir and only valid when using -fclangir");
if (!UseCIR) {
FrontendInputFile *it =
llvm::find_if(CI.getFrontendOpts().Inputs, [](const auto &FIF) {
return FIF.getKind().getLanguage() == Language::CIR;
});
if (it != CI.getFrontendOpts().Inputs.end()) {
CI.getDiagnostics().Report(diag::err_fe_cir_disabled) << it->getFile();
return nullptr;
}
}
#endif

switch (CI.getFrontendOpts().ProgramAction) {
case ASTDeclList: return std::make_unique<ASTDeclListAction>();
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CIR/CodeGen/builtin_prefetch.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-cir %s -o - | FileCheck %s -check-prefix=CIR
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - | FileCheck %s -check-prefix=CIR
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o - | FileCheck %s -check-prefix=LLVM
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s -check-prefix=OGCG
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o - | FileCheck %s -check-prefix=OGCG

void foo(void *a) {
__builtin_prefetch(a); // rw=0, locality=3
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/dlti.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-cir %s -o %t.cir
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=LITTLE

void foo() {}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/dlti_be.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// REQUIRES: aarch64-registered-target
// RUN: %clang_cc1 -triple aarch64_be-linux-gnu -emit-cir %s -o %t.cir
// RUN: %clang_cc1 -triple aarch64_be-linux-gnu -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=BIG

void foo() {}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/module-asm.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-cir %s -o %t.cir
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s

// CHECK: cir.module_asm = [".globl bar", ".globl foo"]
Expand Down
11 changes: 11 additions & 0 deletions clang/test/Driver/cir-flags-error.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// REQUIRES: cir-support

// RUN: not %clang -emit-cir %s -o /dev/null 2>&1 | FileCheck %s -check-prefix=EMIT_CIR_ERROR
// EMIT_CIR_ERROR: error: -emit-cir is only valid with -fclangir

// RUN: %clang -fclangir -emit-cir %s -o /dev/null 2>&1 | FileCheck %s --allow-empty -check-prefix=EMIT_CIR_OK
// EMIT_CIR_OK-NOT: error: -emit-cir is only valid with -fclangir

int main(void) {
return 0;
}
20 changes: 20 additions & 0 deletions clang/test/Driver/cir-input-without-fclangir.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: not %clang %s -emit-llvm -o /dev/null 2>&1 | FileCheck %s -check-prefix=CIR_INPUT_ERROR
// CIR_INPUT_ERROR: error: trying to compile CIR module {{.*}} with clang IR disabled; use -fclangir to enable CIR pipeline

// RUN: %clang -fclangir %s -emit-llvm -o /dev/null 2>&1 | FileCheck %s --allow-empty -check-prefix=CIR_INPUT_OK
// CIR_INPUT_OK-NOT: error: trying to compile CIR module

// REQUIRES: x86-registered-target
// REQUIRES: cir-support

!s32i = !cir.int<s, 32>

module attributes {cir.lang = #cir.lang<cxx>, cir.triple = "x86_64-unknown-linux-gnu"} {
cir.func @test_function() -> !s32i {
%0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"] {alignment = 4 : i64}
%1 = cir.const #cir.int<42> : !s32i
cir.store %1, %0 : !s32i, !cir.ptr<!s32i>
%2 = cir.load %0 : !cir.ptr<!s32i>, !s32i
cir.return %2 : !s32i
}
}