linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] fix missing base type examination
@ 2017-11-25  9:31 Luc Van Oostenryck
  2017-11-25  9:31 ` [PATCH 1/2] add test case unexamined base type Luc Van Oostenryck
  2017-11-25  9:31 ` [PATCH 2/2] fix: evaluate_dereference() " Luc Van Oostenryck
  0 siblings, 2 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2017-11-25  9:31 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

The goal of this series is to add te missing
examination of the base type in evaluate_dereference().

Luc Van Oostenryck (2):
  add test case unexamined base type
  fix: evaluate_dereference() unexamined base type

 evaluate.c                                |  2 +-
 validation/bugs/unexamined-base-type-00.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 validation/bugs/unexamined-base-type-00.c


The series is available for testing at:
	git://github.com/lucvoo/sparse-dev.git fix-unexamined

-- Luc Van Oostenryck

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] add test case unexamined base type
  2017-11-25  9:31 [PATCH 0/2] fix missing base type examination Luc Van Oostenryck
@ 2017-11-25  9:31 ` Luc Van Oostenryck
  2017-11-25  9:31 ` [PATCH 2/2] fix: evaluate_dereference() " Luc Van Oostenryck
  1 sibling, 0 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2017-11-25  9:31 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/bugs/unexamined-base-type-00.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 validation/bugs/unexamined-base-type-00.c

diff --git a/validation/bugs/unexamined-base-type-00.c b/validation/bugs/unexamined-base-type-00.c
new file mode 100644
index 000000000..2032599b7
--- /dev/null
+++ b/validation/bugs/unexamined-base-type-00.c
@@ -0,0 +1,29 @@
+# define __force	__attribute__((force))
+
+
+struct s {
+	int a;
+};
+
+static int foo(struct s *s)
+{
+	return (*((typeof(s->a) __force *) &s->a)) & 1;
+}
+
+
+/*
+ * check-name: unexamined base type 00
+ * check-command: test-linearize -Wno-decl $file
+ * check-description:
+ *	The wrong generated is:
+ *		ptrcast.64  %r3 <- (64) %arg1
+ *		load        %r4 <- 0[%r3]	; !! WRONG
+ *		cast.32     %r5 <- (0) %r4	; !! WRONG
+ *		and.32      %r6 <- %r5, $1
+ *		ret.32      %r6
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: load[^.]
+ * check-output-excludes: cast\..*(0)
+ */
-- 
2.15.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] fix: evaluate_dereference() unexamined base type
  2017-11-25  9:31 [PATCH 0/2] fix missing base type examination Luc Van Oostenryck
  2017-11-25  9:31 ` [PATCH 1/2] add test case unexamined base type Luc Van Oostenryck
@ 2017-11-25  9:31 ` Luc Van Oostenryck
  2017-11-26 17:48   ` Christopher Li
  1 sibling, 1 reply; 5+ messages in thread
From: Luc Van Oostenryck @ 2017-11-25  9:31 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

Examination of a pointer type doesn't examine the corresponding base type
(this base type maybe not yet be complete).
The examination of thz base type must thus be done later.

However, in some cases (maybe only when typeof() is involved) it's
possible to call evaluate_dereference() while the base type is still
unexamined.

Fix this by adding the missing examine_symbol_type() on the base type.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 evaluate.c                                | 2 +-
 validation/bugs/unexamined-base-type-00.c | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/evaluate.c b/evaluate.c
index 4bca13542..bb128ecd8 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -1777,7 +1777,7 @@ static struct symbol *evaluate_dereference(struct expression *expr)
 		ctype = ctype->ctype.base_type;
 
 	node = alloc_symbol(expr->pos, SYM_NODE);
-	target = ctype->ctype.base_type;
+	target = examine_symbol_type(ctype->ctype.base_type);
 
 	switch (ctype->type) {
 	default:
diff --git a/validation/bugs/unexamined-base-type-00.c b/validation/bugs/unexamined-base-type-00.c
index 2032599b7..7749a9def 100644
--- a/validation/bugs/unexamined-base-type-00.c
+++ b/validation/bugs/unexamined-base-type-00.c
@@ -21,7 +21,6 @@ static int foo(struct s *s)
  *		cast.32     %r5 <- (0) %r4	; !! WRONG
  *		and.32      %r6 <- %r5, $1
  *		ret.32      %r6
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-excludes: load[^.]
-- 
2.15.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] fix: evaluate_dereference() unexamined base type
  2017-11-25  9:31 ` [PATCH 2/2] fix: evaluate_dereference() " Luc Van Oostenryck
@ 2017-11-26 17:48   ` Christopher Li
  2017-11-26 19:18     ` Luc Van Oostenryck
  0 siblings, 1 reply; 5+ messages in thread
From: Christopher Li @ 2017-11-26 17:48 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: Linux-Sparse

On Sat, Nov 25, 2017 at 5:31 PM, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
> Examination of a pointer type doesn't examine the corresponding base type
> (this base type maybe not yet be complete).
> The examination of thz base type must thus be done later.
>
> However, in some cases (maybe only when typeof() is involved) it's
> possible to call evaluate_dereference() while the base type is still
> unexamined.
>
> Fix this by adding the missing examine_symbol_type() on the base type.

The changes looks fine to me.

Will this show up as some thing easy pull-able for
sparse master?

Chris

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] fix: evaluate_dereference() unexamined base type
  2017-11-26 17:48   ` Christopher Li
@ 2017-11-26 19:18     ` Luc Van Oostenryck
  0 siblings, 0 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2017-11-26 19:18 UTC (permalink / raw)
  To: Christopher Li; +Cc: Linux-Sparse

On Mon, Nov 27, 2017 at 01:48:01AM +0800, Christopher Li wrote:
> On Sat, Nov 25, 2017 at 5:31 PM, Luc Van Oostenryck
> <luc.vanoostenryck@gmail.com> wrote:
> > Examination of a pointer type doesn't examine the corresponding base type
> > (this base type maybe not yet be complete).
> > The examination of thz base type must thus be done later.
> >
> > However, in some cases (maybe only when typeof() is involved) it's
> > possible to call evaluate_dereference() while the base type is still
> > unexamined.
> >
> > Fix this by adding the missing examine_symbol_type() on the base type.
> 
> The changes looks fine to me.

But better to hold now for now.
I *think* the change is correct but things are a bit muddy
there and it triggers another, more annoying, bug.

-- Luc

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-11-26 19:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-25  9:31 [PATCH 0/2] fix missing base type examination Luc Van Oostenryck
2017-11-25  9:31 ` [PATCH 1/2] add test case unexamined base type Luc Van Oostenryck
2017-11-25  9:31 ` [PATCH 2/2] fix: evaluate_dereference() " Luc Van Oostenryck
2017-11-26 17:48   ` Christopher Li
2017-11-26 19:18     ` Luc Van Oostenryck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).