]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization: [PR102622]: wrong code due to signed one bit integer and "a?-1:0"
authorAndrew Pinski <apinski@marvell.com>
Sun, 10 Oct 2021 01:28:59 +0000 (01:28 +0000)
committerAndrew Pinski <apinski@marvell.com>
Mon, 11 Oct 2021 21:16:19 +0000 (21:16 +0000)
Since the problem was already fixed on this branch, we just want to add the
testcase so it does not regress there.

PR tree-optimization/102622

gcc/testsuite/ChangeLog:

* gcc.c-torture/execute/bitfld-10.c: New test.

(cherry picked from commit 882d806c1a8f9d2d2ade1133de88d63e5d4fe40c)

gcc/testsuite/gcc.c-torture/execute/bitfld-10.c [new file with mode: 0644]

diff --git a/gcc/testsuite/gcc.c-torture/execute/bitfld-10.c b/gcc/testsuite/gcc.c-torture/execute/bitfld-10.c
new file mode 100644 (file)
index 0000000..bdbf573
--- /dev/null
@@ -0,0 +1,24 @@
+/* PR tree-optimization/102622 */
+/* Wrong code introduced due to phi-opt
+   introducing undefined signed interger overflow
+   with one bit signed integer negation. */
+
+struct f{signed t:1;};
+int g(struct f *a, int t) __attribute__((noipa));
+int g(struct f *a, int t)
+{
+    if (t)
+      a->t = -1;
+    else
+      a->t = 0;
+    int t1 = a->t;
+    if (t1) return 1;
+    return t1;
+}
+
+int main(void)
+{
+    struct f a;
+    if (!g(&a, 1))  __builtin_abort();
+    return 0;
+}