1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 20:23:11 +01:00

Move getVariableSize from Verifier.cpp into DIVariable::getSize() (NFC)

llvm-svn: 319125
This commit is contained in:
Adrian Prantl 2017-11-28 00:57:51 +00:00
parent e2828b0392
commit c1f644643c
3 changed files with 28 additions and 26 deletions

View File

@ -2091,6 +2091,8 @@ public:
DITypeRef getType() const { return DITypeRef(getRawType()); } DITypeRef getType() const { return DITypeRef(getRawType()); }
uint32_t getAlignInBits() const { return AlignInBits; } uint32_t getAlignInBits() const { return AlignInBits; }
uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; } uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
/// Determines the size of the variable's type.
Optional<uint64_t> getSizeInBits() const;
StringRef getFilename() const { StringRef getFilename() const {
if (auto *F = getFile()) if (auto *F = getFile())

View File

@ -614,6 +614,29 @@ DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops); 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, DIExpression *DIExpression::getImpl(LLVMContext &Context,
ArrayRef<uint64_t> Elements, ArrayRef<uint64_t> Elements,
StorageType Storage, bool ShouldCreate) { StorageType Storage, bool ShouldCreate) {

View File

@ -4498,29 +4498,6 @@ void Verifier::visitDbgIntrinsic(StringRef Kind, DbgInfoIntrinsic &DII) {
verifyFnArgs(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<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) { void Verifier::verifyFragmentExpression(const DbgInfoIntrinsic &I) {
DILocalVariable *V = dyn_cast_or_null<DILocalVariable>(I.getRawVariable()); DILocalVariable *V = dyn_cast_or_null<DILocalVariable>(I.getRawVariable());
DIExpression *E = dyn_cast_or_null<DIExpression>(I.getRawExpression()); DIExpression *E = dyn_cast_or_null<DIExpression>(I.getRawExpression());
@ -4552,15 +4529,15 @@ void Verifier::verifyFragmentExpression(const DIVariable &V,
ValueOrMetadata *Desc) { ValueOrMetadata *Desc) {
// If there's no size, the type is broken, but that should be checked // If there's no size, the type is broken, but that should be checked
// elsewhere. // elsewhere.
uint64_t VarSize = getVariableSize(V); auto VarSize = V.getSizeInBits();
if (!VarSize) if (!VarSize)
return; return;
unsigned FragSize = Fragment.SizeInBits; unsigned FragSize = Fragment.SizeInBits;
unsigned FragOffset = Fragment.OffsetInBits; unsigned FragOffset = Fragment.OffsetInBits;
AssertDI(FragSize + FragOffset <= VarSize, AssertDI(FragSize + FragOffset <= *VarSize,
"fragment is larger than or outside of variable", Desc, &V); "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) { void Verifier::verifyFnArgs(const DbgInfoIntrinsic &I) {