From d93af085fa0fad96200bc281cc50f60f1f790e6a Mon Sep 17 00:00:00 2001 From: Felipe de Azevedo Piovezan Date: Thu, 28 Jul 2022 11:05:58 -0400 Subject: [PATCH] [llvm-mc][CAS] Add sanity check for CAS backend flags The `--cas-backend` flag is only compatible with `--filetype=obj`, however no error is produced if a different filetype is specified, and the `--cas-backend` flag is silently ignored. This patch emits an error in these cases, to prevent incorrect usage of the tool. --- llvm/tools/llvm-mc/llvm-mc.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp index d2c1cc2f95fb8..6bf9c48609552 100644 --- a/llvm/tools/llvm-mc/llvm-mc.cpp +++ b/llvm/tools/llvm-mc/llvm-mc.cpp @@ -549,6 +549,12 @@ int main(int argc, char **argv) { assert(MCII && "Unable to create instruction info!"); MCInstPrinter *IP = nullptr; + + if (UseMCCASBackend && FileType != OFT_ObjectFile) { + WithColor::error() << "-cas-backend is only compatible with -filetype=obj"; + return 1; + } + if (FileType == OFT_AssemblyFile) { IP = TheTarget->createMCInstPrinter(Triple(TripleName), OutputAsmVariant, *MAI, *MCII, *MRI);