From 664ef9a3e1016e80fc1fcbbef6e9f66a2ededfe6 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 30 Jun 2018 19:34:41 +0200 Subject: pkg/compiler: check for unused declarations Error on unused structs/unions/resources/flags. Finds tons of bugs. --- pkg/compiler/testdata/all.txt | 13 +++++++++++++ pkg/compiler/testdata/consts.txt | 3 +++ pkg/compiler/testdata/errors2.txt | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) (limited to 'pkg/compiler/testdata') diff --git a/pkg/compiler/testdata/all.txt b/pkg/compiler/testdata/all.txt index 69ad6d181..a5a097de3 100644 --- a/pkg/compiler/testdata/all.txt +++ b/pkg/compiler/testdata/all.txt @@ -7,6 +7,7 @@ foo$2(a ptr[out, array[int32]]) foo$3(a union_arg) foo$4() r0 foo$5(a int8['a':'z']) +foo$6(a ptr[in, strings]) resource r0[intptr] @@ -38,6 +39,8 @@ strings { string_flags1 = "foo", "barbaz" string_flags2 = "" int_flags = 0, 1 +_ = 1, 2 +_ = C1, C2 # Proc type. @@ -45,6 +48,8 @@ proc_struct1 { f1 proc[C0, 8, int8] } +foo$proc1(a ptr[in, proc_struct1]) + # Len/bytesize types. type len_templ1[DATA1, DATA2] { @@ -122,6 +127,8 @@ bitfield0 { f2 int8:2 } +foo$bitfield0(a ptr[in, bitfield0]) + # Type templates. type type0 int8 @@ -184,6 +191,8 @@ foo$templ3(a ptr[in, templ_struct1[1]], b ptr[in, templ_struct1[2]]) foo$templ4(a ptr[in, templ_struct1[3]]) foo$templ5(a ptr[in, templ_struct1[3]]) foo$templ6(a ptr[in, templ_struct4]) +foo$templ7(a ptr[in, templ_struct5], b ptr[in, templ_struct6], c ptr[in, templ_union], d ptr[in, type3]) +foo$templ8(a ptr[in, templ_templ_use]) # Structs. @@ -195,8 +204,12 @@ s1 { f1 int8 } [size[C2]] +foo$s0(a ptr[in, s0], b ptr[in, s1]) + # Unions. u0 [ f1 int32 ] + +foo$u0(a ptr[in, u0]) diff --git a/pkg/compiler/testdata/consts.txt b/pkg/compiler/testdata/consts.txt index f7c8daa35..ef248a1e0 100644 --- a/pkg/compiler/testdata/consts.txt +++ b/pkg/compiler/testdata/consts.txt @@ -35,3 +35,6 @@ foo$1(a ptr[in, templ1[CONST20]]) str2 { f1 int8 } [size[CONST21]] + +_ = CONST22, CONST23 +_ = CONST24 diff --git a/pkg/compiler/testdata/errors2.txt b/pkg/compiler/testdata/errors2.txt index 69fa46e62..1b1adefa5 100644 --- a/pkg/compiler/testdata/errors2.txt +++ b/pkg/compiler/testdata/errors2.txt @@ -6,6 +6,7 @@ resource r0[r0] ### recursive resource r0->r0 resource r1[r2] ### recursive resource r1->r2->r1 resource r2[r1] ### recursive resource r2->r1->r2 +resource r3[int32] ### unused resource r3 foo$0(a0 ptr[out, r0], a1 ptr[out, r1], a2 ptr[out, r2]) @@ -54,6 +55,28 @@ sr9 { f templ_sr[ptr[in, sr9]] ### recursive declaration: sr9.f -> templ_sr[ptr[in, sr9]].f -> sr9 (mark some pointers as opt) } +use_sr { + u2 u2 + u3 u3 + s3 s3 + s4 s4 + s6 s6 + sr1 sr1 + sr2 sr2 + sr5 sr5 + sr7 sr7 + sr8 sr8 + sr9 sr9 + s400 s400 + s401 s401 + u400 u400 + u401 u401 + s402 s402 + s403 s403 +} [packed] + +foo$sr0(a ptr[in, use_sr]) + # Len target tests. foo$100(a int32, b len[a]) @@ -169,8 +192,17 @@ s403 { f3 int32 } +s404 { ### unused struct s404 + f1 int8 +} + +u404 [ ### unused union u404 + f1 int8 +] + sf400 = "foo", "bar", "baz" sf401 = "a", "b", "cd" +sf402 = "a", "b" ### unused string flags sf402 # Const argument checks. @@ -184,5 +216,8 @@ foo$506(a ptr[in, array[int32, 0]]) ### arrays of size 0 are not supported foo$507(a ptr[in, array[int32, 0:0]]) ### arrays of size 0 are not supported foo$508(a ptr[in, string["foo", 3]]) ### string value "foo\x00" exceeds buffer length 3 foo$509(a int8['b':'a']) ### bad int range [98:97] +foo$510(a type500) type type500 proc[C1, 8, int8] ### values starting from 1 with step 8 overflow base type for 32 procs +type type501 int8 ### unused type type501 +type type502[C] const[C, int8] ### unused type type502 -- cgit mrf-deployment