linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 1/5] unqual: add testcases
Date: Wed, 18 Nov 2020 22:11:43 +0100	[thread overview]
Message-ID: <20201118211147.10680-2-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20201118211147.10680-1-luc.vanoostenryck@gmail.com>

Add some testcases related to qualifier dropping / lvalue conversion.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/eval/unqual-comma.c     | 13 +++++++++++++
 validation/eval/unqual-postop.c    | 23 +++++++++++++++++++++++
 validation/eval/unqual-stmt-expr.c | 13 +++++++++++++
 validation/eval/unqual02.c         | 26 ++++++++++++++++++++++++++
 4 files changed, 75 insertions(+)
 create mode 100644 validation/eval/unqual-comma.c
 create mode 100644 validation/eval/unqual-postop.c
 create mode 100644 validation/eval/unqual-stmt-expr.c
 create mode 100644 validation/eval/unqual02.c

diff --git a/validation/eval/unqual-comma.c b/validation/eval/unqual-comma.c
new file mode 100644
index 000000000000..e06586cd43e3
--- /dev/null
+++ b/validation/eval/unqual-comma.c
@@ -0,0 +1,13 @@
+#define __unqual_typeof(x) typeof(((void)0, (x)))
+
+int *foo(volatile int x);
+int *foo(volatile int x)
+{
+	extern __unqual_typeof(x) y;
+	return &y;
+}
+
+/*
+ * check-name: unqual-comma
+ * check-known-to-fail
+ */
diff --git a/validation/eval/unqual-postop.c b/validation/eval/unqual-postop.c
new file mode 100644
index 000000000000..fb3082dc8836
--- /dev/null
+++ b/validation/eval/unqual-postop.c
@@ -0,0 +1,23 @@
+static void test_volatile(void)
+{
+	volatile int x = 0;
+	int *pp;
+
+	typeof(++x)		v1; pp = &v1;	// KO
+	typeof(x++)		v2; pp = &v2;	// KO
+}
+
+/*
+ * check-name: unqual-postop
+ * check-command: sparse -Wno-declaration-after-statement $file
+ * check-known-to-fail
+ *
+ * check-error-start
+eval/unqual-postop.c:6:40: warning: incorrect type in assignment (different modifiers)
+eval/unqual-postop.c:6:40:    expected int *pp
+eval/unqual-postop.c:6:40:    got int volatile *
+eval/unqual-postop.c:7:40: warning: incorrect type in assignment (different modifiers)
+eval/unqual-postop.c:7:40:    expected int *pp
+eval/unqual-postop.c:7:40:    got int volatile *
+ * check-error-end
+ */
diff --git a/validation/eval/unqual-stmt-expr.c b/validation/eval/unqual-stmt-expr.c
new file mode 100644
index 000000000000..bac6cb6b197f
--- /dev/null
+++ b/validation/eval/unqual-stmt-expr.c
@@ -0,0 +1,13 @@
+#define __unqual_typeof(x) typeof(({ x; }))
+
+int *foo(volatile int x);
+int *foo(volatile int x)
+{
+	extern __unqual_typeof(x) y;
+	return &y;
+}
+
+/*
+ * check-name: unqual-stmt-expr
+ * check-known-to-fail
+ */
diff --git a/validation/eval/unqual02.c b/validation/eval/unqual02.c
new file mode 100644
index 000000000000..f136cbd50510
--- /dev/null
+++ b/validation/eval/unqual02.c
@@ -0,0 +1,26 @@
+static void test_const(volatile int x)
+{
+	const int x = 0;
+	typeof(1?x:x)		i3; i3 = 0;	// should be OK
+	typeof(+x)		i4; i4 = 0;	// should be OK
+	typeof(-x)		i5; i5 = 0;	// should be OK
+	typeof(!x)		i6; i6 = 0;	// should be OK
+	typeof(x+x)		i7; i7 = 0;	// should be OK
+}
+
+static void test_volatile(void)
+{
+	volatile int x = 0;
+	int *pp;
+
+	typeof(1?x:x)		i3; pp = &i3;	// should be OK
+	typeof(+x)		i4; pp = &i4;	// should be OK
+	typeof(-x)		i5; pp = &i5;	// should be OK
+	typeof(!x)		i6; pp = &i6;	// should be OK
+	typeof(x+x)		i7; pp = &i7;	// should be OK
+}
+
+/*
+ * check-name: unqual02
+ * check-command: sparse -Wno-declaration-after-statement $file
+ */
-- 
2.29.2


  reply	other threads:[~2020-11-18 21:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-18 21:11 [PATCH 0/5] fix qualifier dropping Luc Van Oostenryck
2020-11-18 21:11 ` Luc Van Oostenryck [this message]
2020-11-18 21:11 ` [PATCH 2/5] unqual: unqualify_type() should check for null ctypes Luc Van Oostenryck
2020-11-18 21:11 ` [PATCH 3/5] unqual: comma expressions should drop qualifiers Luc Van Oostenryck
2020-11-18 21:11 ` [PATCH 4/5] unqual: statement " Luc Van Oostenryck
2020-11-18 21:11 ` [PATCH 5/5] unqual: pre- & post-increment/decrement should *not* " Luc Van Oostenryck

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=20201118211147.10680-2-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=torvalds@linux-foundation.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).