aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
-rw-r--r--symbol.c30
-rw-r--r--validation/init-char-array1.c27
2 files changed, 53 insertions, 4 deletions
diff --git a/symbol.c b/symbol.c
index 80a2f238..2ec62000 100644
--- a/symbol.c
+++ b/symbol.c
@@ -296,9 +296,21 @@ static int count_array_initializer(struct symbol *t, struct expression *expr)
if (entry->idx_to >= nr)
nr = entry->idx_to+1;
break;
+ case EXPR_PREOP: {
+ struct expression *e = entry;
+ if (is_char) {
+ while (e && e->type == EXPR_PREOP && e->op == '(')
+ e = e->unop;
+ if (e && e->type == EXPR_STRING) {
+ entry = e;
case EXPR_STRING:
- if (is_char)
- str_len = entry->string->length;
+ if (is_char)
+ str_len = entry->string->length;
+ }
+
+
+ }
+ }
default:
nr++;
}
@@ -307,9 +319,19 @@ static int count_array_initializer(struct symbol *t, struct expression *expr)
nr = str_len;
break;
}
+ case EXPR_PREOP:
+ if (is_char) {
+ struct expression *e = expr;
+ while (e && e->type == EXPR_PREOP && e->op == '(')
+ e = e->unop;
+ if (e && e->type == EXPR_STRING) {
+ expr = e;
case EXPR_STRING:
- if (is_char)
- nr = expr->string->length;
+ if (is_char)
+ nr = expr->string->length;
+ }
+ }
+ break;
default:
break;
}
diff --git a/validation/init-char-array1.c b/validation/init-char-array1.c
new file mode 100644
index 00000000..24fd8d82
--- /dev/null
+++ b/validation/init-char-array1.c
@@ -0,0 +1,27 @@
+/*
+ * for array of char, ("...") as the initializer is an gcc language
+ * extension. check that a parenthesized string initializer is handled
+ * correctly and that -Wparen-string warns about it's use.
+ */
+static const char u[] = ("hello");
+static const char v[] = {"hello"};
+static const char v1[] = {("hello")};
+static const char w[] = "hello";
+static const char x[5] = "hello";
+
+static void f(void)
+{
+ char a[1/(sizeof(u) == 6)];
+ char b[1/(sizeof(v) == 6)];
+ char c[1/(sizeof(w) == 6)];
+ char d[1/(sizeof(x) == 5)];
+}
+/*
+ * check-name: parenthesized string initializer
+ * check-command: sparse -Wparen-string $file
+ *
+ * check-error-start
+init-char-array1.c:6:26: warning: array initialized from parenthesized string constant
+init-char-array1.c:8:28: warning: array initialized from parenthesized string constant
+ * check-error-end
+ */