aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorJosh Triplett <josh@freedesktop.org>2006-10-16 21:46:15 -0700
committerJosh Triplett <josh@freedesktop.org>2006-10-16 21:46:15 -0700
commitc30df9be78778eacb19b30e7bf903236f6116ee0 (patch)
tree5c7984b7e51f09d2a48a64bb58df886b705b53e7
parent7fdd2a497b8962b15d54b54b412380fb024767ed (diff)
parent8aed19aea597dd467e0de3402ed7e6feae70394c (diff)
downloadsparse-dev-c30df9be78778eacb19b30e7bf903236f6116ee0.tar.gz
Merge branch 'fix-defined-twice-error-on-empty-struct' into staging
-rw-r--r--expand.c10
-rw-r--r--validation/initializer-entry-defined-twice.c43
2 files changed, 47 insertions, 6 deletions
diff --git a/expand.c b/expand.c
index 1007014b..a34d07d3 100644
--- a/expand.c
+++ b/expand.c
@@ -872,12 +872,10 @@ static void verify_nonoverlapping(struct expression_list **list)
struct expression *b;
FOR_EACH_PTR(*list, b) {
- if (a) {
- if (bit_offset(a) == bit_offset(b)) {
- sparse_error(a->pos, "Initializer entry defined twice");
- info(b->pos, " also defined here");
- return;
- }
+ if (a && a->ctype->bit_size && bit_offset(a) == bit_offset(b)) {
+ sparse_error(a->pos, "Initializer entry defined twice");
+ info(b->pos, " also defined here");
+ return;
}
a = b;
} END_FOR_EACH_PTR(b);
diff --git a/validation/initializer-entry-defined-twice.c b/validation/initializer-entry-defined-twice.c
new file mode 100644
index 00000000..80434f1c
--- /dev/null
+++ b/validation/initializer-entry-defined-twice.c
@@ -0,0 +1,43 @@
+/* Tests for the "Initializer entry defined twice" warning. */
+
+/* Initializing a struct field twice should trigger the warning. */
+struct normal {
+ int field1;
+ int field2;
+};
+
+struct normal struct_error = {
+ .field1 = 0,
+ .field1 = 0
+};
+
+/* Initializing two different fields of a union should trigger the warning. */
+struct has_union {
+ int x;
+ union {
+ int a;
+ int b;
+ } y;
+ int z;
+};
+
+struct has_union union_error = {
+ .y = {
+ .a = 0,
+ .b = 0
+ }
+};
+
+/* Empty structures can make two fields have the same offset in a struct.
+ * Initialzing both should not trigger the warning. */
+struct empty { };
+
+struct same_offset {
+ struct empty field1;
+ int field2;
+};
+
+struct same_offset not_an_error = {
+ .field1 = { },
+ .field2 = 0
+};