Skip to content

Commit cf777d0

Browse files
committed
Introduce and use COMPILER_IS_MSVC
1 parent 592a298 commit cf777d0

File tree

8 files changed

+48
-18
lines changed

8 files changed

+48
-18
lines changed

include/swift/AST/AnyFunctionRef.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_AST_ANY_FUNCTION_REF_H
1414
#define SWIFT_AST_ANY_FUNCTION_REF_H
1515

16+
#include "swift/Basic/Compiler.h"
1617
#include "swift/Basic/LLVM.h"
1718
#include "swift/AST/Decl.h"
1819
#include "swift/AST/Expr.h"
@@ -151,7 +152,7 @@ class AnyFunctionRef {
151152
}
152153

153154
// Disable "only for use within the debugger" warning.
154-
#if defined(_MSC_VER)
155+
#if COMPILER_IS_MSVC
155156
#pragma warning(push)
156157
#pragma warning(disable: 4996)
157158
#endif
@@ -176,7 +177,7 @@ class AnyFunctionRef {
176177
llvm_unreachable("unexpected AnyFunctionRef representation");
177178
}
178179
};
179-
#if defined(_MSC_VER)
180+
#if COMPILER_IS_MSVC
180181
#pragma warning(pop)
181182
#endif
182183

include/swift/Basic/Compiler.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===--- Compiler.h - Compiler specific definitions -------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_BASIC_COMPILER_H
14+
#define SWIFT_BASIC_COMPILER_H
15+
16+
#if defined(_MSC_VER) && !defined(__clang__)
17+
#define COMPILER_IS_MSVC 1
18+
#else
19+
#define COMPILER_IS_MSVC 0
20+
#endif
21+
22+
#endif // SWIFT_BASIC_COMPILER_H

include/swift/Basic/EncodedSequence.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#ifndef SWIFT_BASIC_ENCODEDSEQUENCE_H
2222
#define SWIFT_BASIC_ENCODEDSEQUENCE_H
2323

24+
#include "swift/Basic/Compiler.h"
2425
#include "swift/Basic/LLVM.h"
2526
#include "swift/Basic/PrefixMap.h"
2627
#include "llvm/ADT/ArrayRef.h"
@@ -339,7 +340,7 @@ class EncodedSequence : public EncodedSequenceBase {
339340
template <class ValueType> class Map {
340341
// Hack: MSVC isn't able to resolve the InlineKeyCapacity part of the
341342
// template of PrefixMap, so we have to split it up and pass it manually.
342-
#if defined(_MSC_VER) && !defined(__clang__)
343+
#if COMPILER_IS_MSVC
343344
static const size_t Size = (sizeof(void*) - 1) / sizeof(Chunk);
344345
static const size_t ActualSize = max<size_t>(Size, 1);
345346

include/swift/Basic/type_traits.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define SWIFT_BASIC_TYPETRAITS_H
1515

1616
#include <type_traits>
17+
#include "swift/Basic/Compiler.h"
1718

1819
#ifndef __has_feature
1920
#define SWIFT_DEFINED_HAS_FEATURE
@@ -29,8 +30,8 @@ namespace swift {
2930
/// is not intended to be specialized.
3031
template<typename T>
3132
struct IsTriviallyCopyable {
32-
#if _LIBCPP_VERSION || (defined(_MSC_VER) && !defined(__clang__))
33-
// libc++ implements it.
33+
#if _LIBCPP_VERSION || COMPILER_IS_MSVC
34+
// libc++ and MSVC implement is_trivially_copyable.
3435
static const bool value = std::is_trivially_copyable<T>::value;
3536
#elif __has_feature(is_trivially_copyable)
3637
static const bool value = __is_trivially_copyable(T);
@@ -41,8 +42,8 @@ struct IsTriviallyCopyable {
4142

4243
template<typename T>
4344
struct IsTriviallyConstructible {
44-
#if _LIBCPP_VERSION || (defined(_MSC_VER) && !defined(__clang__))
45-
// libc++ implements it.
45+
#if _LIBCPP_VERSION || COMPILER_IS_MSVC
46+
// libc++ and MSVC implement is_trivially_constructible.
4647
static const bool value = std::is_trivially_constructible<T>::value;
4748
#elif __has_feature(has_trivial_constructor)
4849
static const bool value = __has_trivial_constructor(T);
@@ -53,8 +54,8 @@ struct IsTriviallyConstructible {
5354

5455
template<typename T>
5556
struct IsTriviallyDestructible {
56-
#if _LIBCPP_VERSION || (defined(_MSC_VER) && !defined(__clang__))
57-
// libc++ implements it.
57+
#if _LIBCPP_VERSION || COMPILER_IS_MSVC
58+
// libc++ and MSVC implement is_trivially_destructible.
5859
static const bool value = std::is_trivially_destructible<T>::value;
5960
#elif __has_feature(has_trivial_destructor)
6061
static const bool value = __has_trivial_destructor(T);

include/swift/SIL/SILOpenedArchetypesTracker.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_SIL_SILOPENEDARCHETYPESTRACKER_H
1414
#define SWIFT_SIL_SILOPENEDARCHETYPESTRACKER_H
1515

16+
#include "swift/Basic/Compiler.h"
1617
#include "swift/SIL/Notifications.h"
1718
#include "swift/SIL/SILModule.h"
1819
#include "swift/SIL/SILFunction.h"
@@ -21,7 +22,8 @@
2122
namespace swift {
2223

2324
// Disable MSVC warning: multiple copy constructors specified.
24-
#if defined(_MSC_VER)
25+
// TODO: silence this warning.
26+
#if COMPILER_IS_MSVC
2527
#pragma warning(push)
2628
#pragma warning(disable: 4521)
2729
#endif
@@ -134,7 +136,7 @@ class SILOpenedArchetypesTracker : public DeleteNotificationHandler {
134136
OpenedArchetypeDefsMap LocalOpenedArchetypeDefs;
135137
};
136138

137-
#if defined(_MSC_VER)
139+
#if COMPILER_IS_MSVC
138140
#pragma warning(pop)
139141
#endif
140142

lib/AST/ASTContext.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "swift/AST/RawComment.h"
3232
#include "swift/AST/SILLayout.h"
3333
#include "swift/AST/TypeCheckerDebugConsumer.h"
34+
#include "swift/Basic/Compiler.h"
3435
#include "swift/Basic/Fallthrough.h"
3536
#include "swift/Basic/SourceManager.h"
3637
#include "swift/Basic/StringExtras.h"
@@ -277,12 +278,12 @@ struct ASTContext::Implementation {
277278
conformance.~SpecializedProtocolConformance();
278279
// Work around MSVC warning: local variable is initialized but
279280
// not referenced.
280-
#if defined(_MSC_VER)
281+
#if COMPILER_IS_MSVC
281282
#pragma warning (disable: 4189)
282283
#endif
283284
for (auto &conformance : InheritedConformances)
284285
conformance.~InheritedProtocolConformance();
285-
#if defined(_MSC_VER)
286+
#if COMPILER_IS_MSVC
286287
#pragma warning (default: 4189)
287288
#endif
288289

lib/AST/Module.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "swift/AST/ReferencedNameTracker.h"
3030
#include "swift/AST/PrettyStackTrace.h"
3131
#include "swift/AST/PrintOptions.h"
32+
#include "swift/Basic/Compiler.h"
3233
#include "swift/Basic/SourceManager.h"
3334
#include "clang/Basic/Module.h"
3435
#include "llvm/ADT/DenseMap.h"
@@ -841,8 +842,8 @@ namespace {
841842

842843
template <typename T>
843844
struct OperatorLookup {
844-
// This assertion fails in MSVC, but not clang-cl.
845-
#if !defined(_MSC_VER) || defined(__clang__)
845+
// TODO: this assertion fails in MSVC, but not clang-cl.
846+
#if !COMPILER_IS_MSVC
846847
static_assert(static_cast<T*>(nullptr), "Only usable with operators");
847848
#endif
848849
};

lib/Sema/Constraint.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "Constraint.h"
1919
#include "ConstraintSystem.h"
2020
#include "swift/AST/Types.h"
21+
#include "swift/Basic/Compiler.h"
2122
#include "swift/Basic/Fallthrough.h"
2223
#include "llvm/Support/raw_ostream.h"
2324
#include "llvm/Support/SaveAndRestore.h"
@@ -332,13 +333,13 @@ void Constraint::dump(ConstraintSystem *CS) const {
332333
// Print all type variables as $T0 instead of _ here.
333334
llvm::SaveAndRestore<bool> X(CS->getASTContext().LangOpts.
334335
DebugConstraintSolver, true);
335-
// Disabled MSVC warning: only for use within the debugger
336-
#if defined(_MSC_VER)
336+
// Disable MSVC warning: only for use within the debugger.
337+
#if COMPILER_IS_MSVC
337338
#pragma warning(push)
338339
#pragma warning(disable: 4996)
339340
#endif
340341
dump(&CS->getASTContext().SourceMgr);
341-
#if defined(_MSC_VER)
342+
#if COMPILER_IS_MSVC
342343
#pragma warning(pop)
343344
#endif
344345
}

0 commit comments

Comments
 (0)