GCC patch v2 description
This commit is contained in:
parent
060d7685c6
commit
68c42910dd
@ -1,7 +1,49 @@
|
||||
From 0d2945f8e3c1b89b122fef0ded3973dfae2eb904 Mon Sep 17 00:00:00 2001
|
||||
From: York Jasper Niebuhr <yjnworkstation@gmail.com>
|
||||
Date: Thu, 30 Oct 2025 13:12:24 +0100
|
||||
Subject: [PATCH] c_parse_component_ref callback
|
||||
Subject: [PATCH] c, plugin: Add c_parse_component_ref callback
|
||||
|
||||
This patch supersedes my earlier submission:
|
||||
https://gcc.gnu.org/pipermail/gcc-patches/2025-October/697934.html
|
||||
|
||||
It adds the c_parse_component_ref callback that plugins can register
|
||||
using register_c_parse_component_ref_cb. The callback receives the
|
||||
parsed COMPONENT_REF tree and may replace it by returning a new tree.
|
||||
Replacements that are not type-compatible with the original are ignored.
|
||||
|
||||
The callback allows plugins to observe or instrument struct member
|
||||
accesses that would otherwise be lost due to folding before the earliest
|
||||
possible plugin pass or hook. In particular, the fold_offsetof
|
||||
functionality removes all traces of type and member information in
|
||||
offsetof-like trees, leaving only an integer constant for plugins to
|
||||
inspect.
|
||||
|
||||
A typical use case would be to replace a select set of COMPONENT_REF
|
||||
nodes with type-compatible expressions calling a placeholder function,
|
||||
e.g. __deferred_offsetof(type, member). These calls cannot be folded
|
||||
away and thus remain available for plugin analysis in later passes.
|
||||
Offsets not of interest can be left untouched, preserving their const
|
||||
qualification and use in static assertions.
|
||||
|
||||
Allowing the callback to alter COMPONENT_REF nodes required minor
|
||||
adjustments to fold_offsetof, which assumes a specific input format.
|
||||
The parser paths that cannot guarantee that format after invoking the
|
||||
callback now use fold_offsetof_maybe(), which attempts to fold normally
|
||||
but, on failure, casts the unfolded expressions to the desired output
|
||||
type.
|
||||
|
||||
If the callback is not used to alter COMPONENT_REF trees, there is **no
|
||||
change** in GCC’s behavior.
|
||||
|
||||
Since this callback targets fairly niche use cases, I opted to not make
|
||||
it part of the public plugin API so there is no need for maintenance
|
||||
guarantees.
|
||||
|
||||
**Changes since the first proposal:**
|
||||
* Moved callback invocation to a higher level (the parser)
|
||||
* The callback is no longer part of the public plugin API
|
||||
|
||||
Signed-off-by: York Jasper Niebuhr <yjnworkstation@gmail.com>
|
||||
|
||||
---
|
||||
gcc/c-family/c-common.cc | 48 +++++++++++++++++++++------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user