Skip to content

Commit cb2dd02

Browse files
authored
[clang][NFC] constify or staticify some CGRecordLowering fns (llvm#82874)
Some CGRecordLowering functions either do not need the object or do not mutate it. Thus marking static or const as appropriate.
1 parent 3356818 commit cb2dd02

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

clang/lib/CodeGen/CGRecordLayoutBuilder.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct CGRecordLowering {
9595
CGRecordLowering(CodeGenTypes &Types, const RecordDecl *D, bool Packed);
9696
// Short helper routines.
9797
/// Constructs a MemberInfo instance from an offset and llvm::Type *.
98-
MemberInfo StorageInfo(CharUnits Offset, llvm::Type *Data) {
98+
static MemberInfo StorageInfo(CharUnits Offset, llvm::Type *Data) {
9999
return MemberInfo(Offset, MemberInfo::Field, Data);
100100
}
101101

@@ -104,7 +104,7 @@ struct CGRecordLowering {
104104
/// fields of the same formal type. We want to emit a layout with
105105
/// these discrete storage units instead of combining them into a
106106
/// continuous run.
107-
bool isDiscreteBitFieldABI() {
107+
bool isDiscreteBitFieldABI() const {
108108
return Context.getTargetInfo().getCXXABI().isMicrosoft() ||
109109
D->isMsStruct(Context);
110110
}
@@ -121,60 +121,60 @@ struct CGRecordLowering {
121121
/// other bases, which complicates layout in specific ways.
122122
///
123123
/// Note specifically that the ms_struct attribute doesn't change this.
124-
bool isOverlappingVBaseABI() {
124+
bool isOverlappingVBaseABI() const {
125125
return !Context.getTargetInfo().getCXXABI().isMicrosoft();
126126
}
127127

128128
/// Wraps llvm::Type::getIntNTy with some implicit arguments.
129-
llvm::Type *getIntNType(uint64_t NumBits) {
129+
llvm::Type *getIntNType(uint64_t NumBits) const {
130130
unsigned AlignedBits = llvm::alignTo(NumBits, Context.getCharWidth());
131131
return llvm::Type::getIntNTy(Types.getLLVMContext(), AlignedBits);
132132
}
133133
/// Get the LLVM type sized as one character unit.
134-
llvm::Type *getCharType() {
134+
llvm::Type *getCharType() const {
135135
return llvm::Type::getIntNTy(Types.getLLVMContext(),
136136
Context.getCharWidth());
137137
}
138138
/// Gets an llvm type of size NumChars and alignment 1.
139-
llvm::Type *getByteArrayType(CharUnits NumChars) {
139+
llvm::Type *getByteArrayType(CharUnits NumChars) const {
140140
assert(!NumChars.isZero() && "Empty byte arrays aren't allowed.");
141141
llvm::Type *Type = getCharType();
142142
return NumChars == CharUnits::One() ? Type :
143143
(llvm::Type *)llvm::ArrayType::get(Type, NumChars.getQuantity());
144144
}
145145
/// Gets the storage type for a field decl and handles storage
146146
/// for itanium bitfields that are smaller than their declared type.
147-
llvm::Type *getStorageType(const FieldDecl *FD) {
147+
llvm::Type *getStorageType(const FieldDecl *FD) const {
148148
llvm::Type *Type = Types.ConvertTypeForMem(FD->getType());
149149
if (!FD->isBitField()) return Type;
150150
if (isDiscreteBitFieldABI()) return Type;
151151
return getIntNType(std::min(FD->getBitWidthValue(Context),
152152
(unsigned)Context.toBits(getSize(Type))));
153153
}
154154
/// Gets the llvm Basesubobject type from a CXXRecordDecl.
155-
llvm::Type *getStorageType(const CXXRecordDecl *RD) {
155+
llvm::Type *getStorageType(const CXXRecordDecl *RD) const {
156156
return Types.getCGRecordLayout(RD).getBaseSubobjectLLVMType();
157157
}
158-
CharUnits bitsToCharUnits(uint64_t BitOffset) {
158+
CharUnits bitsToCharUnits(uint64_t BitOffset) const {
159159
return Context.toCharUnitsFromBits(BitOffset);
160160
}
161-
CharUnits getSize(llvm::Type *Type) {
161+
CharUnits getSize(llvm::Type *Type) const {
162162
return CharUnits::fromQuantity(DataLayout.getTypeAllocSize(Type));
163163
}
164-
CharUnits getAlignment(llvm::Type *Type) {
164+
CharUnits getAlignment(llvm::Type *Type) const {
165165
return CharUnits::fromQuantity(DataLayout.getABITypeAlign(Type));
166166
}
167-
bool isZeroInitializable(const FieldDecl *FD) {
167+
bool isZeroInitializable(const FieldDecl *FD) const {
168168
return Types.isZeroInitializable(FD->getType());
169169
}
170-
bool isZeroInitializable(const RecordDecl *RD) {
170+
bool isZeroInitializable(const RecordDecl *RD) const {
171171
return Types.isZeroInitializable(RD);
172172
}
173173
void appendPaddingBytes(CharUnits Size) {
174174
if (!Size.isZero())
175175
FieldTypes.push_back(getByteArrayType(Size));
176176
}
177-
uint64_t getFieldBitOffset(const FieldDecl *FD) {
177+
uint64_t getFieldBitOffset(const FieldDecl *FD) const {
178178
return Layout.getFieldOffset(FD->getFieldIndex());
179179
}
180180
// Layout routines.

0 commit comments

Comments
 (0)