Merge pull request #656 from larsclausen/enum-compatibility

Restrict enum compatibility to the same scope
This commit is contained in:
Stephen Williams 2022-03-20 19:13:56 -07:00 committed by GitHub
commit fc80465b87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 116 additions and 12 deletions

View File

@ -186,8 +186,7 @@ static void elaborate_scope_enumeration(Design*des, NetScope*scope,
netenum_t*use_enum = new netenum_t(enum_type->base_type,
enum_type->signed_flag,
enum_type->integer_flag, range,
enum_type->names->size(),
enum_type);
enum_type->names->size());
use_enum->set_line(*enum_type);
scope->add_enumeration_set(enum_type, use_enum);

View File

@ -0,0 +1,25 @@
// Check that enum types declared in a higher level scope are compatible between
// different instances of a module.
typedef enum integer {
A
} T;
module M;
T e;
endmodule
module test;
M m1();
M m2();
initial begin
m1.e = A;
m2.e = m1.e;
if (m2.e === A) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,30 @@
// Check that enum types explicitly imported from a package are compatible
// between different instances of a module.
package P;
typedef enum integer {
A
} T;
endpackage
module M;
import P::T;
T e;
endmodule
module test;
import P::A;
M m1();
M m2();
initial begin
m1.e = A;
m2.e = m1.e;
if (m2.e === A) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,30 @@
// Check that enum types implicitly imported from a package are compatible
// between different instances of a module.
package P;
typedef enum integer {
A
} T;
endpackage
module M;
import P::*;
T e;
endmodule
module test;
import P::*;
M m1();
M m2();
initial begin
m1.e = A;
m2.e = m1.e;
if (m2.e === A) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,21 @@
// Check that enums declared within a module are not compatible between
// different instances of a module
module M;
enum integer {
A
} e;
endmodule
module test;
M m1();
M m2();
initial begin
// These are different types and not compatible
m1.e = m2.e;
$display("FAILED");
end
endmodule

View File

@ -232,6 +232,10 @@ disable_fork_cmd normal,-g2009 ivltests
display_bug normal,-g2009 ivltests gold=display_bug.gold
edge normal,-g2009 ivltests
enum_base_range normal,-g2005-sv ivltests
enum_compatibility1 normal,-g2005-sv ivltests
enum_compatibility2 normal,-g2005-sv ivltests
enum_compatibility3 normal,-g2005-sv ivltests
enum_compatibility_fail CE,-g2005-sv ivltests
enum_elem_ranges normal,-g2005-sv ivltests
enum_dims_invalid CE,-g2005-sv ivltests
enum_in_struct normal,-g2005-sv ivltests

View File

@ -24,11 +24,9 @@
using namespace std;
netenum_t::netenum_t(ivl_variable_type_t btype, bool signed_flag,
bool integer_flag, const netrange_t &range, size_t name_count,
enum_type_t*enum_type)
: base_type_(btype), enum_type_(enum_type), signed_flag_(signed_flag),
integer_flag_(integer_flag), range_(range),
names_(name_count), bits_(name_count)
bool integer_flag, const netrange_t &range, size_t name_count)
: base_type_(btype), signed_flag_(signed_flag), integer_flag_(integer_flag),
range_(range), names_(name_count), bits_(name_count)
{
}
@ -159,5 +157,5 @@ perm_string netenum_t::bits_at(size_t idx) const
bool netenum_t::matches(const netenum_t*other) const
{
return enum_type_ == other->enum_type_;
return this == other;
}

View File

@ -29,14 +29,12 @@
class NetScope;
struct enum_type_t;
class netenum_t : public LineInfo, public ivl_type_s {
public:
explicit netenum_t(ivl_variable_type_t base_type, bool signed_flag,
bool isint_flag, const netrange_t &range,
size_t name_count, enum_type_t*enum_type);
size_t name_count);
~netenum_t();
virtual ivl_variable_type_t base_type() const;
@ -74,7 +72,6 @@ class netenum_t : public LineInfo, public ivl_type_s {
private:
ivl_variable_type_t base_type_;
enum_type_t*enum_type_;
bool signed_flag_;
bool integer_flag_;
netrange_t range_;