Patch message
This commit is contained in:
parent
08272b175a
commit
7a09b69cfe
@ -1,7 +1,45 @@
|
||||
From ab8884cbf3712f939556fc7789bbf32132c7ff1a Mon Sep 17 00:00:00 2001
|
||||
From: York Jasper Niebuhr <yjnworkstation@gmail.com>
|
||||
Date: Fri, 17 Oct 2025 22:04:41 +0200
|
||||
Subject: [PATCH] PLUGIN_BUILD_COMPONENT_REF callback
|
||||
Subject: [PATCH] Add PLUGIN_BUILD_COMPONENT_REF callback
|
||||
|
||||
This patch adds the PLUGIN_BUILD_COMPONENT_REF callback, which is invoked
|
||||
by the C front end when a COMPONENT_REF node is built. The callback
|
||||
receives a pointer to the COMPONENT_REF tree (of type 'tree *'). Plugins
|
||||
may replace the node by assigning through the pointer, but any
|
||||
replacement must be type-compatible with the original node.
|
||||
|
||||
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 considered alternative was to disable fold_offsetof altogether.
|
||||
However, that prevents offsetof expressions from qualifying as
|
||||
constant-expressions; for example, static assertions can no longer be
|
||||
evaluated if they contain non-folded offsetof expressions. The callback
|
||||
provides fine-grained control over individual COMPONENT_REFs instead of
|
||||
universally changing folding behavior.
|
||||
|
||||
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 PLUGIN_BUILD_COMPONENT_REF to alter COMPONENT_REF nodes required
|
||||
minor adjustments to fold_offsetof, which assumes a specific input
|
||||
format. Code paths that cannot guarantee that format should now use
|
||||
fold_offsetof_maybe(), which attempts to fold normally but, on failure,
|
||||
casts the unfolded expression to the desired output type.
|
||||
|
||||
If the callback is not used to alter COMPONENT_REF trees, there is **no
|
||||
change** in GCC’s behavior.
|
||||
|
||||
Signed-off-by: York Jasper Niebuhr <yjnworkstation@gmail.com>
|
||||
|
||||
---
|
||||
gcc/c-family/c-common.cc | 48 +++++++++++++++++++++++++++++++---------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user