From bde8fd413bd79491702c8ff7103f5069745574e9 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Thu, 28 Dec 2023 11:36:49 +0100 Subject: pkg/compiler: extend parent reference support in len Earlier only len[parent, T] was supported and meant the size of the whole structure. Logically, len[parent:b, T] should be equivalent to just len[b, T]. Let len[parent:parent:a, T] refer to the structure that encloses the current one. Support len fields inside unions. --- pkg/compiler/testdata/all.txt | 8 +++++++- pkg/compiler/testdata/errors2.txt | 31 ++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 12 deletions(-) (limited to 'pkg/compiler/testdata') diff --git a/pkg/compiler/testdata/all.txt b/pkg/compiler/testdata/all.txt index edf4bd896..f7639c761 100644 --- a/pkg/compiler/testdata/all.txt +++ b/pkg/compiler/testdata/all.txt @@ -95,6 +95,7 @@ len_expr2 { f23 ptr[in, len_expr4] f24 ptr[in, ptr[in, len_expr4]] f25 len[f21:f31, int32] + f26 len_union } len_expr3 { @@ -112,6 +113,11 @@ len_expr4 { f41 int32 } +len_union [ + u1 len[parent:parent:f21:f31, int32] + u2 int32 +] + foo_len_expr(a ptr[in, len_expr1], b ptr[in, array[int8, 3]]) # Pointer type. @@ -342,4 +348,4 @@ union_compressed [ compressed$1(a compressed_image) (no_generate, no_minimize) compressed$2(a ptr[in, compressed_image]) (no_generate, no_minimize) compressed$3(a ptr[in, struct_compressed]) (no_generate, no_minimize) -compressed$4(a ptr[in, union_compressed]) (no_generate, no_minimize) \ No newline at end of file +compressed$4(a ptr[in, union_compressed]) (no_generate, no_minimize) diff --git a/pkg/compiler/testdata/errors2.txt b/pkg/compiler/testdata/errors2.txt index 13e69ef8a..d08f3e01e 100644 --- a/pkg/compiler/testdata/errors2.txt +++ b/pkg/compiler/testdata/errors2.txt @@ -86,14 +86,14 @@ foo$sr0(a ptr[in, use_sr]) foo$100(a int32, b len[a]) foo$101(a len[a]) ### len target a refers to itself foo$102(a ptr[in, len[a, int8]]) ### len target a refers to itself -foo$103(a int32, b len[c]) ### len target c does not exist -foo$104(a len[parent]) ### len target parent does not exist +foo$103(a int32, b len[c]) ### len target c does not exist in +foo$104(a len[parent]) ### parent reached the call (foo$104) foo$105(a ptr[in, int32], b ptr[in, array[len[a, int32]]]) foo$106(a int32, b ptr[in, csum[a, inet, int32]]) -foo$107(a int32, b ptr[in, csum[c, inet, int32]]) ### csum target c does not exist +foo$107(a int32, b ptr[in, csum[c, inet, int32]]) ### csum target c does not exist in s1 { - f1 len[s2, int32] ### len target s2 does not exist + f1 len[s2, int32] ### len target s2 does not exist in s1 } s2 { @@ -123,12 +123,12 @@ s8 { } [align[7]] ### bad struct s8 alignment 7 (must be a sane power of 2) u0 [ - f len[f1, int32] ### len target f1 does not exist + f len[f1, int32] ### len target f1 does not exist in u0 ] u1 [ f1 ptr[in, array[int8]] - f2 len[f1, int32] ### len target f1 does not exist + f2 len[f1, int32] ### len target f1 does not exist in u1 ] u2 [ @@ -144,17 +144,17 @@ foo$201(a ptr[in, s1]) foo$202(a ptr[in, s7]) foo$203(a u1) -foo$204(a ptr[in, slen1]) +foo$204(a ptr[in, slen1], b ptr[in, no_slen22]) slen1 { f0 len[parent, int32] - f1 len[parent:f0, int32] ### parent can't be part of path expressions - f2 len[slen21:a, int32] ### len target a does not exist - f3 len[f0:parent, int32] ### parent can't be part of path expressions + f1 len[parent:f0, int32] + f2 len[slen21:a, int32] ### len target a does not exist in slen2 + f3 len[f0:parent, int32] ### parent may only stay at the beginning (max 2 times) f4 len[slen2:f, int32] ### len path slen2 does not refer to a struct f5 len[slen22:f, int32] ### len path slen22 does not refer to a struct f6 len[syscall, int32] ### no argument name after syscall reference - f7 len[syscall:b, int32] ### len target b does not exist + f7 len[syscall:c, int32] ### len target c does not exist in f8 offsetof[parent, int32] ### offsetof must refer to fields f9 offsetof[slen1, int32] ### offsetof must refer to fields f10 len[f0:syscall:b, int32] ### syscall can't be in the middle of path expressions @@ -168,13 +168,22 @@ slen1 { slen2 { f int32 f1 slen3 + f2 len[parent:parent:slen22, int32] ### len target slen22 does not exist in no_slen22 } slen3 [ a int32 b int32 + c len[parent:parent:parent:x, int32] ### parent may only stay at the beginning (max 2 times) + d len[parent:a, int32] ### len target a does not exist in slen3 ] +no_slen22 { + # This one violates the parent:parent:slen22 chain. + f slen2 +} + + # Resource ctor tests. resource r100[int32] ### resource r100 can't be created (never mentioned as a syscall return value or output argument/field) -- cgit mrf-deployment