Linux-Sparse Archive on
 help / color / Atom feed
* [PATCH] generic: fix missing inlining of generic expression
@ 2020-07-24 22:26 Luc Van Oostenryck
  0 siblings, 0 replies; only message in thread
From: Luc Van Oostenryck @ 2020-07-24 22:26 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck, Peter Zijlstra

Inlining in sparse works slightly differently than what my
mental model is: the body is only evaluated after the inline
expansion. IOW, an inline function is not evaluated until it
is effectively inlined. That's fine but it means that generic
expressions also need to be handled during the inlining.

However, since the body of inline functions is evaluated just
after inline expansion, so (recursively) copying the expression
and its type - expression map is quite useless here.

So, just copy the expression itself and its control expression
to 'isolate' them from evaluation, evaluate it and then just
copy the selected expression.

Reported-by: Peter Zijlstra <>
Signed-off-by: Luc Van Oostenryck <>
 inline.c                    |  8 ++++++++
 validation/inline-generic.c | 10 ++++++++++
 2 files changed, 18 insertions(+)

This patch is also available for testing on sparse-dev repo:
 git:// gen-crash

diff --git a/inline.c b/inline.c
index a959728013f1..eceef8ba0443 100644
--- a/inline.c
+++ b/inline.c
@@ -274,6 +274,14 @@ static struct expression * copy_expression(struct expression *expr)
+		expr = dup_expression(expr);
+		expr->control = copy_expression(expr->control);
+		if (!evaluate_expression(expr))
+			return NULL;
+		expr = copy_expression(expr);
+		break;
 		warning(expr->pos, "trying to copy expression type %d", expr->type);
diff --git a/validation/inline-generic.c b/validation/inline-generic.c
new file mode 100644
index 000000000000..1f05c07904b5
--- /dev/null
+++ b/validation/inline-generic.c
@@ -0,0 +1,10 @@
+extern int a, b;
+inline int c(void) { return a++; }
+inline int e(int d) { return 0; }
+inline unsigned f(void) { return e(_Generic(b, int: c())); }
+static int g(void) { return f(); }
+static int h(void) { return f(); }
+ * check-name: inline-generic
+ */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-24 22:26 [PATCH] generic: fix missing inlining of generic expression Luc Van Oostenryck

Linux-Sparse Archive on

Archives are clonable:
	git clone --mirror 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/ \
	public-inbox-index linux-sparse

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone