public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Martin Schwidefsky <schwidefsky@de.ibm.com>
To: Dave Jones <davej@redhat.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>, linux-kernel@vger.kernel.org
Subject: Re: sparse warnings for variable length arrays
Date: Fri, 14 Jul 2006 13:00:58 +0200	[thread overview]
Message-ID: <1152874858.7522.18.camel@localhost> (raw)
In-Reply-To: <20060713170127.GI12807@redhat.com>

On Thu, 2006-07-13 at 13:01 -0400, Dave Jones wrote:
> On Thu, Jul 13, 2006 at 10:58:08AM +0200, Heiko Carstens wrote:
>  > Hi all,
>  > 
>  > in include/asm-s390/bitops.h we have several typedefs:
>  > 
>  > typedef struct { long _[__BITOPS_WORDS(size)]; } addrtype;
>  > 
>  > sparse warns about these with "error: bad constant expression".
>  > Is there any way to tell sparse to be quiet? __force doesn't seem to work.
> 
> In many cases, these turn up as on-stack variables.  It'd be
> nice if sparse could figure out the maximum potential bound
> and warn appropriately if they could reach $BIGSIZE.

The reason why I introduced the typedef was a bug that had its cause in
an on-stack bit field (actually is has been a single unsigned long) that
was passed to one of find_bit functions. The old find_bit inlines did
not tell the compiler that the content of the on-stack bit field is
accessed, just the address to it was passed and ther has been a "memory"
clobber. The "memory" clobber works fine with bit fields that are not on
the stack, it forces the compiler to write everything to memory before
calling the inline. For on-stack bit fields things look different, the
old inline did not inform the compiler that the content of the local
variable is accessed, only the address of a local variable is needed. If
no other code in the scope of the local variable accesses the content of
the bitfield the surprising conclusion of gcc is that since nobody
accesses the content it can remove the initialization of it and the
stack slot for it as well. gcc just passed the inline an address
pointing to nothing.

In short, we need the typedef (or something equivalent). Sparse reports
a false positive.

> For non-stack vars, it's less of an issue of course.

Even for non-stack variables the typedef makes sense. By telling the
compiler exactly what is accessed by the inline you don't need the
"memory" clobber anymore. The inlines of the s390 find_xxx_bit functions
do not have it. That allows the compiler to optimize a little bit
better.

-- 
blue skies,
  Martin.

Martin Schwidefsky
Linux for zSeries Development & Services
IBM Deutschland Entwicklung GmbH

"Reality continues to ruin my life." - Calvin.



      reply	other threads:[~2006-07-14 11:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-13  8:58 sparse warnings for variable length arrays Heiko Carstens
2006-07-13 17:01 ` Dave Jones
2006-07-14 11:00   ` Martin Schwidefsky [this message]

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=1152874858.7522.18.camel@localhost \
    --to=schwidefsky@de.ibm.com \
    --cc=davej@redhat.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=linux-kernel@vger.kernel.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