linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Chris Li" <christ.li@gmail.com>
To: Pierre Habouzit <pierre.habouzit@m4x.org>
Cc: linux-sparse@vger.kernel.org
Subject: Re: for (int i = expr; ....)
Date: Fri, 22 Feb 2008 12:26:30 -0800	[thread overview]
Message-ID: <70318cbf0802221226l7888c24auafbe2aabfa9774b9@mail.gmail.com> (raw)
In-Reply-To: <20080221150527.GA7117@artemis.madism.org>

[-- Attachment #1: Type: text/plain, Size: 755 bytes --]

On Thu, Feb 21, 2008 at 7:05 AM, Pierre Habouzit
<pierre.habouzit@m4x.org> wrote:
> Sparse doesn't support the C99 construct `for (int i = expr; ....)` properly.
>  for example, the following C code:
>
>     #include <stdlib.h>
>
>     int main(void)
>     {
>         for (int i = atoi("12"); i < 10; i++);
>         return 0;
>     }
>
>  make sparse spit:
>
>     $ sparse -Wall test.c
>     test.c:5:22: warning: call with no type!
>
>  In fact sparse doesn't support 'expr' to be a complex enough expression
>  (expressions that can be folded work, but not any other afaict).

Nah, sparse supports expression in initializer all right.
It just need to evaluate them to give it the correct ctype.

Please try the this one line patch I attached.

Chris

[-- Attachment #2: init-notype --]
[-- Type: application/octet-stream, Size: 723 bytes --]

evaluate iterator symbols

evaluate.c forgets to evaluate iterator_syms, which
might have some expression in initializer.

Signed-Off-By: Christopher Li <sparse@chrisli.org>

Index: sparse/evaluate.c
===================================================================
--- sparse.orig/evaluate.c	2008-02-13 09:25:21.000000000 -0800
+++ sparse/evaluate.c	2008-02-22 10:07:10.000000000 -0800
@@ -3093,6 +3093,7 @@ static void evaluate_if_statement(struct
 
 static void evaluate_iterator(struct statement *stmt)
 {
+	evaluate_symbol_list(stmt->iterator_syms);
 	evaluate_conditional(stmt->iterator_pre_condition, 1);
 	evaluate_conditional(stmt->iterator_post_condition,1);
 	evaluate_statement(stmt->iterator_pre_statement);

  reply	other threads:[~2008-02-22 20:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-21 15:05 for (int i = expr; ....) Pierre Habouzit
2008-02-22 20:26 ` Chris Li [this message]
2008-02-23 13:33   ` Pierre Habouzit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=70318cbf0802221226l7888c24auafbe2aabfa9774b9@mail.gmail.com \
    --to=christ.li@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=pierre.habouzit@m4x.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).