Skip to content

Fix errors and warnings building swift/reflection on Windows with MSVC #6026

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
Dec 12, 2016
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
12 changes: 6 additions & 6 deletions include/swift/Reflection/MetadataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class MetadataSource {
unsigned Index;
if (!decodeNatural(it, end, Index))
return nullptr;
return A.template createClosureBinding(Index);
return A.createClosureBinding(Index);
}

template <typename Allocator>
Expand All @@ -95,7 +95,7 @@ class MetadataSource {
unsigned Index;
if (!decodeNatural(it, end, Index))
return nullptr;
return A.template createReferenceCapture(Index);
return A.createReferenceCapture(Index);
}

template <typename Allocator>
Expand All @@ -114,7 +114,7 @@ class MetadataSource {
unsigned Index;
if (!decodeNatural(it, end, Index))
return nullptr;
return A.template createMetadataCapture(Index);
return A.createMetadataCapture(Index);
}

template <typename Allocator>
Expand Down Expand Up @@ -143,7 +143,7 @@ class MetadataSource {

++it;

return A.template createGenericArgument(Index, Source);
return A.createGenericArgument(Index, Source);
}

template <typename Allocator>
Expand All @@ -162,7 +162,7 @@ class MetadataSource {
if (it == end || *it != '_')
return nullptr;

return A.template createParent(Child);
return A.createParent(Child);
}

template <typename Allocator>
Expand All @@ -184,7 +184,7 @@ class MetadataSource {
return decodeParent(A, it, end);
case 'S':
++it;
return A.template createSelf();
return A.createSelf();
default:
return nullptr;
}
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Reflection/ReflectionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef SWIFT_REFLECTION_REFLECTIONCONTEXT_H
#define SWIFT_REFLECTION_REFLECTIONCONTEXT_H

#include "swift/Basic/Unreachable.h"
#include "swift/Remote/MemoryReader.h"
#include "swift/Remote/MetadataReader.h"
#include "swift/Reflection/Records.h"
Expand Down Expand Up @@ -452,6 +453,8 @@ class ReflectionContext
case MetadataSourceKind::SelfWitnessTable:
return true;
}

swift_unreachable("Unhandled MetadataSourceKind in switch.");
}

/// Read metadata for a captured generic type from a closure context.
Expand Down
26 changes: 19 additions & 7 deletions include/swift/Reflection/TypeRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/Casting.h"
#include "swift/ABI/MetadataValues.h"
#include "swift/Basic/Unreachable.h"

#include <iostream>

Expand All @@ -36,13 +37,22 @@ enum class TypeRefKind {
#undef TYPEREF
};

#define FIND_OR_CREATE_TYPEREF(Allocator, TypeRefTy, ...) \
auto ID = Profile(__VA_ARGS__); \
const auto Entry = Allocator.template TypeRefTy##s.find(ID); \
if (Entry != Allocator.template TypeRefTy##s.end()) \
return Entry->second; \
const auto TR = Allocator.template makeTypeRef<TypeRefTy>(__VA_ARGS__); \
Allocator.template TypeRefTy##s.insert({ID, TR}); \
// MSVC reports an error if we use "template"
// Clang reports an error if we don't use "template"
#if defined(__clang__) || defined(__GNUC__)
#define DEPENDENT_TEMPLATE template
#else
#define DEPENDENT_TEMPLATE
#endif

#define FIND_OR_CREATE_TYPEREF(Allocator, TypeRefTy, ...) \
auto ID = Profile(__VA_ARGS__); \
const auto Entry = Allocator.DEPENDENT_TEMPLATE TypeRefTy##s.find(ID); \
if (Entry != Allocator.DEPENDENT_TEMPLATE TypeRefTy##s.end()) \
return Entry->second; \
const auto TR = \
Allocator.DEPENDENT_TEMPLATE makeTypeRef<TypeRefTy>(__VA_ARGS__); \
Allocator.DEPENDENT_TEMPLATE TypeRefTy##s.insert({ID, TR}); \
Copy link
Member

Choose a reason for hiding this comment

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

We should file a SR to address this difference and try to unify the behavior once the compilers are updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

return TR;

/// An identifier containing the unique bit pattern made up of all of the
Expand Down Expand Up @@ -772,6 +782,8 @@ class TypeRefVisitor {
::std::forward<Args>(args)...);
#include "swift/Reflection/TypeRefs.def"
}

swift_unreachable("Unhandled TypeRefKind in switch.");
}
};

Expand Down
17 changes: 10 additions & 7 deletions stdlib/public/Reflection/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//===----------------------------------------------------------------------===//

#include "swift/Reflection/TypeLowering.h"
#include "swift/Basic/Unreachable.h"
#include "swift/Reflection/TypeRef.h"
#include "swift/Reflection/TypeRefBuilder.h"

Expand All @@ -30,12 +31,6 @@
#define DEBUG(expr)
#endif

[[noreturn]]
static void unreachable(const char *Message) {
std::cerr << "fatal error: " << Message << "\n";
std::abort();
}

namespace swift {
namespace reflection {

Expand Down Expand Up @@ -191,7 +186,7 @@ class PrintTypeInfo {
}
}

unreachable("Bad TypeInfo kind");
swift_unreachable("Bad TypeInfo kind");
}
};

Expand Down Expand Up @@ -1047,6 +1042,8 @@ class LowerType
DEBUG(std::cerr << "Invalid field descriptor: "; TR->dump());
return nullptr;
}

swift_unreachable("Unhandled FieldDescriptorKind in switch.");
}

const TypeInfo *visitNominalTypeRef(const NominalTypeRef *N) {
Expand Down Expand Up @@ -1076,6 +1073,8 @@ class LowerType
case FunctionMetadataConvention::CFunctionPointer:
return TC.getTypeInfo(TC.getThinFunctionTypeRef());
}

swift_unreachable("Unhandled FunctionMetadataConvention in switch.");
}

const TypeInfo *visitProtocolTypeRef(const ProtocolTypeRef *P) {
Expand All @@ -1102,6 +1101,8 @@ class LowerType
case MetatypeRepresentation::Thick:
return TC.getTypeInfo(TC.getAnyMetatypeTypeRef());
}

swift_unreachable("Unhandled MetatypeRepresentation in switch.");
}

const TypeInfo *
Expand Down Expand Up @@ -1283,6 +1284,8 @@ const TypeInfo *TypeConverter::getClassInstanceTypeInfo(const TypeRef *TR,
DEBUG(std::cerr << "Invalid field descriptor: "; TR->dump());
return nullptr;
}

swift_unreachable("Unhandled FieldDescriptorKind in switch.");
}

} // namespace reflection
Expand Down
4 changes: 4 additions & 0 deletions tools/swift-reflection-dump/swift-reflection-dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
#include "llvm/Object/ELF.h"
#include "llvm/Support/CommandLine.h"

#if defined(_WIN32)
#include <io.h>
#else
#include <unistd.h>
#endif

#include <algorithm>
#include <iostream>
Expand Down