Support detailed failure info for constraint violations (#6617) (#6883)

* logging for the unsatisfied constraints

* Apply 'make format'

* fix teh quote error in the array indexing

* Apply 'make format'

* Len change for the hash for randomity when named assertion is used

* seperate name assertion and satisfied case

* Apply 'make format'

* simply comments and display info

* refine code and fix protect case

* format

* update display in test and .out file

* add an enable flag and warning type, add a protect_id version test and update out files

* Apply 'make format'

* simplify some comments

* update out file, ready to be merged.

* update .py file to set the hash key solid

* rename and reformate the warning message to follow the verilator style

* add a nowarn test

* Apply 'make format'

* ordering

---------

Co-authored-by: Udaya Raj Subedi <[email protected]>
Co-authored-by: github action <[email protected]>
This commit is contained in:
Yilou Wang
2026-01-12 15:53:49 +01:00
committed by GitHub
co-authored by Udaya Raj Subedi github action
parent 703c82cb3d
commit 31f8be0b85
17 changed files with 401 additions and 12 deletions
+18
View File
@@ -1353,6 +1353,24 @@ class ConstraintExprVisitor final : public VNVisitor {
VAccess::READWRITE},
VCMethod::RANDOMIZER_HARD, nodep->exprp()->unlinkFrBack()};
callp->dtypeSetVoid();
// Pass filename, lineno, and source as separate arguments
// This allows EmitC to call protect() on filename, similar to VL_STOP
// Add filename parameter
callp->addPinsp(
new AstCExpr{nodep->fileline(), "\"" + nodep->fileline()->filename() + "\""});
// Add line number parameter
callp->addPinsp(new AstCExpr{nodep->fileline(), cvtToStr(nodep->fileline()->lineno())});
// Add source text parameter (empty if --protect-ids to avoid source leakage)
std::string prettyText;
if (!v3Global.opt.protectIds()) {
prettyText = nodep->fileline()->prettySource();
size_t pos = 0;
while ((pos = prettyText.find('"', pos)) != std::string::npos) {
prettyText.insert(pos, "\\");
pos += std::strlen("\\\"");
}
}
callp->addPinsp(new AstCExpr{nodep->fileline(), "\"" + prettyText + "\""});
nodep->replaceWith(callp->makeStmt());
VL_DO_DANGLING(nodep->deleteTree(), nodep);
}