[llvm] r319125 - Move getVariableSize from Verifier.cpp into DIVariable::getSize() (NFC)
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 27 16:57:51 PST 2017
Author: adrian
Date: Mon Nov 27 16:57:51 2017
New Revision: 319125
URL: http://llvm.org/viewvc/llvm-project?rev=319125&view=rev
Log:
Move getVariableSize from Verifier.cpp into DIVariable::getSize() (NFC)
Modified:
llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
llvm/trunk/lib/IR/DebugInfoMetadata.cpp
llvm/trunk/lib/IR/Verifier.cpp
Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=319125&r1=319124&r2=319125&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Mon Nov 27 16:57:51 2017
@@ -2091,6 +2091,8 @@ public:
DITypeRef getType() const { return DITypeRef(getRawType()); }
uint32_t getAlignInBits() const { return AlignInBits; }
uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
+ /// Determines the size of the variable's type.
+ Optional<uint64_t> getSizeInBits() const;
StringRef getFilename() const {
if (auto *F = getFile())
Modified: llvm/trunk/lib/IR/DebugInfoMetadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfoMetadata.cpp?rev=319125&r1=319124&r2=319125&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfoMetadata.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfoMetadata.cpp Mon Nov 27 16:57:51 2017
@@ -614,6 +614,29 @@ DILocalVariable *DILocalVariable::getImp
DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops);
}
+Optional<uint64_t> DIVariable::getSizeInBits() const {
+ // This is used by the Verifier so be mindful of broken types.
+ const Metadata *RawType = getRawType();
+ while (RawType) {
+ // Try to get the size directly.
+ if (auto *T = dyn_cast<DIType>(RawType))
+ if (uint64_t Size = T->getSizeInBits())
+ return Size;
+
+ if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
+ // Look at the base type.
+ RawType = DT->getRawBaseType();
+ continue;
+ }
+
+ // Missing type or size.
+ break;
+ }
+
+ // Fail gracefully.
+ return None;
+}
+
DIExpression *DIExpression::getImpl(LLVMContext &Context,
ArrayRef<uint64_t> Elements,
StorageType Storage, bool ShouldCreate) {
Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=319125&r1=319124&r2=319125&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Mon Nov 27 16:57:51 2017
@@ -4498,29 +4498,6 @@ void Verifier::visitDbgIntrinsic(StringR
verifyFnArgs(DII);
}
-static uint64_t getVariableSize(const DIVariable &V) {
- // Be careful of broken types (checked elsewhere).
- const Metadata *RawType = V.getRawType();
- while (RawType) {
- // Try to get the size directly.
- if (auto *T = dyn_cast<DIType>(RawType))
- if (uint64_t Size = T->getSizeInBits())
- return Size;
-
- if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
- // Look at the base type.
- RawType = DT->getRawBaseType();
- continue;
- }
-
- // Missing type or size.
- break;
- }
-
- // Fail gracefully.
- return 0;
-}
-
void Verifier::verifyFragmentExpression(const DbgInfoIntrinsic &I) {
DILocalVariable *V = dyn_cast_or_null<DILocalVariable>(I.getRawVariable());
DIExpression *E = dyn_cast_or_null<DIExpression>(I.getRawExpression());
@@ -4552,15 +4529,15 @@ void Verifier::verifyFragmentExpression(
ValueOrMetadata *Desc) {
// If there's no size, the type is broken, but that should be checked
// elsewhere.
- uint64_t VarSize = getVariableSize(V);
+ auto VarSize = V.getSizeInBits();
if (!VarSize)
return;
unsigned FragSize = Fragment.SizeInBits;
unsigned FragOffset = Fragment.OffsetInBits;
- AssertDI(FragSize + FragOffset <= VarSize,
+ AssertDI(FragSize + FragOffset <= *VarSize,
"fragment is larger than or outside of variable", Desc, &V);
- AssertDI(FragSize != VarSize, "fragment covers entire variable", Desc, &V);
+ AssertDI(FragSize != *VarSize, "fragment covers entire variable", Desc, &V);
}
void Verifier::verifyFnArgs(const DbgInfoIntrinsic &I) {
More information about the llvm-commits
mailing list