diff mbox series

[1/3] add test for enum sign extension

Message ID 20190925220340.5128-2-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series fix sign extension in casting enums | expand

Commit Message

Luc Van Oostenryck Sept. 25, 2019, 10:03 p.m. UTC
In a declaration like:
	enum {
	        a = 0x80000000,
	        b = -1,
	}
the underlying type should be long and b's value should be
0xffffffffffffffff (on a 64-bit machine) but is 0xffffffff.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/enum-sign-extend.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
 create mode 100644 validation/enum-sign-extend.c
diff mbox series

Patch

diff --git a/validation/enum-sign-extend.c b/validation/enum-sign-extend.c
new file mode 100644
index 000000000..7f17debac
--- /dev/null
+++ b/validation/enum-sign-extend.c
@@ -0,0 +1,12 @@ 
+enum num {
+	a = 0x80000000,
+	b = -1,
+};
+
+_Static_assert([typeof(b)] == [long], "type");
+_Static_assert(b == -1L,              "value");
+
+/*
+ * check-name: enum-sign-extend
+ * check-known-to-fail
+ */