[PATCH 7/9] enum: warn when mixing different restricted types

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sparse support enum initializers with restricted/bitwise type
type but this make sense only if they are all the same type.

Add a check and issue a warning if we're using initializers
with different restricted types.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 parse.c                       |  5 +++++
 validation/enum-bitwise-bad.c | 20 ++++++++++++++++++++
 2 files changed, 25 insertions(+)
 create mode 100644 validation/enum-bitwise-bad.c

diff --git a/parse.c b/parse.c
index 38e5d3056..0b5524e5e 100644
--- a/parse.c
+++ b/parse.c
@@ -907,6 +907,11 @@ static struct token *parse_enum_declaration(struct token *token, struct symbol *
 				if (!mix_bitwise++) {
 					warning(expr->pos, "mixed bitwiseness");
 				}
+			} else if (is_restricted_type(base_type) && base_type != ctype) {
+				sparse_error(expr->pos, "incompatible restricted type");
+				info(expr->pos, "   expected: %s", show_typename(base_type));
+				info(expr->pos, "        got: %s", show_typename(ctype));
+				base_type = &bad_ctype;
 			} else
 				base_type = &bad_ctype;
 			parent->ctype.base_type = base_type;
diff --git a/validation/enum-bitwise-bad.c b/validation/enum-bitwise-bad.c
new file mode 100644
index 000000000..6d31ca38c
--- /dev/null
+++ b/validation/enum-bitwise-bad.c
@@ -0,0 +1,20 @@
+#define __bitwise __attribute__((bitwise))
+#define __force   __attribute__((force))
+
+typedef int __bitwise apple_t;
+typedef int __bitwise orange_t;
+
+enum fruit {
+	A = (__force  apple_t) 0,
+	B = (__force orange_t) 1,
+};
+
+/*
+ * check-name: enum-bitwise-bad
+ *
+ * check-error-start
+enum-bitwise-bad.c:9:14: error: incompatible restricted type
+enum-bitwise-bad.c:9:14:    expected: restricted apple_t
+enum-bitwise-bad.c:9:14:         got: restricted orange_t
+ * check-error-end
+ */
-- 
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux