aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Verifier.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-08-24 16:30:01 +0200
committerNikita Popov <npopov@redhat.com>2023-10-09 14:22:12 +0200
commit8840da2db237cd714d975c199d5992945d2b71e9 (patch)
tree47017629a9abfab760d505c71c516fec66ff5950 /llvm/lib/IR/Verifier.cpp
parent111c7c1d072ccfe0799787436f4fb72cbd2bc61c (diff)
downloadllvm-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.cpp14
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) {