From ba5077701da600f426ca93ec4814b3267328b4b4 Mon Sep 17 00:00:00 2001 From: Jack May Date: Mon, 25 Feb 2019 17:05:59 -0800 Subject: [PATCH] Avoid possible simplified lowering of passed struct (#2938) --- programs/bpf/c/src/struct_ret/struct_ret.c | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/programs/bpf/c/src/struct_ret/struct_ret.c b/programs/bpf/c/src/struct_ret/struct_ret.c index f60206ba2e..7fd87c398d 100644 --- a/programs/bpf/c/src/struct_ret/struct_ret.c +++ b/programs/bpf/c/src/struct_ret/struct_ret.c @@ -1,18 +1,21 @@ #include -struct foo {const uint8_t *input;}; -struct foo bar(const uint8_t *input); +struct test_struct { uint64_t x; uint64_t y; uint64_t z;}; -extern bool entrypoint(const uint8_t *input) { - struct foo foo = bar(input); - sol_log_64(0, 0, 0, (uint64_t)input, (uint64_t)foo.input); - sol_assert(input == foo.input); - return true; +static struct test_struct __attribute__ ((noinline)) test_function(void) { + struct test_struct s; + s.x = 3; + s.y = 4; + s.z = 5; + return s; } -struct foo bar(const uint8_t *input) { - struct foo foo; - foo.input = input; - return foo; +extern bool entrypoint(const uint8_t* input) { + struct test_struct s = test_function(); + sol_log("foobar"); + if (s.x + s.y + s.z == 12 ) { + return true; + } + return false; }