Skip to content

Commit f739411

Browse files
committed
Move ParamDecl's IsCompileTimeConst bit elsewhere.
PointerIntPair shouldn't be used with 4 low bits, because the allocator won't necessarily provide enough padding. Move the recently-added IsCompileTimeConst bit into a separate field. Fixes rdar://87614547.
1 parent dd4fea1 commit f739411

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

include/swift/AST/Decl.h

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5458,7 +5458,16 @@ class ParamDecl : public VarDecl {
54585458
friend class DefaultArgumentInitContextRequest;
54595459
friend class DefaultArgumentExprRequest;
54605460

5461-
llvm::PointerIntPair<Identifier, 1, bool> ArgumentNameAndDestructured;
5461+
enum class ArgumentNameFlags : uint8_t {
5462+
/// Whether or not this parameter is destructed.
5463+
Destructured = 1 << 0,
5464+
5465+
/// Whether or not this parameter is '_const'.
5466+
IsCompileTimeConst = 1 << 1,
5467+
};
5468+
5469+
llvm::PointerIntPair<Identifier, 2, OptionSet<ArgumentNameFlags>>
5470+
ArgumentNameAndFlags;
54625471
SourceLoc ParameterNameLoc;
54635472
SourceLoc ArgumentNameLoc;
54645473
SourceLoc SpecifierLoc;
@@ -5489,13 +5498,10 @@ class ParamDecl : public VarDecl {
54895498

54905499
/// Whether or not this parameter is 'isolated'.
54915500
IsIsolated = 1 << 2,
5492-
5493-
/// Whether or not this parameter is '_const'.
5494-
IsCompileTimeConst = 1 << 3,
54955501
};
54965502

54975503
/// The default value, if any, along with flags.
5498-
llvm::PointerIntPair<StoredDefaultArgument *, 4, OptionSet<Flags>>
5504+
llvm::PointerIntPair<StoredDefaultArgument *, 3, OptionSet<Flags>>
54995505
DefaultValueAndFlags;
55005506

55015507
friend class ParamSpecifierRequest;
@@ -5513,7 +5519,7 @@ class ParamDecl : public VarDecl {
55135519

55145520
/// Retrieve the argument (API) name for this function parameter.
55155521
Identifier getArgumentName() const {
5516-
return ArgumentNameAndDestructured.getPointer();
5522+
return ArgumentNameAndFlags.getPointer();
55175523
}
55185524

55195525
/// Retrieve the parameter (local) name for this function parameter.
@@ -5533,8 +5539,17 @@ class ParamDecl : public VarDecl {
55335539
TypeRepr *getTypeRepr() const { return TyRepr; }
55345540
void setTypeRepr(TypeRepr *repr) { TyRepr = repr; }
55355541

5536-
bool isDestructured() const { return ArgumentNameAndDestructured.getInt(); }
5537-
void setDestructured(bool repr) { ArgumentNameAndDestructured.setInt(repr); }
5542+
bool isDestructured() const {
5543+
auto flags = ArgumentNameAndFlags.getInt();
5544+
return flags.contains(ArgumentNameFlags::Destructured);
5545+
}
5546+
5547+
void setDestructured(bool repr) {
5548+
auto flags = ArgumentNameAndFlags.getInt();
5549+
flags = repr ? flags | ArgumentNameFlags::Destructured
5550+
: flags - ArgumentNameFlags::Destructured;
5551+
ArgumentNameAndFlags.setInt(flags);
5552+
}
55385553

55395554
DefaultArgumentKind getDefaultArgumentKind() const {
55405555
return static_cast<DefaultArgumentKind>(Bits.ParamDecl.defaultArgumentKind);
@@ -5666,13 +5681,15 @@ class ParamDecl : public VarDecl {
56665681

56675682
/// Whether or not this parameter is marked with '_const'.
56685683
bool isCompileTimeConst() const {
5669-
return DefaultValueAndFlags.getInt().contains(Flags::IsCompileTimeConst);
5684+
return ArgumentNameAndFlags.getInt().contains(
5685+
ArgumentNameFlags::IsCompileTimeConst);
56705686
}
56715687

56725688
void setCompileTimeConst(bool value = true) {
5673-
auto flags = DefaultValueAndFlags.getInt();
5674-
DefaultValueAndFlags.setInt(value ? flags | Flags::IsCompileTimeConst
5675-
: flags - Flags::IsCompileTimeConst);
5689+
auto flags = ArgumentNameAndFlags.getInt();
5690+
flags = value ? flags | ArgumentNameFlags::IsCompileTimeConst
5691+
: flags - ArgumentNameFlags::IsCompileTimeConst;
5692+
ArgumentNameAndFlags.setInt(flags);
56765693
}
56775694

56785695
/// Does this parameter reject temporary pointer conversions?

include/swift/AST/TypeAlignments.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace swift {
7575
constexpr size_t SILFunctionAlignInBits = 2;
7676
constexpr size_t ASTContextAlignInBits = 2;
7777
constexpr size_t TypeVariableAlignInBits = 4;
78-
constexpr size_t StoredDefaultArgumentAlignInBits = 4;
78+
constexpr size_t StoredDefaultArgumentAlignInBits = 3;
7979

8080
// Well, this is the *minimum* pointer alignment; it's going to be 3 on
8181
// 64-bit targets, but that doesn't matter.

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6551,7 +6551,7 @@ ParamDecl::ParamDecl(SourceLoc specifierLoc,
65516551
/*IsStatic*/ false,
65526552
VarDecl::Introducer::Let, parameterNameLoc, parameterName, dc,
65536553
StorageIsNotMutable),
6554-
ArgumentNameAndDestructured(argumentName, false),
6554+
ArgumentNameAndFlags(argumentName, None),
65556555
ParameterNameLoc(parameterNameLoc),
65566556
ArgumentNameLoc(argumentNameLoc), SpecifierLoc(specifierLoc) {
65576557
Bits.ParamDecl.SpecifierComputed = false;

0 commit comments

Comments
 (0)