Skip to content

Commit 6b915c5

Browse files
adriwebcodex
andcommitted
clang/AST/Type: fix sizeof static assertion on Windows.
Co-Authored-By: Codex CLI <codex@openai.com>
1 parent 3da5349 commit 6b915c5

2 files changed

Lines changed: 20 additions & 34 deletions

File tree

clang/include/clang/AST/Type.h

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,21 +2226,6 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
22262226
unsigned NumExpansions;
22272227
};
22282228

2229-
class CountAttributedTypeBitfields {
2230-
friend class CountAttributedType;
2231-
2232-
LLVM_PREFERRED_TYPE(TypeBitfields)
2233-
unsigned : NumTypeBits;
2234-
2235-
static constexpr unsigned NumCoupledDeclsBits = 4;
2236-
unsigned NumCoupledDecls : NumCoupledDeclsBits;
2237-
LLVM_PREFERRED_TYPE(bool)
2238-
unsigned CountInBytes : 1;
2239-
LLVM_PREFERRED_TYPE(bool)
2240-
unsigned OrNull : 1;
2241-
};
2242-
static_assert(sizeof(CountAttributedTypeBitfields) <= sizeof(unsigned));
2243-
22442229
union {
22452230
TypeBitfields TypeBits;
22462231
ArrayTypeBitfields ArrayTypeBits;
@@ -2263,7 +2248,6 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
22632248
DependentTemplateSpecializationTypeBitfields
22642249
DependentTemplateSpecializationTypeBits;
22652250
PackExpansionTypeBitfields PackExpansionTypeBits;
2266-
CountAttributedTypeBitfields CountAttributedTypeBits;
22672251
};
22682252

22692253
private:
@@ -3269,7 +3253,19 @@ class CountAttributedType final
32693253
TypeCoupledDeclRefInfo> {
32703254
friend class ASTContext;
32713255

3256+
public:
3257+
enum DynamicCountPointerKind {
3258+
CountedBy = 0,
3259+
SizedBy,
3260+
CountedByOrNull,
3261+
SizedByOrNull,
3262+
};
3263+
3264+
private:
32723265
Expr *CountExpr;
3266+
LLVM_PREFERRED_TYPE(DynamicCountPointerKind)
3267+
unsigned Kind : 2;
3268+
32733269
/// \p CountExpr represents the argument of __counted_by or the likes. \p
32743270
/// CountInBytes indicates that \p CountExpr is a byte count (i.e.,
32753271
/// __sized_by(_or_null)) \p OrNull means it's an or_null variant (i.e.,
@@ -3281,29 +3277,20 @@ class CountAttributedType final
32813277
ArrayRef<TypeCoupledDeclRefInfo> CoupledDecls);
32823278

32833279
unsigned numTrailingObjects(OverloadToken<TypeCoupledDeclRefInfo>) const {
3284-
return CountAttributedTypeBits.NumCoupledDecls;
3280+
return Decls.size();
32853281
}
32863282

32873283
public:
3288-
enum DynamicCountPointerKind {
3289-
CountedBy = 0,
3290-
SizedBy,
3291-
CountedByOrNull,
3292-
SizedByOrNull,
3293-
};
3294-
32953284
Expr *getCountExpr() const { return CountExpr; }
3296-
bool isCountInBytes() const { return CountAttributedTypeBits.CountInBytes; }
3297-
bool isOrNull() const { return CountAttributedTypeBits.OrNull; }
3285+
bool isCountInBytes() const { return static_cast<unsigned>(getKind()) & 1; }
3286+
bool isOrNull() const { return static_cast<unsigned>(getKind()) & 2; }
32983287

32993288
DynamicCountPointerKind getKind() const {
3300-
if (isOrNull())
3301-
return isCountInBytes() ? SizedByOrNull : CountedByOrNull;
3302-
return isCountInBytes() ? SizedBy : CountedBy;
3289+
return static_cast<DynamicCountPointerKind>(Kind);
33033290
}
33043291

33053292
void Profile(llvm::FoldingSetNodeID &ID) {
3306-
Profile(ID, desugar(), CountExpr, isCountInBytes(), isOrNull());
3293+
Profile(ID, desugar(), getCountExpr(), isCountInBytes(), isOrNull());
33073294
}
33083295

33093296
static void Profile(llvm::FoldingSetNodeID &ID, QualType WrappedTy,

clang/lib/AST/Type.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3849,10 +3849,9 @@ CountAttributedType::CountAttributedType(
38493849
QualType Wrapped, QualType Canon, Expr *CountExpr, bool CountInBytes,
38503850
bool OrNull, ArrayRef<TypeCoupledDeclRefInfo> CoupledDecls)
38513851
: BoundsAttributedType(CountAttributed, Wrapped, Canon),
3852-
CountExpr(CountExpr) {
3853-
CountAttributedTypeBits.NumCoupledDecls = CoupledDecls.size();
3854-
CountAttributedTypeBits.CountInBytes = CountInBytes;
3855-
CountAttributedTypeBits.OrNull = OrNull;
3852+
CountExpr(CountExpr),
3853+
Kind(OrNull ? (CountInBytes ? SizedByOrNull : CountedByOrNull)
3854+
: (CountInBytes ? SizedBy : CountedBy)) {
38563855
auto *DeclSlot = getTrailingObjects<TypeCoupledDeclRefInfo>();
38573856
Decls = llvm::ArrayRef(DeclSlot, CoupledDecls.size());
38583857
for (unsigned i = 0; i != CoupledDecls.size(); ++i)

0 commit comments

Comments
 (0)