From: "Christopher Li" <sparse@chrisli.org>
To: Alexey Zaytsev <alexey.zaytsev@gmail.com>
Cc: linux-sparse@vger.kernel.org, Tommy Thorn <tommy@numba-tu.com>
Subject: Re: [PATCH] Null ctype should have ptr_ctype as its base type.
Date: Sun, 28 Dec 2008 12:52:59 -0800 [thread overview]
Message-ID: <70318cbf0812281252m70c70493h507295316e6621df@mail.gmail.com> (raw)
In-Reply-To: <20081228151134.6062.83633.stgit@zaytsev.su>
[-- Attachment #1: Type: text/plain, Size: 597 bytes --]
On Sun, Dec 28, 2008 at 7:14 AM, Alexey Zaytsev
<alexey.zaytsev@gmail.com> wrote:
> So, we are getting a sizeof(NULL), or a sizeof((void *)0). It triggers here
That is my fault. My test for void type should have been more careful.
> because we are getting a null_ctype, and it's base_type points to
> void_ctype. I'm not sure if this patch is correct, but it seems to do
> the trick, all void warnings are gone. Christopher?
No, that is not the right way to fix it. Now you declare NULL as pointer
to a pointer type "(void**) 0".
Thanks for finding it out. Does my patch work for you?
Chris
[-- Attachment #2: 0001-Correct-testing-for-void-type.patch --]
[-- Type: application/octet-stream, Size: 1549 bytes --]
From a7b5de90ea3ea8485882ba348b045279709bd6d9 Mon Sep 17 00:00:00 2001
From: Christopher Li <sparse@chrisli.org>
Date: Sun, 28 Dec 2008 12:31:50 -0800
Subject: [PATCH] Correct testing for void type.
The last sizeof(void) warning commit too eager to
declare type is void. It end up sizeof(NULL) == 1
as well.
Signed-off-by: Christopher Li <sparse@chrisli.org>
---
evaluate.c | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/evaluate.c b/evaluate.c
index d99d34f..2fff46e 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -337,6 +337,13 @@ static inline int is_byte_type(struct symbol *type)
return type->bit_size == bits_in_char && type->type != SYM_BITFIELD;
}
+static inline int is_void_type(struct symbol *type)
+{
+ if (type->type == SYM_NODE)
+ type = type->ctype.base_type;
+ return type == &void_ctype;
+}
+
enum {
TYPE_NUM = 1,
TYPE_BITFIELD = 2,
@@ -584,7 +591,7 @@ static struct symbol *evaluate_ptr_add(struct expression *expr, struct symbol *i
}
/* Get the size of whatever the pointer points to */
- multiply = (base == &void_ctype) ? 1 : bits_to_bytes(base->bit_size);
+ multiply = is_void_type(base) ? 1 : bits_to_bytes(base->bit_size);
if (ctype == &null_ctype)
ctype = &ptr_ctype;
@@ -2050,7 +2057,7 @@ static struct symbol *evaluate_sizeof(struct expression *expr)
size = type->bit_size;
- if (type->ctype.base_type == &void_ctype) {
+ if (size < 0 && is_void_type(type)) {
warning(expr->pos, "expression using sizeof(void)");
size = bits_in_char;
}
--
1.6.0.6
next prev parent reply other threads:[~2008-12-28 20:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-25 2:09 [PATCH] Warn about explicit usage of sizeof(void) Christopher Li
2008-12-25 17:23 ` Tommy Thorn
2008-12-25 18:36 ` [PATCH] Warn about explicit usage of sizeof(void) and sizeof(function) Alexey Zaytsev
2008-12-25 19:45 ` Christopher Li
2008-12-25 20:10 ` [PATCH] Also warn about sizeof(function) Alexey Zaytsev
2008-12-26 0:48 ` Christopher Li
2008-12-28 15:14 ` [PATCH] Null ctype should have ptr_ctype as its base type Alexey Zaytsev
2008-12-28 20:52 ` Christopher Li [this message]
2008-12-28 21:38 ` Alexey Zaytsev
2008-12-29 7:32 ` Christopher Li
2008-12-29 9:03 ` Alexey Zaytsev
2008-12-25 18:48 ` [PATCH] Warn about explicit usage of sizeof(void) Christopher Li
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=70318cbf0812281252m70c70493h507295316e6621df@mail.gmail.com \
--to=sparse@chrisli.org \
--cc=alexey.zaytsev@gmail.com \
--cc=linux-sparse@vger.kernel.org \
--cc=tommy@numba-tu.com \
/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).