From 3e0e1d093435d753f66c51820f49528b91522743 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Tue, 28 Nov 2017 00:57:51 +0000 Subject: [PATCH] Move getVariableSize from Verifier.cpp into DIVariable::getSize() (NFC) llvm-svn: 319125 --- llvm/include/llvm/IR/DebugInfoMetadata.h | 2 ++ llvm/lib/IR/DebugInfoMetadata.cpp | 23 +++++++++++++++++++ llvm/lib/IR/Verifier.cpp | 29 +++--------------------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h index c515f6de2d8c..c35b3bede2a1 100644 --- a/llvm/include/llvm/IR/DebugInfoMetadata.h +++ b/llvm/include/llvm/IR/DebugInfoMetadata.h @@ -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 getSizeInBits() const; StringRef getFilename() const { if (auto *F = getFile()) diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp index ae02392ea14f..940c4d1f3666 100644 --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -614,6 +614,29 @@ DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope, DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops); } +Optional 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(RawType)) + if (uint64_t Size = T->getSizeInBits()) + return Size; + + if (auto *DT = dyn_cast(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 Elements, StorageType Storage, bool ShouldCreate) { diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 5bb1f84d2e5c..084eaba7064c 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -4498,29 +4498,6 @@ void Verifier::visitDbgIntrinsic(StringRef Kind, DbgInfoIntrinsic &DII) { 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(RawType)) - if (uint64_t Size = T->getSizeInBits()) - return Size; - - if (auto *DT = dyn_cast(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(I.getRawVariable()); DIExpression *E = dyn_cast_or_null(I.getRawExpression()); @@ -4552,15 +4529,15 @@ void Verifier::verifyFragmentExpression(const DIVariable &V, 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) {