Linux-Sparse Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/2] predefine: fix multi-token predefine
@ 2020-07-05 13:11 Luc Van Oostenryck
  2020-07-05 13:11 ` [PATCH 1/2] predefine: add testcase for multi-token predefines Luc Van Oostenryck
  2020-07-05 13:11 ` [PATCH 2/2] predefine: fix multi-token predefine Luc Van Oostenryck
  0 siblings, 2 replies; 3+ messages in thread
From: Luc Van Oostenryck @ 2020-07-05 13:11 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

The function predefine() and its variants are only valid
if they define a single-token value but predefine_min()
will produce a multi-token value if the type is signed.
    
This series contains a fix and a tescase for this.


Luc Van Oostenryck (2):
  predefine: add testcase for multi-token predefines
  predefine: fix multi-token predefine

 predefine.c                            | 2 +-
 validation/preprocessor/predef-token.c | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)
 create mode 100644 validation/preprocessor/predef-token.c


base-commit: 88c90bb192663bfc2dc54782c316e39e6fe26e1d
-- 
2.27.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] predefine: add testcase for multi-token predefines
  2020-07-05 13:11 [PATCH 0/2] predefine: fix multi-token predefine Luc Van Oostenryck
@ 2020-07-05 13:11 ` Luc Van Oostenryck
  2020-07-05 13:11 ` [PATCH 2/2] predefine: fix multi-token predefine Luc Van Oostenryck
  1 sibling, 0 replies; 3+ messages in thread
From: Luc Van Oostenryck @ 2020-07-05 13:11 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

The function predefine() and its variants are only valid
if they define a single-token value.

Add a testcase for this.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/preprocessor/predef-token.c | 5 +++++
 1 file changed, 5 insertions(+)
 create mode 100644 validation/preprocessor/predef-token.c

diff --git a/validation/preprocessor/predef-token.c b/validation/preprocessor/predef-token.c
new file mode 100644
index 000000000000..6df8ea407fc5
--- /dev/null
+++ b/validation/preprocessor/predef-token.c
@@ -0,0 +1,5 @@
+static __UINT8_TYPE__ u8;
+
+/*
+ * check-name: predef-token
+ */
-- 
2.27.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] predefine: fix multi-token predefine
  2020-07-05 13:11 [PATCH 0/2] predefine: fix multi-token predefine Luc Van Oostenryck
  2020-07-05 13:11 ` [PATCH 1/2] predefine: add testcase for multi-token predefines Luc Van Oostenryck
@ 2020-07-05 13:11 ` Luc Van Oostenryck
  1 sibling, 0 replies; 3+ messages in thread
From: Luc Van Oostenryck @ 2020-07-05 13:11 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

The function predefine() and its variants are only valid
if they define a single-token value.

However, when a type is signed, predefine_min() will produce
a multi-token value.

Fix this by using add_pre_buffer() instead of predefine().

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 predefine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/predefine.c b/predefine.c
index ff457b389480..d05b1018fdce 100644
--- a/predefine.c
+++ b/predefine.c
@@ -52,7 +52,7 @@ static void predefined_min(const char *name, struct symbol *type)
 	snprintf(buf, sizeof(buf), "__%s_MIN__", name);
 
 	if (is_signed_type(type))
-		predefine(buf, 1, "(-__%s_MAX__ - 1)", name);
+		add_pre_buffer("#weak_define %s (-__%s_MAX__ - 1)\n", buf, name);
 	else
 		predefine(buf, 1, "0%s", suffix);
 }
-- 
2.27.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-05 13:11 [PATCH 0/2] predefine: fix multi-token predefine Luc Van Oostenryck
2020-07-05 13:11 ` [PATCH 1/2] predefine: add testcase for multi-token predefines Luc Van Oostenryck
2020-07-05 13:11 ` [PATCH 2/2] predefine: fix multi-token predefine Luc Van Oostenryck

Linux-Sparse Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-sparse/0 linux-sparse/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-sparse linux-sparse/ https://lore.kernel.org/linux-sparse \
		linux-sparse@vger.kernel.org
	public-inbox-index linux-sparse

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-sparse


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git