Skip to content

ClangImporter: setup macros for WinSDK import #21735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,25 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
});
}

if (triple.isOSWindows()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also kick in for Cygwin. Is that desired?

switch (triple.getArch()) {
default: llvm_unreachable("unsupported Windows architecture");
case llvm::Triple::arm:
case llvm::Triple::thumb:
invocationArgStrs.insert(invocationArgStrs.end(), {"-D_ARM_"});
break;
case llvm::Triple::aarch64:
invocationArgStrs.insert(invocationArgStrs.end(), {"-D_ARM64_"});
break;
case llvm::Triple::x86:
invocationArgStrs.insert(invocationArgStrs.end(), {"-D_X86_"});
break;
case llvm::Triple::x86_64:
invocationArgStrs.insert(invocationArgStrs.end(), {"-D_AMD64_"});
break;
}
}

// The module map used for Glibc depends on the target we're compiling for,
// and is not included in the resource directory with the other implicit
// module maps. It's at {freebsd|linux}/{arch}/glibc.modulemap.
Expand Down
14 changes: 14 additions & 0 deletions test/ClangImporter/windows-sdk-macros.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// REQUIRES: CODEGENERATOR=AArch64
// REQUIRES: CODEGENERATOR=ARM
// REQUIRES: CODEGENERATOR=X86

// RUN: %swift -target i686-unknown-windows-msvc -typecheck %s -parse-stdlib -dump-clang-diagnostics 2>&1 | %FileCheck %s -check-prefix CHECK-X86
// RUN: %swift -target x86_64-unknown-windows-msvc -typecheck %s -parse-stdlib -dump-clang-diagnostics 2>&1 | %FileCheck %s -check-prefix CHECK-X64
// RUN: %swift -target thumbv7-unknown-windows-msvc -typecheck %s -parse-stdlib -dump-clang-diagnostics 2>&1 | %FileCheck %s -check-prefix CHECK-ARM
// RUN: %swift -target aarch64-unknown-windows-msvc -typecheck %s -parse-stdlib -dump-clang-diagnostics 2>&1 | %FileCheck %s -check-prefix CHECK-ARM64

// CHECK-X86: -D_X86_
// CHECK-X64: -D_AMD64_
// CHECK-ARM: -D_ARM_
// CHECK-ARM64: -D_ARM64_