Fix $fopen etc on integer arrays (#3214).

This commit is contained in:
Wilson Snyder 2021-11-23 18:22:16 -05:00
parent c14bbb9421
commit e7ebe0e280
4 changed files with 9 additions and 7 deletions

View File

@ -26,6 +26,7 @@ Verilator 4.215 devel
* Fix display of signed without format (#3204). [Julie Schwartz]
* Fix display of empty string constant (#3207). [Julie Schwartz]
* Fix incorrect width after and-or optimization (#3208). [Julie Schwartz]
* Fix $fopen etc on integer arrays (#3214). [adrienlemasle]
* Fix %0 format on $value$plusargs.

View File

@ -679,7 +679,7 @@ string EmitCFunc::emitVarResetRecurse(const AstVar* varp, const string& varNameP
return "";
} else if (basicp) {
bool zeroit
= (varp->attrFileDescr() // Zero so we don't core dump if never $fopen
= (varp->attrFileDescr() // Zero so we don't do file IO if never $fopen
|| (basicp && basicp->isZeroInit())
|| (v3Global.opt.underlineZero() && !varp->name().empty() && varp->name()[0] == '_')
|| (v3Global.opt.xInitial() == "fast" || v3Global.opt.xInitial() == "0"));

View File

@ -403,10 +403,8 @@ private:
}
static void expectDescriptor(AstNode* nodep, AstNodeVarRef* filep) {
if (!filep) {
nodep->v3warn(E_UNSUPPORTED,
"Unsupported: $fopen/$fclose/$f* descriptor must be a simple variable");
}
// This might fail on complex expressions like arrays
// We use attrFileDescr() only for lint suppression, so that's ok
if (filep && filep->varp()) filep->varp()->attrFileDescr(true);
}

View File

@ -14,6 +14,7 @@
module t;
integer file;
integer file_a[0];
integer chars;
reg [1*8:1] letterl;
@ -91,8 +92,10 @@ module t;
begin
// Check quadword access; a little strange, but it's legal to open "."
file = $fopen(".","r");
$fclose(file);
// Also checks using array reference
file_a[0] = $fopen(".","r");
if (file_a[0] == 0) $stop;
$fclose(file_a[0]);
end
begin