From: Kris Van Hees <kris.van.hees@oracle.com>
To: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: [PATCH 3/4] parser: accept typedef names as offsetof members
Date: Mon, 09 Nov 2026 20:09:16 +0000 [thread overview]
Message-ID: <192dc1a5c9806037591b9fe47fca29fb@oracle.com> (raw)
Allow the member argument of offsetof() to be either an identifier or a
type-name token. Kernel typedefs such as code can otherwise cause valid
member names to being recognized during parsing.
Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
---
libdtrace/dt_grammar.y | 12 ++++++++++--
test/unittest/offsetof/tst.typedef-member.d | 21 +++++++++++++++++++++
test/unittest/offsetof/tst.typedef-member.r | 2 ++
3 files changed, 33 insertions(+), 2 deletions(-)
create mode 100644 test/unittest/offsetof/tst.typedef-member.d
create mode 100644 test/unittest/offsetof/tst.typedef-member.r
diff --git a/libdtrace/dt_grammar.y b/libdtrace/dt_grammar.y
index 7984b85d..83feb9f7 100644
--- a/libdtrace/dt_grammar.y
+++ b/libdtrace/dt_grammar.y
@@ -1,7 +1,7 @@
%{
/*
* Oracle Linux DTrace.
- * Copyright (c) 2006, 2025, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2026, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
@@ -153,6 +153,8 @@ int yylex (void);
%type <l_decl> direct_abstract_declarator
%type <l_decl> translator_input_type
+%type <l_str> offsetof_member
+
%type <l_node> parameter_type_list
%type <l_node> parameter_list
%type <l_node> parameter_declaration
@@ -387,7 +389,7 @@ postfix_expression:
$$ = OP1(DT_TOK_POSTDEC, $1);
}
| DT_TOK_OFFSETOF DT_TOK_LPAR type_name DT_TOK_COMMA
- DT_TOK_IDENT DT_TOK_RPAR {
+ offsetof_member DT_TOK_RPAR {
$$ = dt_node_offsetof($3, $5);
}
| DT_TOK_XLATE DT_TOK_LT type_name DT_TOK_GT
@@ -396,6 +398,12 @@ postfix_expression:
}
;
+/* A member name can also be a typedef name in an unrelated scope. */
+offsetof_member:
+ DT_TOK_IDENT
+ | DT_TOK_TNAME
+ ;
+
unary_expression:
postfix_expression
| DT_TOK_ADDADD unary_expression { $$ = OP1(DT_TOK_PREINC, $2); }
diff --git a/test/unittest/offsetof/tst.typedef-member.d b/test/unittest/offsetof/tst.typedef-member.d
new file mode 100644
index 00000000..e3838b61
--- /dev/null
+++ b/test/unittest/offsetof/tst.typedef-member.d
@@ -0,0 +1,21 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION:
+ * offsetof() accepts a member name that is also a typedef name. The kernel
+ * defines both the code typedef and flow_dissector_key_icmp.code, which is
+ * inside an anonymous struct.
+ */
+
+#pragma D option quiet
+
+dtrace:::BEGIN
+{
+ printf("offset is %d\n", offsetof(struct `flow_dissector_key_icmp, code));
+ exit(offsetof(struct `flow_dissector_key_icmp, code) != 1);
+}
diff --git a/test/unittest/offsetof/tst.typedef-member.r b/test/unittest/offsetof/tst.typedef-member.r
new file mode 100644
index 00000000..96366d41
--- /dev/null
+++ b/test/unittest/offsetof/tst.typedef-member.r
@@ -0,0 +1,2 @@
+offset is 1
+
--
2.52.0
reply other threads:[~2026-11-09 20:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=192dc1a5c9806037591b9fe47fca29fb@oracle.com \
--to=kris.van.hees@oracle.com \
--cc=dtrace-devel@oss.oracle.com \
--cc=dtrace@lists.linux.dev \
/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