diff options
author | Nikita Popov <npopov@redhat.com> | 2023-08-24 16:30:01 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2023-10-09 14:22:12 +0200 |
commit | 8840da2db237cd714d975c199d5992945d2b71e9 (patch) | |
tree | 47017629a9abfab760d505c71c516fec66ff5950 /llvm/lib/IR/Verifier.cpp | |
parent | 111c7c1d072ccfe0799787436f4fb72cbd2bc61c (diff) | |
download | llvm-8840da2db237cd714d975c199d5992945d2b71e9.zip llvm-8840da2db237cd714d975c199d5992945d2b71e9.tar.gz llvm-8840da2db237cd714d975c199d5992945d2b71e9.tar.bz2 |
Reapply [Verifier] Sanity check alloca size against DILocalVariable fragment size
Reapply now that generation of incorrect debuginfo for FnDef
in rustc has been fixed.
-----
Add a check that the DILocalVariable fragment size in dbg.declare
does not exceed the size of the alloca.
This would have caught the invalid debuginfo regenerated by rustc
in https://github.com/llvm/llvm-project/issues/64149.
Differential Revision: https://reviews.llvm.org/D158743
Diffstat (limited to 'llvm/lib/IR/Verifier.cpp')
-rw-r--r-- | llvm/lib/IR/Verifier.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 5a33284..188e4a4 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -6318,6 +6318,20 @@ void Verifier::visitDbgIntrinsic(StringRef Kind, DbgVariableIntrinsic &DII) { CheckDI(isType(Var->getRawType()), "invalid type ref", Var, Var->getRawType()); verifyFnArgs(DII); + + if (auto *Declare = dyn_cast<DbgDeclareInst>(&DII)) { + if (auto *Alloca = dyn_cast_or_null<AllocaInst>(Declare->getAddress())) { + DIExpression *Expr = Declare->getExpression(); + std::optional<uint64_t> FragSize = Declare->getFragmentSizeInBits(); + std::optional<TypeSize> AllocSize = Alloca->getAllocationSizeInBits(DL); + if (FragSize && AllocSize && !AllocSize->isScalable() && + !Expr->isComplex()) { + CheckDI(*FragSize <= AllocSize->getFixedValue(), + "llvm.dbg.declare has larger fragment size than alloca size ", + &DII); + } + } + } } void Verifier::visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI) { |