Add warning on mis-sized literal, bug1156.
This commit is contained in:
parent
62b3deb90d
commit
bdeee35669
1
Changes
1
Changes
|
|
@ -5,6 +5,7 @@ The contributors that suggested a given feature are shown in []. Thanks!
|
|||
|
||||
* Verilator 3.903 devel
|
||||
|
||||
**** Add warning on mis-sized literal, bug1156. [Todd Strader]
|
||||
|
||||
|
||||
* Verilator 3.902 2017-04-02
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ V3Number::V3Number(VerilogStringLiteral, FileLine* fileline, const string& str)
|
|||
}
|
||||
}
|
||||
}
|
||||
opCleanThis();
|
||||
opCleanThis(true);
|
||||
}
|
||||
|
||||
V3Number::V3Number (FileLine* fileline, const char* sourcep) {
|
||||
|
|
@ -254,7 +254,7 @@ V3Number::V3Number (FileLine* fileline, const char* sourcep) {
|
|||
setBit(obit, bitIs(obit-1));
|
||||
obit++;
|
||||
}
|
||||
opCleanThis();
|
||||
opCleanThis(true);
|
||||
|
||||
//printf("Dump \"%s\" CP \"%s\" B '%c' %d W %d\n", sourcep, value_startp, base, width(), m_value[0]);
|
||||
}
|
||||
|
|
@ -1587,10 +1587,16 @@ V3Number& V3Number::opClean (const V3Number& lhs, uint32_t bits) {
|
|||
return opSel(lhs, bits-1, 0);
|
||||
}
|
||||
|
||||
void V3Number::opCleanThis() {
|
||||
// Clean in place number
|
||||
m_value[words()-1] &= hiWordMask();
|
||||
m_valueX[words()-1] &= hiWordMask();
|
||||
void V3Number::opCleanThis(bool warnOnTruncation) {
|
||||
// Clean MSB of number
|
||||
uint32_t newValueMsb = m_value[words()-1] & hiWordMask();
|
||||
uint32_t newValueXMsb = m_valueX[words()-1] & hiWordMask();
|
||||
if (warnOnTruncation && (newValueMsb != m_value[words()-1] || newValueXMsb != m_valueX[words()-1])) {
|
||||
// Displaying in decimal avoids hiWordMask truncation
|
||||
m_fileline->v3warn(WIDTH,"Value too large for "<<width()<<" bit number: "<<displayed(m_fileline, "%d"));
|
||||
}
|
||||
m_value[words()-1] = newValueMsb;
|
||||
m_valueX[words()-1] = newValueXMsb;
|
||||
}
|
||||
|
||||
V3Number& V3Number::opSel (const V3Number& lhs, const V3Number& msb, const V3Number& lsb) {
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class V3Number {
|
|||
// METHODS
|
||||
V3Number& setSingleBits(char value);
|
||||
V3Number& setString(const string& str) { m_isString=true; m_stringVal=str; return *this; }
|
||||
void opCleanThis();
|
||||
void opCleanThis(bool warnOnTruncation = false);
|
||||
public:
|
||||
FileLine* fileline() const { return m_fileline; }
|
||||
void fileline(FileLine* fl) { m_fileline=fl; }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/perl
|
||||
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
|
||||
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
||||
#
|
||||
# Copyright 2017 by Todd Strader. This program is free software; you can
|
||||
# redistribute it and/or modify it under the terms of either the GNU
|
||||
# Lesser General Public License Version 3 or the Perl Artistic License
|
||||
# Version 2.0.
|
||||
|
||||
$Self->skip("Verilator only test") if !$Self->{vlt};
|
||||
|
||||
compile (
|
||||
fails=>1,
|
||||
expect=>
|
||||
'%Warning-WIDTH: t/t_lint_literal_bad.v:9: Value too large for 8 bit number: 256
|
||||
',
|
||||
);
|
||||
|
||||
ok(1);
|
||||
1;
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
// DESCRIPTION: Verilator: Verilog Test module
|
||||
//
|
||||
// This file ONLY is placed into the Public Domain, for any use,
|
||||
// without warranty, 2017 by Todd Strader.
|
||||
|
||||
module t (
|
||||
);
|
||||
|
||||
localparam the_localparam = 8'd256;
|
||||
|
||||
endmodule
|
||||
Loading…
Reference in New Issue