linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: sparse@chrisli.org
Cc: linux-sparse@vger.kernel.org
Subject: [PATCH] sparse: make __builtin_object_size argument const
Date: Tue,  4 Oct 2016 10:54:45 +0200	[thread overview]
Message-ID: <1475571285-18180-1-git-send-email-johannes@sipsolutions.net> (raw)

gcc clearly allows that, and this makes no difference since we
can still pass a non-const pointer without warnings.

Add a test for it, while at it.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
---
 lib.c                            |  2 +-
 validation/builtin_object_size.c | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 validation/builtin_object_size.c

diff --git a/lib.c b/lib.c
index 8dc5bcf9dc18..cade28c95a48 100644
--- a/lib.c
+++ b/lib.c
@@ -877,7 +877,7 @@ void declare_builtin_functions(void)
 	add_pre_buffer("extern int __builtin_isunordered(float, float);\n");
 
 	/* And some __FORTIFY_SOURCE ones.. */
-	add_pre_buffer ("extern __SIZE_TYPE__ __builtin_object_size(void *, int);\n");
+	add_pre_buffer ("extern __SIZE_TYPE__ __builtin_object_size(const void *, int);\n");
 	add_pre_buffer ("extern void * __builtin___memcpy_chk(void *, const void *, __SIZE_TYPE__, __SIZE_TYPE__);\n");
 	add_pre_buffer ("extern void * __builtin___memmove_chk(void *, const void *, __SIZE_TYPE__, __SIZE_TYPE__);\n");
 	add_pre_buffer ("extern void * __builtin___mempcpy_chk(void *, const void *, __SIZE_TYPE__, __SIZE_TYPE__);\n");
diff --git a/validation/builtin_object_size.c b/validation/builtin_object_size.c
new file mode 100644
index 000000000000..a7013a80e7fd
--- /dev/null
+++ b/validation/builtin_object_size.c
@@ -0,0 +1,13 @@
+static void fn(void)
+{
+	static int i;
+	const void *ptr = (void *)0;
+
+	i = __builtin_object_size(ptr, 0);
+}
+
+/*
+ * check-name: __builtin_object_size
+ * check-error-start
+ * check-error-end
+ */
-- 
2.8.1


             reply	other threads:[~2016-10-04  8:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-04  8:54 Johannes Berg [this message]
2016-10-04  8:55 ` [PATCH] sparse: make __builtin_object_size argument const Johannes Berg

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=1475571285-18180-1-git-send-email-johannes@sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=linux-sparse@vger.kernel.org \
    --cc=sparse@chrisli.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).