Now that we check `MDExpression` during `-verify` (r232299), make
the `DIExpression` wrapper more strict:
- remove redundant checks in `DebugInfoVerifier`,
- overload `get()` to `cast_or_null<MDExpression>` (superseding
`getRaw()`),
- stop checking for null in any accessor, and
- remove `DIExpression::Verify()` entirely in favour of
`MDExpression::isValid()`.
There is still some logic in this class, mostly to do with high-level
iterators; I'll defer cleaning up those until the rest of the wrappers
are similarly strict.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232412
91177308-0d34-0410-b5e6-
96231b3b80d8
/// this DBG_VALUE instruction.
DIExpression getDebugExpression() const {
assert(isDebugValue() && "not a DBG_VALUE");
- DIExpression Expr(getOperand(3).getMetadata());
- assert(Expr.Verify() && "not a DIExpression");
- return Expr;
+ return cast<MDExpression>(getOperand(3).getMetadata());
}
/// emitError - Emit an error referring to the source location of this
unsigned Reg, unsigned Offset,
const MDNode *Variable, const MDNode *Expr) {
assert(DIVariable(Variable).Verify() && "not a DIVariable");
- assert(DIExpression(Expr).Verify() && "not a DIExpression");
+ assert(DIExpression(Expr)->isValid() && "not a DIExpression");
if (IsIndirect)
return BuildMI(MF, DL, MCID)
.addReg(Reg, RegState::Debug)
unsigned Reg, unsigned Offset,
const MDNode *Variable, const MDNode *Expr) {
assert(DIVariable(Variable).Verify() && "not a DIVariable");
- assert(DIExpression(Expr).Verify() && "not a DIExpression");
+ assert(DIExpression(Expr)->isValid() && "not a DIExpression");
MachineFunction &MF = *BB.getParent();
MachineInstr *MI =
BuildMI(MF, DL, MCID, IsIndirect, Reg, Offset, Variable, Expr);
/// FIXME: Instead of DW_OP_plus taking an argument, this should use DW_OP_const
/// and have DW_OP_plus consume the topmost elements on the stack.
class DIExpression : public DIDescriptor {
- MDExpression *getRaw() const { return dyn_cast_or_null<MDExpression>(get()); }
-
public:
explicit DIExpression(const MDNode *N = nullptr) : DIDescriptor(N) {}
DIExpression(const MDExpression *N) : DIDescriptor(N) {}
- bool Verify() const;
+ MDExpression *get() const {
+ return cast_or_null<MDExpression>(DIDescriptor::get());
+ }
+ operator MDExpression *() const { return get(); }
+ MDExpression *operator->() const { return get(); }
+
+ // Don't call this. Call isValid() directly.
+ bool Verify() const = delete;
/// \brief Return the number of elements in the complex expression.
- unsigned getNumElements() const { RETURN_FROM_RAW(N->getNumElements(), 0); }
+ unsigned getNumElements() const { return get()->getNumElements(); }
/// \brief return the Idx'th complex address element.
- uint64_t getElement(unsigned I) const {
- return cast<MDExpression>(get())->getElement(I);
- }
+ uint64_t getElement(unsigned I) const { return get()->getElement(I); }
/// \brief Return whether this is a piece of an aggregate variable.
bool isBitPiece() const;
}
};
- iterator begin() const { return cast<MDExpression>(get())->elements_begin(); }
- iterator end() const { return cast<MDExpression>(get())->elements_end(); }
+ iterator begin() const { return get()->elements_begin(); }
+ iterator end() const { return get()->elements_end(); }
};
/// \brief This object holds location information.
Value(const MDNode *Var, const MDNode *Expr, MachineLocation Loc)
: Variable(Var), Expression(Expr), EntryKind(E_Location), Loc(Loc) {
assert(DIVariable(Var).Verify());
- assert(DIExpression(Expr).Verify());
+ assert(DIExpression(Expr)->isValid());
}
/// The variable to which this location entry corresponds.
: Var(V), Expr(1, E), TheDIE(nullptr), DotDebugLocOffset(~0U),
MInsn(nullptr), DD(DD) {
FrameIndex.push_back(FI);
- assert(Var.Verify() && E.Verify());
+ assert(Var.Verify());
+ assert(!E || E->isValid());
}
/// Construct a DbgVariable from a DEBUG_VALUE.
DIObjCProperty(DbgNode).Verify() ||
DITemplateTypeParameter(DbgNode).Verify() ||
DITemplateValueParameter(DbgNode).Verify() ||
- DIImportedEntity(DbgNode).Verify() || DIExpression(DbgNode).Verify());
+ DIImportedEntity(DbgNode).Verify());
}
static Metadata *getField(const MDNode *DbgNode, unsigned Elt) {
return isTypeRef(N->getType());
}
-bool DIExpression::Verify() const {
- // FIXME: This should return false if it's null!
- auto *N = getRaw();
- return !N || N->isValid();
-}
-
bool DILocation::Verify() const { return getRaw(); }
bool DINameSpace::Verify() const { return getRaw(); }
bool DIFile::Verify() const { return getRaw(); }
case Intrinsic::dbg_declare: {
auto *DDI = cast<DbgDeclareInst>(&CI);
Finder.processDeclare(*M, DDI);
- if (auto E = DDI->getExpression())
- Assert(DIExpression(E).Verify(), "DIExpression does not Verify!", E);
break;
}
case Intrinsic::dbg_value: {
auto *DVI = cast<DbgValueInst>(&CI);
Finder.processValue(*M, DVI);
- if (auto E = DVI->getExpression())
- Assert(DIExpression(E).Verify(), "DIExpression does not Verify!", E);
break;
}
default: