linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] linearize: Emit C99 declarations correctly
@ 2016-05-04 12:39 Emily Maier
  2016-05-04 12:39 ` [PATCH 2/2] validation: Check C99 for loop variables Emily Maier
  2016-11-02 13:57 ` [PATCH 1/2] linearize: Emit C99 declarations correctly Luc Van Oostenryck
  0 siblings, 2 replies; 5+ messages in thread
From: Emily Maier @ 2016-05-04 12:39 UTC (permalink / raw)
  To: linux-sparse; +Cc: Emily Maier

Variables declared with C99 syntax inside a for statement should be
linearized in the loop top, rather than implicitly inside the loop body.

Signed-off-by: Emily Maier <emily@emilymaier.net>
---
 linearize.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/linearize.c b/linearize.c
index c6ada1e..1309c7d 100644
--- a/linearize.c
+++ b/linearize.c
@@ -1946,7 +1946,11 @@ static pseudo_t linearize_iterator(struct entrypoint *ep, struct statement *stmt
 	struct statement  *post_statement = stmt->iterator_post_statement;
 	struct expression *post_condition = stmt->iterator_post_condition;
 	struct basic_block *loop_top, *loop_body, *loop_continue, *loop_end;
+	struct symbol *sym;
 
+	FOR_EACH_PTR(stmt->iterator_syms, sym) {
+		linearize_one_symbol(ep, sym);
+	} END_FOR_EACH_PTR(sym);
 	concat_symbol_list(stmt->iterator_syms, &ep->syms);
 	linearize_statement(ep, pre_statement);
 
-- 
2.5.5


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

* [PATCH 2/2] validation: Check C99 for loop variables
  2016-05-04 12:39 [PATCH 1/2] linearize: Emit C99 declarations correctly Emily Maier
@ 2016-05-04 12:39 ` Emily Maier
  2016-11-02 14:04   ` Luc Van Oostenryck
  2016-11-02 13:57 ` [PATCH 1/2] linearize: Emit C99 declarations correctly Luc Van Oostenryck
  1 sibling, 1 reply; 5+ messages in thread
From: Emily Maier @ 2016-05-04 12:39 UTC (permalink / raw)
  To: linux-sparse; +Cc: Emily Maier

Previously, sparse would generate incorrect code in the presence of a
C99 variable declaration inside the for statement, completely dropping
the code after the end of the for loop. Check that it's now behaving
correctly by entering a context and not leaving it at the end of the
loop.

Signed-off-by: Emily Maier <emily@emilymaier.net>
---
 validation/c99-for-loop.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 validation/c99-for-loop.c

diff --git a/validation/c99-for-loop.c b/validation/c99-for-loop.c
new file mode 100644
index 0000000..42246c5
--- /dev/null
+++ b/validation/c99-for-loop.c
@@ -0,0 +1,33 @@
+int op(int);
+
+static int good(void)
+{
+	__context__(1);
+	for (int i = 0; i < 10; i++) {
+		if (!op(i)) {
+			__context__(-1);
+			return 0;
+		}
+	}
+	__context__(-1);
+	return 1;
+}
+
+static int bad(void)
+{
+	__context__(1);
+	for (int i = 0; i < 10; i++) {
+		if (!op(i)) {
+			__context__(-1);
+			return 0;
+		}
+	}
+	return 1;
+}
+/*
+ * check-name: C99 for loop variable declaration
+ *
+ * check-error-start
+c99-for-loop.c:16:12: warning: context imbalance in 'bad' - different lock contexts for basic block
+ * check-error-end
+ */
-- 
2.5.5


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

* Re: [PATCH 1/2] linearize: Emit C99 declarations correctly
  2016-05-04 12:39 [PATCH 1/2] linearize: Emit C99 declarations correctly Emily Maier
  2016-05-04 12:39 ` [PATCH 2/2] validation: Check C99 for loop variables Emily Maier
@ 2016-11-02 13:57 ` Luc Van Oostenryck
  2016-11-17  9:14   ` Christopher Li
  1 sibling, 1 reply; 5+ messages in thread
From: Luc Van Oostenryck @ 2016-11-02 13:57 UTC (permalink / raw)
  To: Emily Maier; +Cc: linux-sparse

On Wed, May 04, 2016 at 08:39:43AM -0400, Emily Maier wrote:
> Variables declared with C99 syntax inside a for statement should be
> linearized in the loop top, rather than implicitly inside the loop body.
> 
> Signed-off-by: Emily Maier <emily@emilymaier.net>
> ---
>  linearize.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/linearize.c b/linearize.c
> index c6ada1e..1309c7d 100644
> --- a/linearize.c
> +++ b/linearize.c
> @@ -1946,7 +1946,11 @@ static pseudo_t linearize_iterator(struct entrypoint *ep, struct statement *stmt
>  	struct statement  *post_statement = stmt->iterator_post_statement;
>  	struct expression *post_condition = stmt->iterator_post_condition;
>  	struct basic_block *loop_top, *loop_body, *loop_continue, *loop_end;
> +	struct symbol *sym;
>  
> +	FOR_EACH_PTR(stmt->iterator_syms, sym) {
> +		linearize_one_symbol(ep, sym);
> +	} END_FOR_EACH_PTR(sym);
>  	concat_symbol_list(stmt->iterator_syms, &ep->syms);
>  	linearize_statement(ep, pre_statement);
>  
> -- 

Interesting catch!

Reviewed-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Tested-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>

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

* Re: [PATCH 2/2] validation: Check C99 for loop variables
  2016-05-04 12:39 ` [PATCH 2/2] validation: Check C99 for loop variables Emily Maier
@ 2016-11-02 14:04   ` Luc Van Oostenryck
  0 siblings, 0 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2016-11-02 14:04 UTC (permalink / raw)
  To: Emily Maier; +Cc: linux-sparse

On Wed, May 04, 2016 at 08:39:44AM -0400, Emily Maier wrote:
> Previously, sparse would generate incorrect code in the presence of a
> C99 variable declaration inside the for statement, completely dropping
> the code after the end of the for loop. Check that it's now behaving
> correctly by entering a context and not leaving it at the end of the
> loop.
> 
> Signed-off-by: Emily Maier <emily@emilymaier.net>
> ---

I think a simpler test case showing the generality of the problem
would be even nicer but that would involve the output of
test-linearize and as such this is not usable in the test suite.

This test case has the decisive advantage to be testable.

Revieved-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>

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

* Re: [PATCH 1/2] linearize: Emit C99 declarations correctly
  2016-11-02 13:57 ` [PATCH 1/2] linearize: Emit C99 declarations correctly Luc Van Oostenryck
@ 2016-11-17  9:14   ` Christopher Li
  0 siblings, 0 replies; 5+ messages in thread
From: Christopher Li @ 2016-11-17  9:14 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: Emily Maier, Linux-Sparse

On Wed, Nov 2, 2016 at 9:57 PM, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
> On Wed, May 04, 2016 at 08:39:43AM -0400, Emily Maier wrote:
>> Variables declared with C99 syntax inside a for statement should be
>> linearized in the loop top, rather than implicitly inside the loop body.
> Reviewed-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> Tested-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>

Applied.

Chris

PS. I am pretty happy now I have develop a system to catch up with large
amount of back log patches.

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

end of thread, other threads:[~2016-11-17  9:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-04 12:39 [PATCH 1/2] linearize: Emit C99 declarations correctly Emily Maier
2016-05-04 12:39 ` [PATCH 2/2] validation: Check C99 for loop variables Emily Maier
2016-11-02 14:04   ` Luc Van Oostenryck
2016-11-02 13:57 ` [PATCH 1/2] linearize: Emit C99 declarations correctly Luc Van Oostenryck
2016-11-17  9:14   ` Christopher Li

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).