/// Runs prescan, parsing, sema and lowers to MLIR.
bool beginSourceFileAction() override;
/// Sets up LLVM's TargetMachine.
- void setUpTargetMachine();
+ bool setUpTargetMachine();
/// Runs the optimization (aka middle-end) pipeline on the LLVM module
/// associated with this action.
void runOptimizationPipeline(llvm::raw_pwrite_stream &os);
}
mlirModule = std::make_unique<mlir::ModuleOp>(module.release());
- setUpTargetMachine();
+ if (!setUpTargetMachine())
+ return false;
const llvm::DataLayout &dl = tm->createDataLayout();
setMLIRDataLayout(*mlirModule, dl);
return true;
*mlirModule, ci.getInvocation().getLangOpts().OpenMPIsDevice);
}
- setUpTargetMachine();
+ if (!setUpTargetMachine())
+ return false;
const llvm::DataLayout &dl = tm->createDataLayout();
setMLIRDataLayout(*mlirModule, dl);
}
-void CodeGenAction::setUpTargetMachine() {
+bool CodeGenAction::setUpTargetMachine() {
CompilerInstance &ci = this->getInstance();
const TargetOptions &targetOpts = ci.getInvocation().getTargetOpts();
std::string error;
const llvm::Target *theTarget =
llvm::TargetRegistry::lookupTarget(theTriple, error);
- assert(theTarget && "Failed to create Target");
+ if (!theTarget) {
+ ci.getDiagnostics().Report(clang::diag::err_fe_unable_to_create_target)
+ << error;
+ return false;
+ }
// Create `TargetMachine`
const auto &CGOpts = ci.getInvocation().getCodeGenOpts();
/*Reloc::Model=*/CGOpts.getRelocationModel(),
/*CodeModel::Model=*/std::nullopt, OptLevel));
assert(tm && "Failed to create TargetMachine");
+ return true;
}
static std::unique_ptr<llvm::raw_pwrite_stream>
// Set the triple based on the targetmachine (this comes compiler invocation
// and the command-line target option if specified, or the default if not
// given on the command-line).
- setUpTargetMachine();
+ if (!setUpTargetMachine())
+ return;
const std::string &theTriple = tm->getTargetTriple().str();
if (llvmModule->getTargetTriple() != theTriple) {
--- /dev/null
+! RUN: not %flang --target=some-invalid-triple -S %s -o \
+! RUN: /dev/null 2>&1 | FileCheck %s
+! RUN: not %flang_fc1 -triple some-invalid-triple -S %s -o \
+! RUN: /dev/null 2>&1 | FileCheck %s
+
+! CHECK: error: unable to create target: 'No available targets are compatible with triple "some-invalid-triple"'