diff --git a/ivtest/gold/constfunccall3-iverilog-stderr.gold b/ivtest/gold/constfunccall3-iverilog-stderr.gold new file mode 100644 index 000000000..88bd8191f --- /dev/null +++ b/ivtest/gold/constfunccall3-iverilog-stderr.gold @@ -0,0 +1,3 @@ +ivltests/constfunccall3.v:21: error: A function invoked by a constant function must be a constant function local to the current module or provided by a package. +ivltests/constfunccall3.v:26: error: `f2' is not a constant function. +2 error(s) during elaboration. diff --git a/ivtest/ivltests/constfunccall1.v b/ivtest/ivltests/constfunccall1.v new file mode 100644 index 000000000..ba9e250cf --- /dev/null +++ b/ivtest/ivltests/constfunccall1.v @@ -0,0 +1,32 @@ +// Check that a constant function call is permitted when the call is inside +// a named block (issue #1141) + +module test; + +function integer f1(input integer i); + +begin + f1 = i + 1; +end + +endfunction + +function integer f2(input integer i); + +begin : b2 + f2 = f1(i); +end + +endfunction + +localparam p = f2(1); + +initial begin + $display(p); + if (p === 2) + $display("PASSED"); + else + $display("FAILED"); +end + +endmodule diff --git a/ivtest/ivltests/constfunccall2.v b/ivtest/ivltests/constfunccall2.v new file mode 100644 index 000000000..b41f9a321 --- /dev/null +++ b/ivtest/ivltests/constfunccall2.v @@ -0,0 +1,36 @@ +// Check that a constant function call is permitted when the function is +// provided by a package. + +package p1; + +function integer f1(input integer i); + +begin + f1 = i + 1; +end + +endfunction + +endpackage + +module test; + +function integer f2(input integer i); + +begin + f2 = p1::f1(i); +end + +endfunction + +localparam p = f2(1); + +initial begin + $display(p); + if (p === 2) + $display("PASSED"); + else + $display("FAILED"); +end + +endmodule diff --git a/ivtest/ivltests/constfunccall3.v b/ivtest/ivltests/constfunccall3.v new file mode 100644 index 000000000..70699893f --- /dev/null +++ b/ivtest/ivltests/constfunccall3.v @@ -0,0 +1,36 @@ +// Check that a constant function call is permitted when the function is +// provided by a package. + +module m1; + +function integer f1(input integer i); + +begin + f1 = i + 1; +end + +endfunction + +endmodule + +module test; + +function integer f2(input integer i); + +begin + f2 = m1.f1(i); +end + +endfunction + +localparam p = f2(1); + +initial begin + $display(p); + if (p === 2) + $display("PASSED"); + else + $display("FAILED"); +end + +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index 37df52a39..36ffd6773 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -68,6 +68,9 @@ constfunc17 vvp_tests/constfunc17.json constfunc18 vvp_tests/constfunc18.json constfunc19 vvp_tests/constfunc19.json constfunc20 vvp_tests/constfunc20.json +constfunccall1 vvp_tests/constfunccall1.json +constfunccall2 vvp_tests/constfunccall2.json +constfunccall3 vvp_tests/constfunccall3.json decl_before_use1 vvp_tests/decl_before_use1.json decl_before_use2 vvp_tests/decl_before_use2.json decl_before_use3 vvp_tests/decl_before_use3.json diff --git a/ivtest/vvp_tests/constfunccall1.json b/ivtest/vvp_tests/constfunccall1.json new file mode 100644 index 000000000..03f85fc87 --- /dev/null +++ b/ivtest/vvp_tests/constfunccall1.json @@ -0,0 +1,4 @@ +{ + "type" : "normal", + "source" : "constfunccall1.v" +} diff --git a/ivtest/vvp_tests/constfunccall2.json b/ivtest/vvp_tests/constfunccall2.json new file mode 100644 index 000000000..e508cc504 --- /dev/null +++ b/ivtest/vvp_tests/constfunccall2.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "constfunccall2.v", + "iverilog-args" : [ "-g2009" ] +} diff --git a/ivtest/vvp_tests/constfunccall3.json b/ivtest/vvp_tests/constfunccall3.json new file mode 100644 index 000000000..7b6806182 --- /dev/null +++ b/ivtest/vvp_tests/constfunccall3.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "constfunccall3.v", + "gold" : "constfunccall3" +}