Skip to content

Commit 58562f7

Browse files
committed
Expressions: Move diagnostic tests to slang-lit; Add CHECK-DIAGS command to slang-lit
stack-info: PR: #1926, branch: AndrewNolte/stack/26
1 parent 8845fa0 commit 58562f7

15 files changed

Lines changed: 1291 additions & 1140 deletions

scripts/slang-lit.py

Lines changed: 389 additions & 2 deletions
Large diffs are not rendered by default.

tests/regression/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ add_test(
2424
set_tests_properties(regression_cst_json_roundtrip
2525
PROPERTIES DEPENDS regression_cst_json_gen)
2626

27+
add_subdirectory(ast)
2728
add_subdirectory(driver)
2829

2930
if(SLANG_INCLUDE_UVM_TEST)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ~~~
2+
# SPDX-FileCopyrightText: Michael Popoloski
3+
# SPDX-License-Identifier: MIT
4+
# ~~~
5+
6+
add_test(
7+
NAME ast_lit_tests
8+
COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/slang-lit.py
9+
${CMAKE_CURRENT_LIST_DIR} --slang $<TARGET_FILE:slang::driver>)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// SPDX-FileCopyrightText: Michael Popoloski
2+
// SPDX-License-Identifier: MIT
3+
4+
// RUN: %slang %s --diag-json %t --error-limit=0 2>&1 || true
5+
// CHECK-DIAGS: %t
6+
7+
// Array method with-clause plumbing
8+
module m_array_method_with_clause_plumbing;
9+
typedef struct { int i; } asdf_t;
10+
function asdf_t foo;
11+
endfunction
12+
13+
asdf_t a = '{default:0};
14+
15+
int j = foo().i();
16+
// ^^^^^^^^^ ExpressionNotCallable expression is not callable
17+
// ^ - for ExpressionNotCallable
18+
int k = foo().i with (bar);
19+
// ^^^^ UnexpectedWithClause unexpected 'with' clause
20+
int l = a.i with (bar);
21+
// ^^^^ UnexpectedWithClause unexpected 'with' clause
22+
int m = foo() with (bar);
23+
// ^^^^ WithClauseNotAllowed cannot use 'with' expression with 'foo'
24+
int n = $bits(a) with (bar);
25+
// ^^^^ WithClauseNotAllowed cannot use 'with' expression with '$bits'
26+
27+
int o[3] = '{default:0};
28+
int p = o.and(a);
29+
// ^^^ IteratorArgsWithoutWithClause cannot provide arguments to 'and' without corresponding 'with' clause
30+
int q = o.and();
31+
int r = o.and with (1) { 1; };
32+
// ^^^^^^ UnexpectedConstraintBlock unexpected constraint block
33+
int s = o.and with;
34+
// ^^^^ ExpectedIterationExpression expected a single array iteration expression
35+
int t = o.and with (a, b);
36+
// ^^^^^^ ExpectedIterationExpression expected a single array iteration expression
37+
int u = o.and(a, b, c) with (a == 1);
38+
// ^^^^^^^^^ TooManyArguments too many arguments for 'and'; expected 2 but 3 were provided
39+
int v = o.and(a[1]) with (a == 1);
40+
// ^^^^ ExpectedIteratorName expected name of iterator for use with 'with' expression
41+
int w = o.and(,) with (a == 1);
42+
// ^ EmptyArgNotAllowed empty argument not allowed
43+
int x = o.and(a, .foo()) with (a == 1);
44+
// ^^^^^^ NamedArgNotAllowed named argument not allowed
45+
int y = o.and(posedge clk) with (a == 1);
46+
// ^^^^^^^^^^^ InvalidArgumentExpr sequence and property expressions are not valid in this context
47+
48+
// These are ok.
49+
int z = o.and(b) with (b + 1);
50+
int aa = o.and with (item + x);
51+
endmodule
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// SPDX-FileCopyrightText: Michael Popoloski
2+
// SPDX-License-Identifier: MIT
3+
4+
// RUN: %slang %s --diag-json %t --error-limit=0 2>&1 || true
5+
// CHECK-DIAGS: %t
6+
7+
// Disallowed assignment contexts
8+
module m_disallowed_assignment_contexts;
9+
int i;
10+
int j;
11+
// ^ NoteDeclarationHere declared here - for ConstEvalNonConstVariable(j)
12+
int p;
13+
logic [(j = 2) : 0] asdf;
14+
// ^ ConstEvalNonConstVariable reference to non-constant variable 'j' is not allowed in a constant expression
15+
assign i = 1 + (j = 1);
16+
// ^^^^^ AssignmentNotAllowed assignment expressions are not allowed in this context
17+
18+
initial p = {j = 1};
19+
// ^^^^^ AssignmentRequiresParens assignment expressions must be parenthesized
20+
initial if (p = 1) begin end
21+
// ^^^^^ AssignmentRequiresParens assignment expressions must be parenthesized
22+
23+
assign i = i++;
24+
// ^^^ IncDecNotAllowed increment and decrement expressions are not allowed in this context
25+
assign i = ++i;
26+
// ^^^ IncDecNotAllowed increment and decrement expressions are not allowed in this context
27+
28+
// This is ok
29+
initial p = 1 + (j = 1);
30+
31+
function func(int k);
32+
endfunction
33+
34+
// Initialization in a procedural context is also ok
35+
initial begin
36+
automatic int k = 1;
37+
automatic int l = k++;
38+
static int m = 2;
39+
static int n = m++;
40+
41+
static int foo = k; // disallowed
42+
// ^ AutoFromStaticInit cannot refer to automatic variable 'k' from static initializer
43+
44+
func.k = 4; // ok, param is static
45+
end
46+
47+
final begin
48+
p <= 5;
49+
// ^^^^^^ NonblockingInFinal nonblocking assignments in final blocks have no effect
50+
end
51+
endmodule
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-FileCopyrightText: Michael Popoloski
2+
// SPDX-License-Identifier: MIT
3+
4+
// RUN: %slang %s --diag-json %t --error-limit=0 --allow-array-concat-assign-pattern 2>&1 || true
5+
// CHECK-DIAGS: %t
6+
7+
// Bare associative pattern in unpacked array concat -- with option
8+
module top_bare_associative_pattern_in_unpacked_array_concat_with_optio;
9+
class C;
10+
string s[][int];
11+
function f();
12+
s = {
13+
{0: "sv1", 1: "sv2"},
14+
// ^ BareAssociativePattern associative array literal is missing the required apostrophe prefix
15+
{1: "sv2", 2: "sv4"}
16+
// ^ BareAssociativePattern associative array literal is missing the required apostrophe prefix
17+
};
18+
endfunction
19+
endclass
20+
endmodule
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// SPDX-FileCopyrightText: Michael Popoloski
2+
// SPDX-License-Identifier: MIT
3+
4+
// RUN: %slang %s --diag-json %t --error-limit=0 2>&1 || true
5+
// CHECK-DIAGS: %t
6+
7+
module m;
8+
typedef struct {
9+
int scalar;
10+
// ^ NoteDeclarationHere declared here - for AssignmentPatternNoMember(scalar)
11+
int array[2];
12+
} st;
13+
14+
st value = '{real: 1.0};
15+
// ^^^^^^^^^^^^ AssignmentPatternMissingElements not all elements of array are covered by an assignment pattern key
16+
// ^^^^^^^^^^^^ AssignmentPatternNoMember member 'scalar' is not covered by any assignment pattern key
17+
18+
st too_many = '{
19+
// ^^ WrongNumberAssignmentPatterns assignment pattern for 'st' requires 2 elements but 3 were provided
20+
1,
21+
// ^^ - for WrongNumberAssignmentPatterns
22+
2,
23+
// ^^ - for WrongNumberAssignmentPatterns
24+
3
25+
// ^ - for WrongNumberAssignmentPatterns
26+
};
27+
// ^ - for WrongNumberAssignmentPatterns
28+
endmodule
29+
30+
module assignment_pattern_errors;
31+
event e1 = event'{1};
32+
// ^^^^^^^^^ BadAssignmentPatternType invalid target type 'event' for assignment pattern
33+
parameter p = '{1, 2};
34+
// ^^^^^^^ AssignmentPatternNoContext assignment pattern target type cannot be deduced in this context
35+
36+
typedef event e_t;
37+
e_t e2 = '{1};
38+
// ^^^^ BadAssignmentPatternType invalid target type 'e_t' (aka 'event') for assignment pattern
39+
40+
int a[int] = '{1, 2};
41+
// ^^^^^^^ AssignmentPatternAssociativeType assignment pattern for associative array must specify key:value pairs
42+
43+
typedef real rt;
44+
typedef struct { int a; rt b; } st;
45+
st b = '{1};
46+
// ^^^^ WrongNumberAssignmentPatterns assignment pattern for 'st' requires 2 elements but 1 were provided
47+
int c[1:2] = '{1};
48+
// ^^^^ WrongNumberAssignmentPatterns assignment pattern for 'int$[1:2]' requires 2 elements but 1 were provided
49+
st d = '{default:1, default:2, a:1, a:2, rt:3.14, blah:3, event:1, (1+1):2};
50+
// ^^^^^^^ AssignmentPatternKeyDupDefault assignment pattern has multiple default keys
51+
// ^ AssignmentPatternKeyDupName assignment pattern has multiple keys for member 'a'
52+
// ^ NotePreviousDefinition previous definition here - for AssignmentPatternKeyDupName(a)
53+
// ^^^^ UnknownMember no member named 'blah' in 'st'
54+
// ^^^^^ AssignmentPatternKeyExpr expression is not a valid assignment pattern member name or type
55+
// ^^^^^ AssignmentPatternKeyExpr expression is not a valid assignment pattern member name or type
56+
57+
int e[] = '{0:1, 0:2, default:1, int:3, -1:2};
58+
// ^ AssignmentPatternKeyDupValue assignment pattern has multiple keys for index 0
59+
// ^ NotePreviousDefinition previous definition here - for AssignmentPatternKeyDupValue(0)
60+
// ^^^ AssignmentPatternDynamicType assignment patterns for dynamic arrays, associative arrays, and queues cannot have type keys
61+
// ^^ ValueMustBePositive value must be positive
62+
int f[1:2] = '{default:1, default:2, event:1, 9:1};
63+
// ^^^^^^^ AssignmentPatternKeyDupDefault assignment pattern has multiple default keys
64+
// ^^^^^ AssignmentPatternKeyExpr expression is not a valid assignment pattern member name or type
65+
// ^ IndexValueInvalid cannot refer to element 9 of 'int$[1:2]'
66+
int g[] = '{1:1};
67+
// ^^^^^^ AssignmentPatternMissingElements not all elements of array are covered by an assignment pattern key
68+
69+
st h = '{-1{0}};
70+
// ^^ ValueMustBePositive value must be positive
71+
st i = '{3{1}};
72+
// ^^^^^^^ WrongNumberAssignmentPatterns assignment pattern for 'st' requires 2 elements but 3 were provided
73+
int j[1:2] = '{-1{0}};
74+
// ^^ ValueMustBePositive value must be positive
75+
int k[] = '{-1{0}};
76+
// ^^ ValueMustBePositive value must be positive
77+
78+
int l[int] = '{default:1, default:2, 3:1, 3:2, int:1};
79+
// ^^^^^^^ AssignmentPatternKeyDupDefault assignment pattern has multiple default keys
80+
// ^ AssignmentPatternKeyDupValue assignment pattern has multiple keys for index 3
81+
// ^ NotePreviousDefinition previous definition here - for AssignmentPatternKeyDupValue(3)
82+
// ^^^ AssignmentPatternDynamicType assignment patterns for dynamic arrays, associative arrays, and queues cannot have type keys
83+
84+
int m[2][2] = '{real:3.14};
85+
// ^^^^^^^^^^^^ AssignmentPatternMissingElements not all elements of array are covered by an assignment pattern key
86+
struct { int i; real r; } n[2] = '{real:3.14};
87+
// ^^^^^^^^^^^^ AssignmentPatternNoMember member 'i' is not covered by any assignment pattern key
88+
// ^ NoteDeclarationHere declared here - for AssignmentPatternNoMember(i)
89+
endmodule
90+
91+
module assignment_pattern_statement;
92+
typedef struct {
93+
int scalar;
94+
// ^ NoteDeclarationHere declared here - for AssignmentPatternNoMember(scalar)
95+
int array[2];
96+
} st;
97+
98+
st other;
99+
initial other = '{real: 1.0};
100+
// ^^^^^^^^^^^^ AssignmentPatternMissingElements not all elements of array are covered by an assignment pattern key
101+
// ^^^^^^^^^^^^ AssignmentPatternNoMember member 'scalar' is not covered by any assignment pattern key
102+
endmodule
103+
104+
module nested_assignment_pattern_statement;
105+
typedef struct {
106+
int present;
107+
int missing;
108+
// ^ NoteDeclarationHere declared here - for AssignmentPatternNoMember(missing)
109+
} inner_t;
110+
typedef struct {
111+
inner_t inner;
112+
} outer_t;
113+
114+
outer_t value;
115+
initial value = '{inner: '{present: 1}};
116+
// ^^^^^^^^^^^^^ AssignmentPatternNoMember member 'missing' is not covered by any assignment pattern key
117+
endmodule
118+
119+
module nested_and_outer_missing_assignment_pattern_statement;
120+
typedef struct {
121+
int present;
122+
int missing;
123+
// ^ NoteDeclarationHere declared here - for AssignmentPatternNoMember(missing)
124+
} inner_t;
125+
typedef struct {
126+
inner_t inner;
127+
int outer_missing;
128+
// ^ NoteDeclarationHere declared here - for AssignmentPatternNoMember(outer_missing)
129+
} outer_t;
130+
131+
outer_t value;
132+
initial value = '{inner: '{present: 1}};
133+
// ^^^^^^^^^^^^^^^^^^^^^^^ AssignmentPatternNoMember member 'outer_missing' is not covered by any assignment pattern key
134+
// ^^^^^^^^^^^^^ AssignmentPatternNoMember member 'missing' is not covered by any assignment pattern key
135+
endmodule
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// SPDX-FileCopyrightText: Michael Popoloski
2+
// SPDX-License-Identifier: MIT
3+
4+
// RUN: %slang %s --diag-json %t --error-limit=0 2>&1 || true
5+
// CHECK-DIAGS: %t
6+
7+
// Assignment pattern - invalid default
8+
module m_assignment_pattern_invalid_default;
9+
int i[] = '{default, 5};
10+
// ^^^^^^^ ExpectedExpression expected expression
11+
endmodule
12+
13+
// Invalid assigment pattern lvalues
14+
module m_invalid_assigment_pattern_lvalues;
15+
typedef struct { real r; string s; } U;
16+
function automatic void f1;
17+
real r;
18+
string s;
19+
U'{r:r, s:s} = '{3.14, "Hello World"};
20+
// ^^^^^^^^^^^^ ExpressionNotAssignable expression is not assignable
21+
endfunction
22+
23+
function automatic void f2;
24+
int i[];
25+
int j, k;
26+
'{j, k} = i;
27+
// ^^^^^^^ AssignmentPatternLValueDynamic lvalue assignment patterns cannot be assigned from dynamic arrays
28+
endfunction
29+
endmodule
30+
31+
// Bare associative array pattern -- diagnostic emitted with option
32+
package P_bare_associative_array_pattern_diagnostic_emitted_with_optio;
33+
typedef int int_queue[$];
34+
task automatic T();
35+
int_queue q[string] = {"k":{0,1,2}};
36+
// ^ BareAssociativePattern associative array literal is missing the required apostrophe prefix
37+
endtask
38+
endpackage
39+
40+
// Bare associative pattern in unpacked array concat -- without option
41+
module top_bare_associative_pattern_in_unpacked_array_concat_without_op;
42+
class C;
43+
string s[][int];
44+
function f();
45+
s = {
46+
{0: "sv1", 1: "sv2"},
47+
// ^ BareAssociativePattern associative array literal is missing the required apostrophe prefix
48+
// ^^^^^^^^^^^^^^^^^^^^ AssignmentPatternNoContext assignment pattern target type cannot be deduced in this context
49+
{1: "sv2", 2: "sv4"}
50+
// ^ BareAssociativePattern associative array literal is missing the required apostrophe prefix
51+
// ^^^^^^^^^^^^^^^^^^^^^ AssignmentPatternNoContext assignment pattern target type cannot be deduced in this context
52+
};
53+
endfunction
54+
endclass
55+
endmodule
56+
57+
// Assignment pattern unused default is still error checked
58+
typedef logic [7:0] RT[2];
59+
60+
function RT f1;
61+
return '{0:8, 1:9, default:'{default:foo}};
62+
// ^^^ UndeclaredIdentifier use of undeclared identifier 'foo'
63+
endfunction
64+
65+
function RT f2;
66+
return '{0:8, 1:9, default:'{-1{foo}}};
67+
// ^^ ValueMustBePositive value must be positive
68+
// ^^^ UndeclaredIdentifier use of undeclared identifier 'foo'
69+
endfunction
70+
71+
$static_assert($sformatf("%p", f1()) == "'{8'd8, 8'd9}");
72+
$static_assert($sformatf("%p", f2()) == "'{8'd8, 8'd9}");

0 commit comments

Comments
 (0)