Skip to content

Commit efbeaea

Browse files
committed
AST: Always-on ASSERTs for ProtocolConformanceRef
If any of the get*() methods are called on the wrong kind of ProtocolConformanceRef, we immediately cast a pointer to an incorrect type, which will most likely cause a crash.
1 parent 012ac5d commit efbeaea

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

include/swift/AST/ProtocolConformanceRef.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "swift/AST/ProtocolConformanceRef.h"
2020
#include "swift/AST/Type.h"
2121
#include "swift/AST/TypeAlignments.h"
22+
#include "swift/Basic/Assertions.h"
2223
#include "swift/Basic/Debug.h"
2324
#include "llvm/ADT/Hashing.h"
2425
#include "llvm/ADT/PointerUnion.h"
@@ -101,13 +102,15 @@ class ProtocolConformanceRef {
101102
return !isInvalid() && Union.is<ProtocolConformance*>();
102103
}
103104
ProtocolConformance *getConcrete() const {
105+
ASSERT(isConcrete());
104106
return Union.get<ProtocolConformance*>();
105107
}
106108

107109
bool isPack() const {
108110
return !isInvalid() && Union.is<PackConformance*>();
109111
}
110112
PackConformance *getPack() const {
113+
ASSERT(isPack());
111114
return Union.get<PackConformance*>();
112115
}
113116

@@ -116,6 +119,7 @@ class ProtocolConformanceRef {
116119
}
117120

118121
ProtocolDecl *getAbstract() const {
122+
ASSERT(isAbstract());
119123
return Union.get<ProtocolDecl*>();
120124
}
121125

lib/AST/ProtocolConformanceRef.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ bool ProtocolConformanceRef::isInvalid() const {
4949
}
5050

5151
ProtocolDecl *ProtocolConformanceRef::getRequirement() const {
52-
assert(!isInvalid());
53-
5452
if (isConcrete()) {
5553
return getConcrete()->getProtocol();
5654
} else if (isPack()) {

0 commit comments

Comments
 (0)