diff mbox series

[Committed] Add two testcases for 1bit bit-field

Message ID CA+=Sn1me+VS06uLrFePxNGLHtK1yOvB5UscPDE6cTgrS8YDu=g@mail.gmail.com
State New
Headers show
Series [Committed] Add two testcases for 1bit bit-field | expand

Commit Message

Andrew Pinski Jan. 2, 2020, 8:26 p.m. UTC
Hi,
  While working an optimization, the optimization would produce wrong
code but I noticed there was no testcase for that case at all.

Committed as obvious.

Thanks,
Andrew Pinski

ChangeLog:
* gcc.c-torture/execute/bitfld-8.c: New testcase.
* gcc.c-torture/execute/bitfld-9.c: New testcase.
diff mbox series

Patch

Index: gcc.c-torture/execute/bitfld-8.c
===================================================================
--- gcc.c-torture/execute/bitfld-8.c	(nonexistent)
+++ gcc.c-torture/execute/bitfld-8.c	(working copy)
@@ -0,0 +1,63 @@ 
+struct mouse_button_str {
+        unsigned char left      : 1;
+        unsigned char right     : 1;
+        unsigned char middle    : 1;
+        } button;
+
+static char fct (struct mouse_button_str newbutton) __attribute__ ((__noipa__));
+static char
+fct (struct mouse_button_str newbutton)
+{
+  char l = newbutton.left;
+  char r = newbutton.right;
+  char m = newbutton.middle;
+	return l || r || m;
+}
+
+int main(void)
+{
+  struct mouse_button_str newbutton1;
+  newbutton1.left = 1;
+  newbutton1.middle = 1;
+  newbutton1.right = 1;
+  if (!fct (newbutton1))
+    __builtin_abort ();
+
+  newbutton1.left = 0;
+  newbutton1.middle = 1;
+  newbutton1.right = 1;
+  if (!fct (newbutton1))
+    __builtin_abort ();
+  newbutton1.left = 1;
+  newbutton1.middle = 0;
+  newbutton1.right = 1;
+  if (!fct (newbutton1))
+    __builtin_abort ();
+  newbutton1.left = 1;
+  newbutton1.middle = 1;
+  newbutton1.right = 0;
+  if (!fct (newbutton1))
+    __builtin_abort ();
+
+
+  newbutton1.left = 1;
+  newbutton1.middle = 0;
+  newbutton1.right = 0;
+  if (!fct (newbutton1))
+    __builtin_abort ();
+  newbutton1.left = 0;
+  newbutton1.middle = 1;
+  newbutton1.right = 0;
+  if (!fct (newbutton1))
+    __builtin_abort ();
+  newbutton1.left = 0;
+  newbutton1.middle = 0;
+  newbutton1.right = 1;
+  if (!fct (newbutton1))
+    __builtin_abort ();
+  newbutton1.left = 0;
+  newbutton1.middle = 0;
+  newbutton1.right = 0;
+  if (fct (newbutton1))
+    __builtin_abort ();
+}
\ No newline at end of file
Index: gcc.c-torture/execute/bitfld-9.c
===================================================================
--- gcc.c-torture/execute/bitfld-9.c	(nonexistent)
+++ gcc.c-torture/execute/bitfld-9.c	(working copy)
@@ -0,0 +1,63 @@ 
+struct mouse_button_str {
+        unsigned char left      : 1;
+        unsigned char right     : 1;
+        unsigned char middle    : 1;
+        } button;
+
+static char fct (struct mouse_button_str newbutton) __attribute__ ((__noipa__));
+static char
+fct (struct mouse_button_str newbutton)
+{
+  char l = newbutton.left;
+  char r = newbutton.right;
+  char m = newbutton.middle;
+  return l && r && m;
+}
+
+int main(void)
+{
+  struct mouse_button_str newbutton1;
+  newbutton1.left = 1;
+  newbutton1.middle = 1;
+  newbutton1.right = 1;
+  if (!fct (newbutton1))
+    __builtin_abort ();
+
+  newbutton1.left = 0;
+  newbutton1.middle = 1;
+  newbutton1.right = 1;
+  if (fct (newbutton1))
+    __builtin_abort ();
+  newbutton1.left = 1;
+  newbutton1.middle = 0;
+  newbutton1.right = 1;
+  if (fct (newbutton1))
+    __builtin_abort ();
+  newbutton1.left = 1;
+  newbutton1.middle = 1;
+  newbutton1.right = 0;
+  if (fct (newbutton1))
+    __builtin_abort ();
+
+
+  newbutton1.left = 1;
+  newbutton1.middle = 0;
+  newbutton1.right = 0;
+  if (fct (newbutton1))
+    __builtin_abort ();
+  newbutton1.left = 0;
+  newbutton1.middle = 1;
+  newbutton1.right = 0;
+  if (fct (newbutton1))
+    __builtin_abort ();
+  newbutton1.left = 0;
+  newbutton1.middle = 0;
+  newbutton1.right = 1;
+  if (fct (newbutton1))
+    __builtin_abort ();
+  newbutton1.left = 0;
+  newbutton1.middle = 0;
+  newbutton1.right = 0;
+  if (fct (newbutton1))
+    __builtin_abort ();
+}