[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.
This commit is contained in:
Martin Storsjö 2021-04-21 12:40:39 +03:00
parent dc256a443a
commit 066b8f2fc6
2 changed files with 20 additions and 5 deletions

View File

@ -1,4 +1,4 @@
// RUN: llvm-rc -i%p/Inputs -Fo%t.res %s
// RUN: llvm-rc -v -i%p/Inputs -Fo%t.res %s
// RUN: llvm-readobj %t.res | FileCheck %s
// CHECK: Resource type (int): RCDATA (ID 10)
// CHECK: Resource name (int): 42

View File

@ -114,10 +114,25 @@ ErrorOr<std::string> 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();
}