From 4a1d40cba032b81e8301cbf3d0227545d0856307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 21 Apr 2021 12:40:39 +0300 Subject: [PATCH] [llvm-rc] Try to fix the Preprocessor/llvm-rc.rc test on non arm/x86 architectures When llvm-rc invokes clang for preprocessing, it uses a target triple derived from the default target. The test verifies that e.g. _WIN32 is defined when preprocessing. If running clang with e.g. -target ppc64le-windows-msvc, that particular arch/OS combination isn't hooked up, so _WIN32 doesn't get defined in that configuration. Therefore, the preprocessing test fails. Instead make llvm-rc inspect the architecture of the default target. If it's one of the known supported architectures, use it as such, otherwise set a default one (x86_64). (Clang can run preprocessing with an x86_64 target triple, even if the x86 backend isn't enabled.) Also remove superfluous llvm:: specifications on enums in llvm-rc.cpp. --- tools/llvm-rc/llvm-rc.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tools/llvm-rc/llvm-rc.cpp b/tools/llvm-rc/llvm-rc.cpp index ab5ecb8fa3f..b61fba78ad0 100644 --- a/tools/llvm-rc/llvm-rc.cpp +++ b/tools/llvm-rc/llvm-rc.cpp @@ -114,10 +114,25 @@ ErrorOr findClang(const char *Argv0) { std::string getClangClTriple() { Triple T(sys::getDefaultTargetTriple()); - T.setOS(llvm::Triple::Win32); - T.setVendor(llvm::Triple::PC); - T.setEnvironment(llvm::Triple::MSVC); - T.setObjectFormat(llvm::Triple::COFF); + switch (T.getArch()) { + case Triple::x86: + case Triple::x86_64: + case Triple::arm: + case Triple::thumb: + case Triple::aarch64: + // These work properly with the clang driver, setting the expected + // defines such as _WIN32 etc. + break; + default: + // Other archs aren't set up for use with windows as target OS, (clang + // doesn't define e.g. _WIN32 etc), so set a reasonable default arch. + T.setArch(Triple::x86_64); + break; + } + T.setOS(Triple::Win32); + T.setVendor(Triple::PC); + T.setEnvironment(Triple::MSVC); + T.setObjectFormat(Triple::COFF); return T.str(); }