Fix sformat string incorrectly cleared (#3515) (#3519).

This commit is contained in:
Gustav Svensk 2022-07-25 17:36:34 +02:00 committed by GitHub
parent ac4ec87942
commit eeef5ab4de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View File

@ -33,6 +33,7 @@ Gianfranco Costamagna
Glen Gibb
Graham Rushton
Guokai Chen
Gustav Svensk
Harald Heckmann
Howard Su
Huang Rui

View File

@ -1459,11 +1459,12 @@ void VL_SFORMAT_X(int obits, void* destp, const char* formatp, ...) VL_MT_SAFE {
void VL_SFORMAT_X(int obits_ignored, std::string& output, const char* formatp, ...) VL_MT_SAFE {
if (obits_ignored) {}
output = "";
std::string temp_output;
va_list ap;
va_start(ap, formatp);
_vl_vsformat(output, formatp, ap);
_vl_vsformat(temp_output, formatp, ap);
va_end(ap);
output = temp_output;
}
std::string VL_SFORMATF_NX(const char* formatp, ...) VL_MT_SAFE {

View File

@ -83,6 +83,12 @@ module t;
$swriteo(str2, 4'd12);
if (str2 != "14") $stop;
str3 = "foo";
$sformat(str3, "%s", str3); // $sformat twice so verilator does not
$sformat(str3, "%s", str3); // optimize the call to $sformat(str3, "%s", "foo")
`ifdef TEST_VERBOSE $display("str3=%0s", str3); `endif
if (str3 != "foo") $stop;
$write("*-* All Finished *-*\n");
$finish;
end