diff options
author | Sander de Smalen <sander.desmalen@arm.com> | 2023-11-22 08:52:53 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-22 08:52:53 +0000 |
commit | 81b7f115fb272ef6fd6967f4121b64814b4bcf10 (patch) | |
tree | f62cd768f7932064b190300e2ddb5a497e03a9c9 /llvm/lib/CodeGen/StackProtector.cpp | |
parent | 03f05a4e72891237264ab48adf62034aaac8bd46 (diff) | |
download | llvm-81b7f115fb272ef6fd6967f4121b64814b4bcf10.zip llvm-81b7f115fb272ef6fd6967f4121b64814b4bcf10.tar.gz llvm-81b7f115fb272ef6fd6967f4121b64814b4bcf10.tar.bz2 |
[llvm][TypeSize] Fix addition/subtraction in TypeSize. (#72979)
It seems TypeSize is currently broken in the sense that:
TypeSize::Fixed(4) + TypeSize::Scalable(4) => TypeSize::Fixed(8)
without failing its assert that explicitly tests for this case:
assert(LHS.Scalable == RHS.Scalable && ...);
The reason this fails is that `Scalable` is a static method of class
TypeSize,
and LHS and RHS are both objects of class TypeSize. So this is
evaluating
if the pointer to the function Scalable == the pointer to the function
Scalable,
which is always true because LHS and RHS have the same class.
This patch fixes the issue by renaming `TypeSize::Scalable` ->
`TypeSize::getScalable`, as well as `TypeSize::Fixed` to
`TypeSize::getFixed`,
so that it no longer clashes with the variable in
FixedOrScalableQuantity.
The new methods now also better match the coding standard, which
specifies that:
* Variable names should be nouns (as they represent state)
* Function names should be verb phrases (as they represent actions)
Diffstat (limited to 'llvm/lib/CodeGen/StackProtector.cpp')
-rw-r--r-- | llvm/lib/CodeGen/StackProtector.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/StackProtector.cpp b/llvm/lib/CodeGen/StackProtector.cpp index 9a4d7ff..48dc7cb 100644 --- a/llvm/lib/CodeGen/StackProtector.cpp +++ b/llvm/lib/CodeGen/StackProtector.cpp @@ -215,14 +215,14 @@ static bool HasAddressTaken(const Instruction *AI, TypeSize AllocSize, APInt Offset(IndexSize, 0); if (!GEP->accumulateConstantOffset(DL, Offset)) return true; - TypeSize OffsetSize = TypeSize::Fixed(Offset.getLimitedValue()); + TypeSize OffsetSize = TypeSize::getFixed(Offset.getLimitedValue()); if (!TypeSize::isKnownGT(AllocSize, OffsetSize)) return true; // Adjust AllocSize to be the space remaining after this offset. // We can't subtract a fixed size from a scalable one, so in that case // assume the scalable value is of minimum size. TypeSize NewAllocSize = - TypeSize::Fixed(AllocSize.getKnownMinValue()) - OffsetSize; + TypeSize::getFixed(AllocSize.getKnownMinValue()) - OffsetSize; if (HasAddressTaken(I, NewAllocSize, M, VisitedPHIs)) return true; break; |