diff mbox

[1/2] enum: add testcase for UB in oversized shift

Message ID 20180507144556.75808-2-luc.vanoostenryck@gmail.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Luc Van Oostenryck May 7, 2018, 2:45 p.m. UTC
type_is_ok(), used to calculate the base type of enums,
has a bug related to UB when doing a full width rshift.

Add a testcase for this.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/bug-rshift-ub.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100644 validation/bug-rshift-ub.c
diff mbox

Patch

diff --git a/validation/bug-rshift-ub.c b/validation/bug-rshift-ub.c
new file mode 100644
index 000000000..3a5f3a577
--- /dev/null
+++ b/validation/bug-rshift-ub.c
@@ -0,0 +1,17 @@ 
+enum a {
+	A = ~0ULL,
+};
+
+static enum a a = A;
+
+/*
+ * check-name: bug-rshift-ub
+ * check-known-to-fail
+ * check-description:
+ *	This test trigger(ed) a bug on x86 caused by a
+ *	full width shift (which is UB), expecting to get
+ *	0 but giving the unshifted value and as result
+ *	the type is invalid:
+ *		warning: incorrect type in initializer (invalid types)
+ *			 expected bad type enum a static [toplevel] a
+ */