[clang] [NFC] Refactor ConstantArrayType size storage (PR #85716)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 18 16:22:26 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 4841858862df4b8ac4ac68922086f03c8bbd3dc2 4a11a73b4dd41637b1d730489954c2994489d6be -- clang/include/clang/AST/Type.h clang/lib/AST/ASTContext.cpp clang/lib/AST/Decl.cpp clang/lib/AST/ExprConstant.cpp clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/lib/AST/Interp/EvaluationResult.cpp clang/lib/AST/Interp/Program.cpp clang/lib/AST/JSONNodeDumper.cpp clang/lib/AST/MicrosoftMangle.cpp clang/lib/AST/ScanfFormatString.cpp clang/lib/AST/Type.cpp clang/lib/AST/TypePrinter.cpp clang/lib/Analysis/CFG.cpp clang/lib/Analysis/UnsafeBufferUsage.cpp clang/lib/CodeGen/ABIInfo.cpp clang/lib/CodeGen/ABIInfoImpl.cpp clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CGExprCXX.cpp clang/lib/CodeGen/CGExprConstant.cpp clang/lib/CodeGen/CGObjCMac.cpp clang/lib/CodeGen/CGOpenMPRuntime.cpp clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/CodeGen/CodeGenModule.cpp clang/lib/CodeGen/CodeGenTypes.cpp clang/lib/CodeGen/SwiftCallingConv.cpp clang/lib/CodeGen/Targets/ARM.cpp clang/lib/CodeGen/Targets/LoongArch.cpp clang/lib/CodeGen/Targets/RISCV.cpp clang/lib/CodeGen/Targets/X86.cpp clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaExprCXX.cpp clang/lib/Sema/SemaInit.cpp clang/lib/Sema/SemaOpenMP.cpp clang/lib/Sema/SemaSYCL.cpp clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp clang/lib/StaticAnalyzer/Core/MemRegion.cpp clang/lib/StaticAnalyzer/Core/RegionStore.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index f8739fd54f..f7d7b7f577 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -3181,8 +3181,7 @@ public:
/// Represents the canonical version of C arrays with a specified constant size.
/// For example, the canonical type for 'int A[4 + 4*100]' is a
/// ConstantArrayType where the element type is 'int' and the size is 404.
-class ConstantArrayType final
- : public ArrayType {
+class ConstantArrayType final : public ArrayType {
friend class ASTContext; // ASTContext creates these.
struct ExternalSize {
@@ -3242,21 +3241,19 @@ public:
/// Return true if the size is zero.
bool isZeroSize() const {
return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.isZero()
- : 0 == I.Size;
+ : 0 == I.Size;
}
/// Return the size zero-extended as a uint64_t.
uint64_t getZExtSize() const {
- return ConstantArrayTypeBits.HasExternalSize
- ? SizePtr->Size.getZExtValue()
- : I.Size;
+ return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.getZExtValue()
+ : I.Size;
}
/// Return the size zero-extended as a uint64_t.
int64_t getSExtSize() const {
- return ConstantArrayTypeBits.HasExternalSize
- ? SizePtr->Size.getSExtValue()
- : static_cast<int64_t>(I.Size);
+ return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.getSExtValue()
+ : static_cast<int64_t>(I.Size);
}
/// Return the size zero-extended to uint64_t or UINT64_MAX if the value is
@@ -3269,9 +3266,7 @@ public:
/// Return a pointer to the size expression.
const Expr *getSizeExpr() const {
- return ConstantArrayTypeBits.HasExternalSize
- ? SizePtr->SizeExpr
- : nullptr;
+ return ConstantArrayTypeBits.HasExternalSize ? SizePtr->SizeExpr : nullptr;
}
bool isSugared() const { return false; }
@@ -3295,9 +3290,8 @@ public:
}
static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx,
- QualType ET, uint64_t ArraySize,
- const Expr *SizeExpr, ArraySizeModifier SizeMod,
- unsigned TypeQuals);
+ QualType ET, uint64_t ArraySize, const Expr *SizeExpr,
+ ArraySizeModifier SizeMod, unsigned TypeQuals);
static bool classof(const Type *T) {
return T->getTypeClass() == ConstantArray;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 7889dc00e5..c5bdff0df0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -10996,8 +10996,7 @@ namespace {
return Error(E);
}
- Result = APValue(APValue::UninitArray(), 0,
- CAT->getZExtSize());
+ Result = APValue(APValue::UninitArray(), 0, CAT->getZExtSize());
if (!Result.hasArrayFiller())
return true;
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index 39ef4ba197..12c44f8fa0 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -4022,9 +4022,8 @@ void MicrosoftMangleContextImpl::mangleStringLiteral(const StringLiteral *SL,
// char bar[42] = "foobar";
// Where it is truncated or zero-padded to fit the array. This is the length
// used for mangling, and any trailing null-bytes also need to be mangled.
- unsigned StringLength = getASTContext()
- .getAsConstantArrayType(SL->getType())
- ->getZExtSize();
+ unsigned StringLength =
+ getASTContext().getAsConstantArrayType(SL->getType())->getZExtSize();
unsigned StringByteLength = StringLength * SL->getCharByteWidth();
// <char-type>: The "kind" of string literal is encoded into the mangled name.
diff --git a/clang/lib/AST/ScanfFormatString.cpp b/clang/lib/AST/ScanfFormatString.cpp
index 68a59829f3..7ee21c8c61 100644
--- a/clang/lib/AST/ScanfFormatString.cpp
+++ b/clang/lib/AST/ScanfFormatString.cpp
@@ -448,9 +448,7 @@ bool ScanfSpecifier::fixType(QualType QT, QualType RawQT,
if (const ConstantArrayType *CAT = Ctx.getAsConstantArrayType(RawQT)) {
if (CAT->getSizeModifier() == ArraySizeModifier::Normal)
FieldWidth = OptionalAmount(OptionalAmount::Constant,
- CAT->getZExtSize() - 1,
- "", 0, false);
-
+ CAT->getZExtSize() - 1, "", 0, false);
}
return true;
}
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index d0b56f3a75..9295b36e1d 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -229,9 +229,8 @@ unsigned ConstantArrayType::getMaxSizeBits(const ASTContext &Context) {
void ConstantArrayType::Profile(llvm::FoldingSetNodeID &ID,
const ASTContext &Context, QualType ET,
- uint64_t ArraySize,
- const Expr *SizeExpr, ArraySizeModifier SizeMod,
- unsigned TypeQuals) {
+ uint64_t ArraySize, const Expr *SizeExpr,
+ ArraySizeModifier SizeMod, unsigned TypeQuals) {
ID.AddPointer(ET.getAsOpaquePtr());
ID.AddInteger(ArraySize);
ID.AddInteger(llvm::to_underlying(SizeMod));
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 228df9aa9f..475d96b0e8 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -933,8 +933,8 @@ struct NoExpansion : TypeExpansion {
static std::unique_ptr<TypeExpansion>
getTypeExpansion(QualType Ty, const ASTContext &Context) {
if (const ConstantArrayType *AT = Context.getAsConstantArrayType(Ty)) {
- return std::make_unique<ConstantArrayExpansion>(
- AT->getElementType(), AT->getZExtSize());
+ return std::make_unique<ConstantArrayExpansion>(AT->getElementType(),
+ AT->getZExtSize());
}
if (const RecordType *RT = Ty->getAs<RecordType>()) {
SmallVector<const CXXBaseSpecifier *, 1> Bases;
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 831714881b..00e395c2a2 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7546,8 +7546,8 @@ private:
// it.
if (DimSizes.size() < Components.size() - 1) {
if (CAT)
- DimSizes.push_back(llvm::ConstantInt::get(
- CGF.Int64Ty, CAT->getZExtSize()));
+ DimSizes.push_back(
+ llvm::ConstantInt::get(CGF.Int64Ty, CAT->getZExtSize()));
else if (VAT)
DimSizes.push_back(CGF.Builder.CreateIntCast(
CGF.EmitScalarExpr(VAT->getSizeExpr()), CGF.Int64Ty,
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index a1979469bf..32a235b3fd 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2187,8 +2187,8 @@ llvm::Value *CodeGenFunction::emitArrayLength(const ArrayType *origArrayType,
dyn_cast<llvm::ArrayType>(addr.getElementType());
while (llvmArrayType) {
assert(isa<ConstantArrayType>(arrayType));
- assert(cast<ConstantArrayType>(arrayType)->getZExtSize()
- == llvmArrayType->getNumElements());
+ assert(cast<ConstantArrayType>(arrayType)->getZExtSize() ==
+ llvmArrayType->getNumElements());
gepIndices.push_back(zero);
countFromCLAs *= llvmArrayType->getNumElements();
@@ -2206,8 +2206,7 @@ llvm::Value *CodeGenFunction::emitArrayLength(const ArrayType *origArrayType,
// as some other type (probably a packed struct). Compute the array
// size, and just emit the 'begin' expression as a bitcast.
while (arrayType) {
- countFromCLAs *=
- cast<ConstantArrayType>(arrayType)->getZExtSize();
+ countFromCLAs *= cast<ConstantArrayType>(arrayType)->getZExtSize();
eltType = arrayType->getElementType();
arrayType = getContext().getAsArrayType(eltType);
}
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index b637c53f8b..a5af65ff77 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6833,8 +6833,7 @@ Sema::CheckStaticArrayArgument(SourceLocation CallLoc,
ArgCAT->getElementType())) {
if (ArgCAT->getSize().ult(CAT->getSize())) {
Diag(CallLoc, diag::warn_static_array_too_small)
- << ArgExpr->getSourceRange()
- << (unsigned)ArgCAT->getZExtSize()
+ << ArgExpr->getSourceRange() << (unsigned)ArgCAT->getZExtSize()
<< (unsigned)CAT->getZExtSize() << 0;
DiagnoseCalleeStaticArrayParam(*this, Param);
}
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 6ba8e2b109..2b4805d62d 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -249,11 +249,10 @@ static void CheckStringInit(Expr *Str, QualType &DeclT, const ArrayType *AT,
if (StrLength > CAT->getZExtSize())
S.Diag(Str->getBeginLoc(),
diag::err_initializer_string_for_char_array_too_long)
- << CAT->getZExtSize() << StrLength
- << Str->getSourceRange();
+ << CAT->getZExtSize() << StrLength << Str->getSourceRange();
} else {
// C99 6.7.8p14.
- if (StrLength-1 > CAT->getZExtSize())
+ if (StrLength - 1 > CAT->getZExtSize())
S.Diag(Str->getBeginLoc(),
diag::ext_initializer_string_for_char_array_too_long)
<< Str->getSourceRange();
``````````
</details>
https://github.com/llvm/llvm-project/pull/85716
More information about the cfe-commits
mailing list