@@ -289,7 +289,8 @@ class alignas(1 << TypeAlignInBits) TypeBase {
289
289
290
290
// / Extra information which affects how the function is called, like
291
291
// / regparm and the calling convention.
292
- unsigned ExtInfo : 7 ;
292
+ enum { NumExtInfoBits = 7 };
293
+ unsigned ExtInfo : NumExtInfoBits;
293
294
};
294
295
enum { NumAnyFunctionTypeBits = NumTypeBaseBits + 7 };
295
296
static_assert (NumAnyFunctionTypeBits <= 32 , " fits in an unsigned" );
@@ -316,7 +317,8 @@ class alignas(1 << TypeAlignInBits) TypeBase {
316
317
317
318
struct SILFunctionTypeBitfields {
318
319
unsigned : NumTypeBaseBits;
319
- unsigned ExtInfo : 6 ;
320
+ enum { NumExtInfoBits = 6 };
321
+ unsigned ExtInfo : NumExtInfoBits;
320
322
unsigned CalleeConvention : 3 ;
321
323
unsigned HasErrorResult : 1 ;
322
324
unsigned CoroutineKind : 2 ;
@@ -2392,20 +2394,21 @@ class AnyFunctionType : public TypeBase {
2392
2394
// / \brief A class which abstracts out some details necessary for
2393
2395
// / making a call.
2394
2396
class ExtInfo {
2395
- // NOTE: If bits are added or removed, then TypeBase::AnyFunctionTypeBits
2396
- // must be updated to match.
2397
-
2397
+ // If bits are added or removed, then TypeBase::AnyFunctionTypeBits
2398
+ // and NumMaskBits must be updated, and they must match.
2399
+ //
2398
2400
// |representation|isAutoClosure|noEscape|throws|
2399
2401
// | 0 .. 3 | 4 | 5 | 6 |
2400
2402
//
2401
2403
enum : unsigned {
2402
- RepresentationMask = 0x0F ,
2403
- AutoClosureMask = 0x10 ,
2404
- NoEscapeMask = 0x20 ,
2405
- ThrowsMask = 0x40 ,
2404
+ RepresentationMask = 0xF << 0 ,
2405
+ AutoClosureMask = 1 << 4 ,
2406
+ NoEscapeMask = 1 << 5 ,
2407
+ ThrowsMask = 1 << 6 ,
2408
+ NumMaskBits = 7
2406
2409
};
2407
2410
2408
- unsigned Bits;
2411
+ unsigned Bits; // Naturally sized for speed.
2409
2412
2410
2413
ExtInfo (unsigned Bits) : Bits(Bits) {}
2411
2414
@@ -2505,7 +2508,7 @@ class AnyFunctionType : public TypeBase {
2505
2508
return ExtInfo (Bits & ~ThrowsMask);
2506
2509
}
2507
2510
2508
- uint16_t getFuncAttrKey () const {
2511
+ unsigned getFuncAttrKey () const {
2509
2512
return Bits;
2510
2513
}
2511
2514
@@ -2539,7 +2542,11 @@ class AnyFunctionType : public TypeBase {
2539
2542
: TypeBase(Kind, CanTypeContext, properties), Input(Input), Output(Output),
2540
2543
NumParams (NumParams) {
2541
2544
AnyFunctionTypeBits.ExtInfo = Info.Bits ;
2545
+ // The use of both assert() and static_assert() is intentional.
2542
2546
assert (AnyFunctionTypeBits.ExtInfo == Info.Bits && " Bits were dropped!" );
2547
+ static_assert (ExtInfo::NumMaskBits ==
2548
+ AnyFunctionTypeBitfields::NumExtInfoBits,
2549
+ " ExtInfo and AnyFunctionTypeBitfields must agree on bit size" );
2543
2550
}
2544
2551
2545
2552
public:
@@ -3249,19 +3256,20 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
3249
3256
// / \brief A class which abstracts out some details necessary for
3250
3257
// / making a call.
3251
3258
class ExtInfo {
3252
- // NOTE: If bits are added or removed, then TypeBase::SILFunctionTypeBits
3253
- // must be updated to match.
3259
+ // If bits are added or removed, then TypeBase::SILFunctionTypeBits
3260
+ // and NumMaskBits must be updated, and they must match.
3254
3261
3255
3262
// |representation|pseudogeneric| noescape |
3256
3263
// | 0 .. 3 | 4 | 5 |
3257
3264
//
3258
3265
enum : unsigned {
3259
- RepresentationMask = 0x0F ,
3260
- PseudogenericMask = 0x10 ,
3261
- NoEscapeMask = 0x20 ,
3266
+ RepresentationMask = 0xF << 0 ,
3267
+ PseudogenericMask = 1 << 4 ,
3268
+ NoEscapeMask = 1 << 5 ,
3269
+ NumMaskBits = 6
3262
3270
};
3263
3271
3264
- unsigned Bits;
3272
+ unsigned Bits; // Naturally sized for speed.
3265
3273
3266
3274
ExtInfo (unsigned Bits) : Bits(Bits) {}
3267
3275
@@ -3364,7 +3372,7 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
3364
3372
return ExtInfo (Bits & ~NoEscapeMask);
3365
3373
}
3366
3374
3367
- uint16_t getFuncAttrKey () const {
3375
+ unsigned getFuncAttrKey () const {
3368
3376
return Bits;
3369
3377
}
3370
3378
0 commit comments