]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
bpf: add constant pointer to helper-skb-ancestor-cgroup-id.c test
authorJose E. Marchesi <jose.marchesi@oracle.com>
Sat, 27 Jan 2024 19:08:12 +0000 (20:08 +0100)
committerJose E. Marchesi <jose.marchesi@oracle.com>
Sat, 27 Jan 2024 19:08:12 +0000 (20:08 +0100)
The purpose of this test is to make sure that constant propagation is
achieved with the proper optimization level, so a BPF call instruction
to a kernel helper is generated.  This patch updates the patch so it
also covers kernel helpers defined with constant static pointers.

The motivation for this patch is:

  https://lore.kernel.org/bpf/20240127185031.29854-1-jose.marchesi@oracle.com/T/#u

Tested in bpf-unknown-none target x86_64-linux-gnu host.

gcc/testsuite/ChangeLog

* gcc.target/bpf/helper-skb-ancestor-cgroup-id.c: Add constant
version of kernel helper static pointer.

gcc/testsuite/gcc.target/bpf/helper-skb-ancestor-cgroup-id.c

index 693f390b9bba7f0e1b08eb82c0f68c8b9e260c3c..075dbe6f852d4c0443aa56aa693cd5e1914391f1 100644 (file)
@@ -5,6 +5,7 @@
 
 struct __sk_buff;
 static uint64_t (*bpf_skb_ancestor_cgroup_id)(struct __sk_buff *skb, int ancestor_level) = (void *) 83;
+static uint64_t (* const const_bpf_skb_ancestor_cgroup_id)(struct __sk_buff *skb, int ancestor_level) = (void *) 84;
 
 void
 foo ()
@@ -13,7 +14,9 @@ foo ()
   void *skb;
   int ancestor_level;
 
-  ret = bpf_skb_ancestor_cgroup_id (skb, ancestor_level);
+  ret = bpf_skb_ancestor_cgroup_id (skb, ancestor_level)
+    + const_bpf_skb_ancestor_cgroup_id (skb, ancestor_level);
 }
 
 /* { dg-final { scan-assembler "call\t83" } } */
+/* { dg-final { scan-assembler "call\t84" } } */