Skip to content

Commit e012dc7

Browse files
committed
ClangImporter: setup macros for WinSDK import
Windows SDK requires that the platform target is identified. Unfortunately, `cl` does not specify the value, so we cannot actually specify the value in the clang frontend. Specify this in the swift frontend as this obscures the clang invocation.
1 parent 1d10a6a commit e012dc7

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,25 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
541541
});
542542
}
543543

544+
if (triple.isOSWindows()) {
545+
switch (triple.getArch()) {
546+
default: llvm_unreachable("unsupported Windows architecture");
547+
case llvm::Triple::arm:
548+
case llvm::Triple::thumb:
549+
invocationArgStrs.insert(invocationArgStrs.end(), {"-D_ARM_"});
550+
break;
551+
case llvm::Triple::aarch64:
552+
invocationArgStrs.insert(invocationArgStrs.end(), {"-D_ARM64_"});
553+
break;
554+
case llvm::Triple::x86:
555+
invocationArgStrs.insert(invocationArgStrs.end(), {"-D_X86_"});
556+
break;
557+
case llvm::Triple::x86_64:
558+
invocationArgStrs.insert(invocationArgStrs.end(), {"-D_AMD64_"});
559+
break;
560+
}
561+
}
562+
544563
// The module map used for Glibc depends on the target we're compiling for,
545564
// and is not included in the resource directory with the other implicit
546565
// module maps. It's at {freebsd|linux}/{arch}/glibc.modulemap.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// REQUIRES: CODEGENERATOR=AArch64
2+
// REQUIRES: CODEGENERATOR=ARM
3+
// REQUIRES: CODEGENERATOR=X86
4+
5+
// RUN: %swift -target i686-unknown-windows-msvc -typecheck %s -parse-stdlib -dump-clang-diagnostics 2>&1 | %FileCheck %s -check-prefix CHECK-X86
6+
// RUN: %swift -target x86_64-unknown-windows-msvc -typecheck %s -parse-stdlib -dump-clang-diagnostics 2>&1 | %FileCheck %s -check-prefix CHECK-X64
7+
// RUN: %swift -target thumbv7-unknown-windows-msvc -typecheck %s -parse-stdlib -dump-clang-diagnostics 2>&1 | %FileCheck %s -check-prefix CHECK-ARM
8+
// RUN: %swift -target aarch64-unknown-windows-msvc -typecheck %s -parse-stdlib -dump-clang-diagnostics 2>&1 | %FileCheck %s -check-prefix CHECK-ARM64
9+
10+
// CHECK-X86: -D_X86_
11+
// CHECK-X64: -D_AMD64_
12+
// CHECK-ARM: -D_ARM_
13+
// CHECK-ARM64: -D_ARM64_
14+

0 commit comments

Comments
 (0)