diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -5348,8 +5348,7 @@ // If there's no size, the type is broken, but that should be checked // elsewhere. auto VarSize = V.getSizeInBits(); - if (!VarSize) - return; + AssertDI(VarSize, "variable with fragments must have a size", Desc, &V); unsigned FragSize = Fragment.SizeInBits; unsigned FragOffset = Fragment.OffsetInBits; diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp --- a/llvm/lib/Transforms/Scalar/SROA.cpp +++ b/llvm/lib/Transforms/Scalar/SROA.cpp @@ -4534,15 +4534,14 @@ // The alloca may be larger than the variable. auto VarSize = DbgDeclare->getVariable()->getSizeInBits(); - if (VarSize) { - if (Size > *VarSize) - Size = *VarSize; - if (Size == 0 || Start + Size > *VarSize) - continue; - } + assert(VarSize && "Variable with fragments must have a size"); + if (Size > *VarSize) + Size = *VarSize; + if (Size == 0 || Start + Size > *VarSize) + continue; // Avoid creating a fragment expression that covers the entire variable. - if (!VarSize || *VarSize != Size) { + if (*VarSize != Size) { if (auto E = DIExpression::createFragmentExpression(Expr, Start, Size)) FragmentExpr = *E;