Skip to content

Commit ba3972f

Browse files
committed
[AST] Abort the process when type variable id overflows
1 parent 1a26b3c commit ba3972f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

include/swift/AST/Types.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5224,8 +5224,11 @@ TypeVariableType : public TypeBase {
52245224
TypeVariableType(const ASTContext &C, unsigned ID)
52255225
: TypeBase(TypeKind::TypeVariable, &C,
52265226
RecursiveTypeProperties::HasTypeVariable) {
5227-
// Note: the ID may overflow, but its only used for printing.
5227+
// Note: the ID may overflow (current limit is 2^20 - 1).
52285228
Bits.TypeVariableType.ID = ID;
5229+
if (Bits.TypeVariableType.ID != ID) {
5230+
llvm::report_fatal_error("Type variable id overflow");
5231+
}
52295232
}
52305233

52315234
class Implementation;
@@ -5261,8 +5264,10 @@ TypeVariableType : public TypeBase {
52615264
return reinterpret_cast<Implementation *>(this + 1);
52625265
}
52635266

5264-
/// Type variable IDs are not globally unique and are only meant as a visual
5265-
/// aid when dumping AST.
5267+
/// Type variable IDs are not globally unique and are
5268+
/// used in equivalence class merging (so representative
5269+
/// is always a type variable with smaller id), as well
5270+
/// as a visual aid when dumping AST.
52665271
unsigned getID() const { return Bits.TypeVariableType.ID; }
52675272

52685273
// Implement isa/cast/dyncast/etc.

0 commit comments

Comments
 (0)