aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--evaluate.c2
-rw-r--r--validation/c11-atomic.c2
-rw-r--r--validation/eval/premature-examination.c27
-rw-r--r--validation/restrict.c2
4 files changed, 30 insertions, 3 deletions
diff --git a/evaluate.c b/evaluate.c
index 34578be8..4d08956e 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -1817,7 +1817,6 @@ static struct symbol *evaluate_dereference(struct expression *expr)
ctype = ctype->ctype.base_type;
target = ctype->ctype.base_type;
- examine_symbol_type(target);
switch (ctype->type) {
default:
@@ -1827,6 +1826,7 @@ static struct symbol *evaluate_dereference(struct expression *expr)
*expr = *op;
return expr->ctype;
case SYM_PTR:
+ examine_symbol_type(target);
node = alloc_symbol(expr->pos, SYM_NODE);
node->ctype.modifiers = target->ctype.modifiers & MOD_SPECIFIER;
merge_type(node, ctype);
diff --git a/validation/c11-atomic.c b/validation/c11-atomic.c
index e87d06cd..fc2c27ae 100644
--- a/validation/c11-atomic.c
+++ b/validation/c11-atomic.c
@@ -66,7 +66,7 @@ void baz(void)
/*
* check-name: C11 _Atomic type qualifier
- * check-command: sparse -Wno-decl $file;
+ * check-command: sparse -Wno-decl $file
*
* check-error-start
c11-atomic.c:11:6: error: symbol 'f02' redeclared with different type (originally declared at c11-atomic.c:3) - incompatible argument 1 (different modifiers)
diff --git a/validation/eval/premature-examination.c b/validation/eval/premature-examination.c
new file mode 100644
index 00000000..bd2ffa90
--- /dev/null
+++ b/validation/eval/premature-examination.c
@@ -0,0 +1,27 @@
+extern int i;
+
+int foo(void)
+{
+ return *i;
+}
+
+int bar(void)
+{
+ return i[0];
+}
+
+int *qux(void)
+{
+ return &i[0];
+}
+
+/*
+ * check-name: premature-examination
+ * check-command: sparse -Wno-decl $file
+ *
+ * check-error-start
+eval/premature-examination.c:5:16: error: cannot dereference this type
+eval/premature-examination.c:10:17: error: cannot dereference this type
+eval/premature-examination.c:15:18: error: cannot dereference this type
+ * check-error-end
+ */
diff --git a/validation/restrict.c b/validation/restrict.c
index 92bfdae8..80c437b0 100644
--- a/validation/restrict.c
+++ b/validation/restrict.c
@@ -66,7 +66,7 @@ void baz(void)
/*
* check-name: restrict qualifier
- * check-command: sparse -Wno-decl $file;
+ * check-command: sparse -Wno-decl $file
*
* check-error-start
restrict.c:11:6: error: symbol 'f02' redeclared with different type (originally declared at restrict.c:3) - incompatible argument 1 (different modifiers)