summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/ipa/ipa-structreorg-48-function-ptr-0.c
diff options
context:
space:
mode:
authorErick Ochoa <erick.ochoa@theobroma-systems.com>2020-11-25 14:20:43 +0100
committerErick Ochoa <erick.ochoa@theobroma-systems.com>2020-11-25 14:26:11 +0100
commitcf54c81ecd07c5ad0cdd81e6b2473faff2141b2e (patch)
treee5533471bb27e7182f836fa0df5a5c67a9ff111f /gcc/testsuite/gcc.dg/ipa/ipa-structreorg-48-function-ptr-0.c
parentcacc6dfafad4d5ec8e440be9440abe19f2da5c10 (diff)
Add tests
Diffstat (limited to 'gcc/testsuite/gcc.dg/ipa/ipa-structreorg-48-function-ptr-0.c')
-rw-r--r--gcc/testsuite/gcc.dg/ipa/ipa-structreorg-48-function-ptr-0.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-structreorg-48-function-ptr-0.c b/gcc/testsuite/gcc.dg/ipa/ipa-structreorg-48-function-ptr-0.c
new file mode 100644
index 00000000000..405ccab3c34
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/ipa-structreorg-48-function-ptr-0.c
@@ -0,0 +1,44 @@
+/* { dg-do run } */
+/* { dg-options "-flto -fipa-type-escape-analysis -fdump-ipa-type-escape-analysis " } */
+
+#include <assert.h>
+#include <stddef.h>
+#include <stdio.h>
+
+struct astruct_s
+{
+ _Bool a;
+ _Bool b;
+ _Bool c;
+};
+
+_Bool
+returnLast (struct astruct_s astruct)
+{
+ return astruct.c;
+}
+
+_Bool
+returnLast2 (struct astruct_s astruct)
+{
+ _Bool *ptr = &(astruct.a);
+ ptr = ptr + 1;
+ return *ptr;
+}
+
+int
+main (int argc, char **argv)
+{
+ _Bool (*func1) (struct astruct_s);
+ func1 = &returnLast;
+ _Bool (*func2) (struct astruct_s);
+ func2 = &returnLast2;
+ struct astruct_s astruct;
+ astruct.c = argc;
+ printf ("%d %d", astruct.a, astruct.c);
+ // These test means that things remain equal
+ // A.k.a without an optimization.
+ // Why? Because a function pointer can be a
+ // pointer to anything
+ assert (func1 (astruct) != func2 (astruct));
+}