diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 90db69b44f864..ad564800b6aad 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1045,9 +1045,8 @@ void EmitAssemblyHelper::EmitAssemblyWithLegacyPassManager( // -fsycl-instrument-device-code option was passed. This option can be // used only with spir triple. if (CodeGenOpts.SPIRITTAnnotations) { - if (!llvm::Triple(TheModule->getTargetTriple()).isSPIR()) - llvm::report_fatal_error( - "ITT annotations can only by added to a module with spir target"); + assert(llvm::Triple(TheModule->getTargetTriple()).isSPIR() && + "ITT annotations can only by added to a module with spir target"); PerModulePasses.add(createSPIRITTAnnotationsLegacyPass()); } diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index e3a3c711965b3..e81be82525448 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1900,6 +1900,13 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, Opts.EnableAIXExtendedAltivecABI = O.matches(OPT_mabi_EQ_vec_extabi); } + if (Arg *A = Args.getLastArg(OPT_fsycl_instrument_device_code)) { + if (!T.isSPIR()) + Diags.Report(diag::err_drv_unsupported_opt_for_target) + << A->getSpelling() << T.str(); + Opts.SPIRITTAnnotations = true; + } + bool NeedLocTracking = false; if (!Opts.OptRecordFile.empty()) diff --git a/clang/test/CodeGen/sycl-instrumentation-option.c b/clang/test/CodeGen/sycl-instrumentation-option.c new file mode 100644 index 0000000000000..9097e0c7ee759 --- /dev/null +++ b/clang/test/CodeGen/sycl-instrumentation-option.c @@ -0,0 +1,17 @@ +/// Check if -fsycl-instrument-device-code is allowed only for spir target + +// RUN: %clang_cc1 -fsycl-instrument-device-code -triple spir-unknown-unknown %s -emit-llvm -o - 2>&1 | FileCheck %s +// RUN: %clang_cc1 -fsycl-instrument-device-code -triple spir64-unknown-unknown %s -emit-llvm -o - 2>&1 | FileCheck %s +// RUN: %clang_cc1 -fsycl-instrument-device-code -triple spir64_gen-unknown-unknown %s -emit-llvm -o - 2>&1 | FileCheck %s +// RUN: %clang_cc1 -fsycl-instrument-device-code -triple spir64_fpga-unknown-unknown %s -emit-llvm -o - 2>&1 | FileCheck %s +// RUN: %clang_cc1 -fsycl-instrument-device-code -triple spir64_x86_64-unknown-unknown %s -emit-llvm -o - 2>&1 | FileCheck %s +// CHECK-NOT: error + +// RUN: not %clang_cc1 -fsycl-instrument-device-code -triple spirv32 -emit-llvm %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-ERR +// RUN: not %clang_cc1 -fsycl-instrument-device-code -triple spirv64 -emit-llvm %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-ERR +// RUN: not %clang_cc1 -fsycl-instrument-device-code -triple x86_64-unknown-unknown -emit-llvm %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-ERR +// RUN: not %clang_cc1 -fsycl-instrument-device-code -triple i386-unknown-unknown -emit-llvm %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-ERR +// RUN: not %clang_cc1 -fsycl-instrument-device-code -triple xcore-unknown-unknown -emit-llvm %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-ERR +// RUN: not %clang_cc1 -fsycl-instrument-device-code -triple powerpc64-unknown-unknown -emit-llvm %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-ERR +// RUN: not %clang_cc1 -fsycl-instrument-device-code -triple armv7-unknown-unknown -emit-llvm %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-ERR +// CHECK-ERR: error: unsupported option '-fsycl-instrument-device-code' for target