Skip to content

Commit 137b2ab

Browse files
committed
Fix errors and warnings building swift/reflection on Windows with MSVC
1 parent dbc0cec commit 137b2ab

File tree

5 files changed

+42
-20
lines changed

5 files changed

+42
-20
lines changed

include/swift/Reflection/MetadataSource.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class MetadataSource {
7676
unsigned Index;
7777
if (!decodeNatural(it, end, Index))
7878
return nullptr;
79-
return A.template createClosureBinding(Index);
79+
return A.createClosureBinding(Index);
8080
}
8181

8282
template <typename Allocator>
@@ -95,7 +95,7 @@ class MetadataSource {
9595
unsigned Index;
9696
if (!decodeNatural(it, end, Index))
9797
return nullptr;
98-
return A.template createReferenceCapture(Index);
98+
return A.createReferenceCapture(Index);
9999
}
100100

101101
template <typename Allocator>
@@ -114,7 +114,7 @@ class MetadataSource {
114114
unsigned Index;
115115
if (!decodeNatural(it, end, Index))
116116
return nullptr;
117-
return A.template createMetadataCapture(Index);
117+
return A.createMetadataCapture(Index);
118118
}
119119

120120
template <typename Allocator>
@@ -143,7 +143,7 @@ class MetadataSource {
143143

144144
++it;
145145

146-
return A.template createGenericArgument(Index, Source);
146+
return A.createGenericArgument(Index, Source);
147147
}
148148

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

165-
return A.template createParent(Child);
165+
return A.createParent(Child);
166166
}
167167

168168
template <typename Allocator>
@@ -184,7 +184,7 @@ class MetadataSource {
184184
return decodeParent(A, it, end);
185185
case 'S':
186186
++it;
187-
return A.template createSelf();
187+
return A.createSelf();
188188
default:
189189
return nullptr;
190190
}

include/swift/Reflection/ReflectionContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef SWIFT_REFLECTION_REFLECTIONCONTEXT_H
1919
#define SWIFT_REFLECTION_REFLECTIONCONTEXT_H
2020

21+
#include "swift/Basic/Unreachable.h"
2122
#include "swift/Remote/MemoryReader.h"
2223
#include "swift/Remote/MetadataReader.h"
2324
#include "swift/Reflection/Records.h"
@@ -452,6 +453,8 @@ class ReflectionContext
452453
case MetadataSourceKind::SelfWitnessTable:
453454
return true;
454455
}
456+
457+
swift_unreachable("Unhandled MetadataSourceKind in switch.");
455458
}
456459

457460
/// Read metadata for a captured generic type from a closure context.

include/swift/Reflection/TypeRef.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/ADT/DenseMap.h"
2222
#include "llvm/Support/Casting.h"
2323
#include "swift/ABI/MetadataValues.h"
24+
#include "swift/Basic/Unreachable.h"
2425

2526
#include <iostream>
2627

@@ -36,13 +37,22 @@ enum class TypeRefKind {
3637
#undef TYPEREF
3738
};
3839

39-
#define FIND_OR_CREATE_TYPEREF(Allocator, TypeRefTy, ...) \
40-
auto ID = Profile(__VA_ARGS__); \
41-
const auto Entry = Allocator.template TypeRefTy##s.find(ID); \
42-
if (Entry != Allocator.template TypeRefTy##s.end()) \
43-
return Entry->second; \
44-
const auto TR = Allocator.template makeTypeRef<TypeRefTy>(__VA_ARGS__); \
45-
Allocator.template TypeRefTy##s.insert({ID, TR}); \
40+
// MSVC reports an error if we use "template"
41+
// Clang reports an error if we don't use "template"
42+
#if defined(__clang__) || defined(__GNUC__)
43+
#define DEPENDENT_TEMPLATE template
44+
#else
45+
#define DEPENDENT_TEMPLATE
46+
#endif
47+
48+
#define FIND_OR_CREATE_TYPEREF(Allocator, TypeRefTy, ...) \
49+
auto ID = Profile(__VA_ARGS__); \
50+
const auto Entry = Allocator.DEPENDENT_TEMPLATE TypeRefTy##s.find(ID); \
51+
if (Entry != Allocator.DEPENDENT_TEMPLATE TypeRefTy##s.end()) \
52+
return Entry->second; \
53+
const auto TR = \
54+
Allocator.DEPENDENT_TEMPLATE makeTypeRef<TypeRefTy>(__VA_ARGS__); \
55+
Allocator.DEPENDENT_TEMPLATE TypeRefTy##s.insert({ID, TR}); \
4656
return TR;
4757

4858
/// An identifier containing the unique bit pattern made up of all of the
@@ -772,6 +782,8 @@ class TypeRefVisitor {
772782
::std::forward<Args>(args)...);
773783
#include "swift/Reflection/TypeRefs.def"
774784
}
785+
786+
swift_unreachable("Unhandled TypeRefKind in switch.");
775787
}
776788
};
777789

stdlib/public/Reflection/TypeLowering.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//===----------------------------------------------------------------------===//
2020

2121
#include "swift/Reflection/TypeLowering.h"
22+
#include "swift/Basic/Unreachable.h"
2223
#include "swift/Reflection/TypeRef.h"
2324
#include "swift/Reflection/TypeRefBuilder.h"
2425

@@ -30,12 +31,6 @@
3031
#define DEBUG(expr)
3132
#endif
3233

33-
[[noreturn]]
34-
static void unreachable(const char *Message) {
35-
std::cerr << "fatal error: " << Message << "\n";
36-
std::abort();
37-
}
38-
3934
namespace swift {
4035
namespace reflection {
4136

@@ -191,7 +186,7 @@ class PrintTypeInfo {
191186
}
192187
}
193188

194-
unreachable("Bad TypeInfo kind");
189+
swift_unreachable("Bad TypeInfo kind");
195190
}
196191
};
197192

@@ -1047,6 +1042,8 @@ class LowerType
10471042
DEBUG(std::cerr << "Invalid field descriptor: "; TR->dump());
10481043
return nullptr;
10491044
}
1045+
1046+
swift_unreachable("Unhandled FieldDescriptorKind in switch.");
10501047
}
10511048

10521049
const TypeInfo *visitNominalTypeRef(const NominalTypeRef *N) {
@@ -1076,6 +1073,8 @@ class LowerType
10761073
case FunctionMetadataConvention::CFunctionPointer:
10771074
return TC.getTypeInfo(TC.getThinFunctionTypeRef());
10781075
}
1076+
1077+
swift_unreachable("Unhandled FunctionMetadataConvention in switch.");
10791078
}
10801079

10811080
const TypeInfo *visitProtocolTypeRef(const ProtocolTypeRef *P) {
@@ -1102,6 +1101,8 @@ class LowerType
11021101
case MetatypeRepresentation::Thick:
11031102
return TC.getTypeInfo(TC.getAnyMetatypeTypeRef());
11041103
}
1104+
1105+
swift_unreachable("Unhandled MetatypeRepresentation in switch.");
11051106
}
11061107

11071108
const TypeInfo *
@@ -1283,6 +1284,8 @@ const TypeInfo *TypeConverter::getClassInstanceTypeInfo(const TypeRef *TR,
12831284
DEBUG(std::cerr << "Invalid field descriptor: "; TR->dump());
12841285
return nullptr;
12851286
}
1287+
1288+
swift_unreachable("Unhandled FieldDescriptorKind in switch.");
12861289
}
12871290

12881291
} // namespace reflection

tools/swift-reflection-dump/swift-reflection-dump.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
#include "llvm/Object/ELF.h"
2525
#include "llvm/Support/CommandLine.h"
2626

27+
#if defined(_WIN32)
28+
#include <io.h>
29+
#else
2730
#include <unistd.h>
31+
#endif
2832

2933
#include <algorithm>
3034
#include <iostream>

0 commit comments

Comments
 (0)