Since we can now remove return values of functions with return_nonnull
type attribute, I'll feel a bit safer if we can test this does not ICE
when someone attempts to access a non-existent call LHS. Eventually
we should probably drop the attribute when this happens.
gcc/testsuite/ChangeLog:
2021-11-15 Martin Jambor <mjambor@suse.cz>
* gcc.dg/ipa/ipa-sra-ret-nonull.c: New test.
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-sra-details" } */
+
+volatile void *gp;
+volatile void *gq;
+char buf[16];
+
+__attribute__((returns_nonnull, noinline))
+static char *
+foo (char *p, char *q)
+{
+ gq = q;
+ gp = p;
+ return q;
+}
+
+__attribute__((returns_nonnull, noinline))
+static char *
+bar (char *p, char *q)
+{
+ return foo (p, q) + 8;
+}
+
+__attribute__((noipa))
+static char *
+get_charp (void)
+{
+ return &buf[0];
+}
+
+int
+main ()
+{
+ char *r;
+ asm volatile ("" : : : "memory");
+ r = bar (get_charp (), get_charp ());
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump-times "Will SKIP return." 2 "sra" } } */