[clang] 066b8f2 - [llvm-rc] Try to fix the Preprocessor/llvm-rc.rc test on non arm/x86 architectures
Martin Storsjö via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 21 02:47:41 PDT 2021
Author: Martin Storsjö
Date: 2021-04-21T12:47:33+03:00
New Revision: 066b8f2fc6d584635a017a0a15494ce4460744e3
URL: https://github.com/llvm/llvm-project/commit/066b8f2fc6d584635a017a0a15494ce4460744e3
DIFF: https://github.com/llvm/llvm-project/commit/066b8f2fc6d584635a017a0a15494ce4460744e3.diff
LOG: [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.
Added:
Modified:
clang/test/Preprocessor/llvm-rc.rc
llvm/tools/llvm-rc/llvm-rc.cpp
Removed:
################################################################################
diff --git a/clang/test/Preprocessor/llvm-rc.rc b/clang/test/Preprocessor/llvm-rc.rc
index 689fc87473f9..799bf347dbee 100644
--- a/clang/test/Preprocessor/llvm-rc.rc
+++ b/clang/test/Preprocessor/llvm-rc.rc
@@ -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
diff --git a/llvm/tools/llvm-rc/llvm-rc.cpp b/llvm/tools/llvm-rc/llvm-rc.cpp
index ab5ecb8fa3fd..b61fba78ad01 100644
--- a/llvm/tools/llvm-rc/llvm-rc.cpp
+++ b/llvm/tools/llvm-rc/llvm-rc.cpp
@@ -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();
}
More information about the cfe-commits
mailing list