Fix assignment of null into struct member (#4952).

This commit is contained in:
Wilson Snyder
2024-03-08 17:33:51 -05:00
parent f78783e187
commit 5ee938fd1c
4 changed files with 64 additions and 3 deletions
+3 -2
View File
@@ -82,7 +82,8 @@ class CastVisitor final : public VNVisitor {
}
void ensureCast(AstNodeExpr* nodep) {
if (castSize(nodep->backp()) != castSize(nodep) || !nodep->user1()) {
insertCast(nodep, castSize(nodep->backp()));
const AstConst* const constp = VN_CAST(nodep, Const);
if (!(constp && constp->num().isNull())) insertCast(nodep, castSize(nodep->backp()));
}
}
void ensureLower32Cast(AstCCast* nodep) {
@@ -201,7 +202,7 @@ class CastVisitor final : public VNVisitor {
// Constants are of unknown size if smaller than 33 bits, because
// we're too lazy to wrap every constant in the universe in
// ((IData)#).
nodep->user1(nodep->isQuad() || nodep->isWide());
nodep->user1(nodep->isQuad() || nodep->isWide() || nodep->num().isNull());
}
// Null dereference protection