Skip to content

Introduce and use COMPILER_IS_MSVC #6828

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 16, 2017
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
5 changes: 3 additions & 2 deletions include/swift/AST/AnyFunctionRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef SWIFT_AST_ANY_FUNCTION_REF_H
#define SWIFT_AST_ANY_FUNCTION_REF_H

#include "swift/Basic/Compiler.h"
#include "swift/Basic/LLVM.h"
#include "swift/AST/Decl.h"
#include "swift/AST/Expr.h"
Expand Down Expand Up @@ -151,7 +152,7 @@ class AnyFunctionRef {
}

// Disable "only for use within the debugger" warning.
#if defined(_MSC_VER)
#if COMPILER_IS_MSVC
#pragma warning(push)
#pragma warning(disable: 4996)
#endif
Expand All @@ -176,7 +177,7 @@ class AnyFunctionRef {
llvm_unreachable("unexpected AnyFunctionRef representation");
}
};
#if defined(_MSC_VER)
#if COMPILER_IS_MSVC
#pragma warning(pop)
#endif

Expand Down
22 changes: 22 additions & 0 deletions include/swift/Basic/Compiler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===--- Compiler.h - Compiler specific definitions -------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#ifndef SWIFT_BASIC_COMPILER_H
#define SWIFT_BASIC_COMPILER_H

#if defined(_MSC_VER) && !defined(__clang__)
#define COMPILER_IS_MSVC 1
#else
#define COMPILER_IS_MSVC 0
#endif

#endif // SWIFT_BASIC_COMPILER_H
3 changes: 2 additions & 1 deletion include/swift/Basic/EncodedSequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#ifndef SWIFT_BASIC_ENCODEDSEQUENCE_H
#define SWIFT_BASIC_ENCODEDSEQUENCE_H

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

Expand Down
13 changes: 7 additions & 6 deletions include/swift/Basic/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define SWIFT_BASIC_TYPETRAITS_H

#include <type_traits>
#include "swift/Basic/Compiler.h"

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

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

template<typename T>
struct IsTriviallyDestructible {
#if _LIBCPP_VERSION || (defined(_MSC_VER) && !defined(__clang__))
// libc++ implements it.
#if _LIBCPP_VERSION || COMPILER_IS_MSVC
// libc++ and MSVC implement is_trivially_destructible.
static const bool value = std::is_trivially_destructible<T>::value;
#elif __has_feature(has_trivial_destructor)
static const bool value = __has_trivial_destructor(T);
Expand Down
6 changes: 4 additions & 2 deletions include/swift/SIL/SILOpenedArchetypesTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef SWIFT_SIL_SILOPENEDARCHETYPESTRACKER_H
#define SWIFT_SIL_SILOPENEDARCHETYPESTRACKER_H

#include "swift/Basic/Compiler.h"
#include "swift/SIL/Notifications.h"
#include "swift/SIL/SILModule.h"
#include "swift/SIL/SILFunction.h"
Expand All @@ -21,7 +22,8 @@
namespace swift {

// Disable MSVC warning: multiple copy constructors specified.
#if defined(_MSC_VER)
// TODO: silence this warning.
#if COMPILER_IS_MSVC
#pragma warning(push)
#pragma warning(disable: 4521)
#endif
Expand Down Expand Up @@ -134,7 +136,7 @@ class SILOpenedArchetypesTracker : public DeleteNotificationHandler {
OpenedArchetypeDefsMap LocalOpenedArchetypeDefs;
};

#if defined(_MSC_VER)
#if COMPILER_IS_MSVC
#pragma warning(pop)
#endif

Expand Down
5 changes: 3 additions & 2 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "swift/AST/RawComment.h"
#include "swift/AST/SILLayout.h"
#include "swift/AST/TypeCheckerDebugConsumer.h"
#include "swift/Basic/Compiler.h"
#include "swift/Basic/Fallthrough.h"
#include "swift/Basic/SourceManager.h"
#include "swift/Basic/StringExtras.h"
Expand Down Expand Up @@ -277,12 +278,12 @@ struct ASTContext::Implementation {
conformance.~SpecializedProtocolConformance();
// Work around MSVC warning: local variable is initialized but
// not referenced.
#if defined(_MSC_VER)
#if COMPILER_IS_MSVC
#pragma warning (disable: 4189)
#endif
for (auto &conformance : InheritedConformances)
conformance.~InheritedProtocolConformance();
#if defined(_MSC_VER)
#if COMPILER_IS_MSVC
#pragma warning (default: 4189)
#endif

Expand Down
5 changes: 3 additions & 2 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "swift/AST/ReferencedNameTracker.h"
#include "swift/AST/PrettyStackTrace.h"
#include "swift/AST/PrintOptions.h"
#include "swift/Basic/Compiler.h"
#include "swift/Basic/SourceManager.h"
#include "clang/Basic/Module.h"
#include "llvm/ADT/DenseMap.h"
Expand Down Expand Up @@ -841,8 +842,8 @@ namespace {

template <typename T>
struct OperatorLookup {
// This assertion fails in MSVC, but not clang-cl.
#if !defined(_MSC_VER) || defined(__clang__)
// TODO: this assertion fails in MSVC, but not clang-cl.
#if !COMPILER_IS_MSVC
static_assert(static_cast<T*>(nullptr), "Only usable with operators");
#endif
};
Expand Down
7 changes: 4 additions & 3 deletions lib/Sema/Constraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "Constraint.h"
#include "ConstraintSystem.h"
#include "swift/AST/Types.h"
#include "swift/Basic/Compiler.h"
#include "swift/Basic/Fallthrough.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/SaveAndRestore.h"
Expand Down Expand Up @@ -332,13 +333,13 @@ void Constraint::dump(ConstraintSystem *CS) const {
// Print all type variables as $T0 instead of _ here.
llvm::SaveAndRestore<bool> X(CS->getASTContext().LangOpts.
DebugConstraintSolver, true);
// Disabled MSVC warning: only for use within the debugger
#if defined(_MSC_VER)
// Disable MSVC warning: only for use within the debugger.
#if COMPILER_IS_MSVC
#pragma warning(push)
#pragma warning(disable: 4996)
#endif
dump(&CS->getASTContext().SourceMgr);
#if defined(_MSC_VER)
#if COMPILER_IS_MSVC
#pragma warning(pop)
#endif
}
Expand Down