Fix empty foreach in if in constraints (#5408)

Signed-off-by: Krzysztof Bieganski <kbieganski@antmicro.com>
This commit is contained in:
Krzysztof Bieganski 2024-08-27 15:39:36 +02:00 committed by GitHub
parent e927536099
commit 155dcc5658
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -695,11 +695,13 @@ class ConstraintExprVisitor final : public VNVisitor {
AstNode* const cstmtp = new AstText{fl, "ret += \" \" + "}; AstNode* const cstmtp = new AstText{fl, "ret += \" \" + "};
cstmtp->addNext(itemp); cstmtp->addNext(itemp);
cstmtp->addNext(new AstText{fl, ";"}); cstmtp->addNext(new AstText{fl, ";"});
AstNode* const exprsp = new AstText{fl, "([&]{ std::string ret = \"(bvand\";"}; AstNode* const exprsp = new AstText{fl, "([&]{ std::string ret;"};
exprsp->addNext(new AstBegin{ exprsp->addNext(new AstBegin{
fl, "", fl, "",
new AstForeach{fl, nodep->arrayp()->unlinkFrBack(), new AstCStmt{fl, cstmtp}}, new AstForeach{fl, nodep->arrayp()->unlinkFrBack(), new AstCStmt{fl, cstmtp}},
false, true}); false, true});
exprsp->addNext(
new AstText{fl, "return ret.empty() ? \"#b1\" : \"(bvand \" + ret + \")\";"});
exprsp->addNext(new AstText{fl, "return ret + \")\"; })()"}); exprsp->addNext(new AstText{fl, "return ret + \")\"; })()"});
AstNodeExpr* const newp = new AstCExpr{fl, exprsp}; AstNodeExpr* const newp = new AstCExpr{fl, exprsp};
newp->dtypeSetString(); newp->dtypeSetString();

View File

@ -32,8 +32,16 @@ endclass
class D; class D;
rand bit posit; rand bit posit;
rand int x; rand int x;
int o[$]; // empty
int p[$] = {1};
int q[$] = {0, 0, 0, 0, 0}; int q[$] = {0, 0, 0, 0, 0};
constraint fore { constraint fore {
if (posit == 1) {
foreach(o[i]) o[i] > 0;
}
if (posit == 1) {
foreach(p[i]) p[i] > 0;
}
if (posit == 1) { if (posit == 1) {
x < 7; x < 7;
foreach(q[i]) foreach(q[i])