Skip to content

Commit 5c0afe9

Browse files
authored
Merge pull request #5954 from hughbe/sil-msvc
Fix errors and warnings building swift/SIL on Windows using MSVC
2 parents 75b4be6 + 36100bf commit 5c0afe9

19 files changed

+100
-7
lines changed

include/swift/SIL/Projection.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ inline bool isStrictSubSeqRelation(SubSeqRelation_t Seq) {
6161
case SubSeqRelation_t::RHSStrictSubSeqOfLHS:
6262
return true;
6363
}
64+
65+
llvm_unreachable("Unhandled SubSeqRelation_t in switch.");
6466
}
6567

6668
/// Extract an integer index from a SILValue.
@@ -306,6 +308,8 @@ class Projection {
306308
// Index types do not change the underlying type.
307309
return BaseType;
308310
}
311+
312+
llvm_unreachable("Unhandled ProjectionKind in switch.");
309313
}
310314

311315
VarDecl *getVarDecl(SILType BaseType) const {
@@ -431,6 +435,8 @@ class Projection {
431435
case ProjectionKind::Box:
432436
return false;
433437
}
438+
439+
llvm_unreachable("Unhandled ProjectionKind in switch.");
434440
}
435441

436442
bool isNominalKind() const {
@@ -448,6 +454,8 @@ class Projection {
448454
case ProjectionKind::TailElems:
449455
return false;
450456
}
457+
458+
llvm_unreachable("Unhandled ProjectionKind in switch.");
451459
}
452460

453461
/// Form an aggregate of type BaseType using the SILValue Values. Returns the

include/swift/SIL/SILAllocated.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ class SILAllocated {
2828
void *operator new(size_t) = delete;
2929
void *operator new[](size_t) = delete;
3030

31+
// Work around MSVC error: attempting to reference a deleted function.
32+
#if !defined(_MSC_VER) || defined(__clang__)
3133
/// Disable non-placement delete.
3234
void operator delete(void *) = delete;
35+
#endif
3336
void operator delete[](void *) = delete;
3437

3538
/// Custom version of 'new' that uses the SILModule's BumpPtrAllocator with

include/swift/SIL/SILArgument.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ SILFunctionType::getSILArgumentConvention(unsigned index) const {
3636

3737
class SILArgument : public ValueBase {
3838
void operator=(const SILArgument &) = delete;
39+
40+
// Work around MSVC error: attempting to reference a deleted function.
41+
#if !defined(_MSC_VER) || defined(__clang__)
3942
void operator delete(void *Ptr, size_t) = delete;
43+
#endif
4044

4145
SILBasicBlock *ParentBB;
4246
const ValueDecl *Decl;

include/swift/SIL/SILBasicBlock.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ public llvm::ilist_node<SILBasicBlock>, public SILAllocated<SILBasicBlock> {
5252
friend struct llvm::ilist_traits<SILBasicBlock>;
5353
SILBasicBlock() : Parent(nullptr) {}
5454
void operator=(const SILBasicBlock &) = delete;
55+
56+
// Work around MSVC error: attempting to reference a deleted function.
57+
#if !defined(_MSC_VER) || defined(__clang__)
5558
void operator delete(void *Ptr, size_t) = delete;
59+
#endif
5660

5761
SILBasicBlock(SILFunction *F, SILBasicBlock *afterBB = nullptr);
5862

include/swift/SIL/SILInstruction.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ class SILInstruction : public ValueBase,public llvm::ilist_node<SILInstruction>{
8080

8181
SILInstruction() = delete;
8282
void operator=(const SILInstruction &) = delete;
83+
84+
// Work around MSVC error: attempting to reference a deleted function.
85+
#if !defined(_MSC_VER) || defined(__clang__)
8386
void operator delete(void *Ptr, size_t) = delete;
87+
#endif
8488

8589
/// Check any special state of instructions that are not represented in the
8690
/// instructions operands/type.
@@ -459,8 +463,15 @@ class UnaryInstructionWithTypeDependentOperandsBase :
459463
}
460464
}
461465

466+
// Work around MSVC bug: can't infer llvm::trailing_objects_internal,
467+
// even though we granted friend access to it.
462468
size_t numTrailingObjects(
469+
#if defined(_MSC_VER) && !defined(__clang__)
470+
llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken<
471+
Operand>) const {
472+
#else
463473
typename TrailingBase::template OverloadToken<Operand>) const {
474+
#endif
464475
return NumOperands;
465476
}
466477

@@ -2302,8 +2313,16 @@ class BindMemoryInst final :
23022313
SILType getBoundType() const { return BoundType ; }
23032314

23042315
// Implement llvm::TrailingObjects.
2316+
2317+
// Work around MSVC bug: can't infer llvm::trailing_objects_internal,
2318+
// even though we granted friend access to it.
23052319
size_t numTrailingObjects(
2320+
#if defined(_MSC_VER) && !defined(__clang__)
2321+
llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken<
2322+
Operand>) const {
2323+
#else
23062324
typename TrailingBase::template OverloadToken<Operand>) const {
2325+
#endif
23072326
return NumOperands;
23082327
}
23092328

include/swift/SIL/SILLinkage.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#ifndef SWIFT_SIL_SILLINKAGE_H
1414
#define SWIFT_SIL_SILLINKAGE_H
1515

16+
#include "llvm/Support/ErrorHandling.h"
17+
1618
namespace swift {
1719

1820
/// Linkage for a SIL object. This concept combines the notions
@@ -146,6 +148,8 @@ inline bool hasPublicVisibility(SILLinkage linkage) {
146148
case SILLinkage::HiddenExternal:
147149
return false;
148150
}
151+
152+
llvm_unreachable("Unhandled SILLinkage in switch.");
149153
}
150154

151155
inline bool hasSharedVisibility(SILLinkage linkage) {
@@ -161,6 +165,8 @@ inline bool hasSharedVisibility(SILLinkage linkage) {
161165
case SILLinkage::PrivateExternal:
162166
return false;
163167
}
168+
169+
llvm_unreachable("Unhandled SILLinkage in switch.");
164170
}
165171

166172
inline bool hasPrivateVisibility(SILLinkage linkage) {
@@ -176,6 +182,8 @@ inline bool hasPrivateVisibility(SILLinkage linkage) {
176182
case SILLinkage::SharedExternal:
177183
return false;
178184
}
185+
186+
llvm_unreachable("Unhandled SILLinkage in switch.");
179187
}
180188

181189
/// Returns true if l1 is less visible than l2.

include/swift/SIL/SILOpenedArchetypesTracker.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020

2121
namespace swift {
2222

23+
// Disable MSVC warning: multiple copy constructors specified.
24+
#if defined(_MSC_VER)
25+
#pragma warning(push)
26+
#pragma warning(disable: 4521)
27+
#endif
28+
2329
/// SILOpenedArchetypesTracker is a helper class that can be used to create
2430
/// and maintain a mapping from opened archetypes to instructions
2531
/// defining them, e.g. open_existential_ref, open_existential_addr,
@@ -117,17 +123,21 @@ class SILOpenedArchetypesTracker : public DeleteNotificationHandler {
117123
private:
118124
// Never copy
119125
SILOpenedArchetypesTracker &operator = (const SILOpenedArchetypesTracker &) = delete;
120-
121126
/// The function whose opened archetypes are being tracked.
122127
/// Used only for verification purposes.
123128
const SILFunction &F;
129+
124130
/// Mapping from opened archetypes to their definitions.
125131
OpenedArchetypeDefsMap &OpenedArchetypeDefs;
126132
/// Local map to be used if no other map was provided in the
127133
/// constructor.
128134
OpenedArchetypeDefsMap LocalOpenedArchetypeDefs;
129135
};
130136

137+
#if defined(_MSC_VER)
138+
#pragma warning(pop)
139+
#endif
140+
131141
// A state object containing information about opened archetypes.
132142
// This information can be used by constructors of SILInstructions,
133143
// their create methods, etc.

include/swift/SIL/SILUndef.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ namespace swift {
2020

2121
class SILUndef : public ValueBase {
2222
void operator=(const SILArgument &) = delete;
23+
24+
// Work around MSVC error: attempting to reference a deleted function.
25+
#if !defined(_MSC_VER) || defined(__clang__)
2326
void operator delete(void *Ptr, size_t) = delete;
27+
#endif
2428

2529
SILUndef(SILType Ty) : ValueBase(ValueKind::SILUndef, Ty) {}
2630
public:

lib/SIL/AbstractionPattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ AbstractionPattern::getTupleElementType(unsigned index) const {
303303
if (errorInfo.isErrorParameterReplacedWithVoid()) {
304304
if (paramIndex == errorParamIndex) {
305305
assert(isVoidLike(swiftEltType));
306-
(void) isVoidLike;
306+
(void)&isVoidLike;
307307
return AbstractionPattern(swiftEltType);
308308
}
309309
} else {

lib/SIL/Bridging.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ Type TypeConverter::getLoweredBridgedType(AbstractionPattern pattern,
132132
return getLoweredCBridgedType(pattern, t, canBridgeBool,
133133
purpose == ForResult);
134134
}
135+
136+
llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch.");
135137
};
136138

137139
Type TypeConverter::getLoweredCBridgedType(AbstractionPattern pattern,

0 commit comments

Comments
 (0)