Implement the VLS roadmap on the native VBS build

Native VBS and CMake builds of the server and every registered suite:
protocol and document sync, VBS/compdb providers, stock GCC diagnostics
(including in-process default profile preparation), the stock occurrence
observer and hover/definition, the bounded Scheduler, C++ module graph,
scan and artifact cache with real CMI production, the context-aware
symbol index with schema-2 snapshot migration, navigation and guarded
rename, reflection provenance with splice-origin extraction, index-backed
completion and signature help, live GCC worker control with a registered
DAP suite, and the Neovim and VS Code clients.

VoidLibrary follows main. The private GCC 16.2.0 frontend is reproduced
from the versioned patches and verified stepping reflection/template code
with projected values 17/34 and 41/82.
This commit is contained in:
faumaray committed 2026-12-05 14:06:50 +03:00
1 parent ca04975d54
commit da8003f6d4
310 files changed
+47552 -480

No files matched your search

@@ -0,0 +1,581 @@
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -2501,6 +2501,12 @@
C++ ObjC++ Var(flag_visibility_ms_compat)
Changes visibility to match Microsoft Visual Studio by default.
+fvls-observe
+C++ Var(flag_vls_observe) Undocumented
+
+fvls-step
+C++ Var(flag_vls_step) Undocumented
+
fvtable-gc
C++ ObjC++ WarnRemoved
No longer supported.
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -110,7 +110,7 @@
cp/reflect.o cp/rtti.o \
cp/search.o cp/semantics.o \
cp/tree.o cp/typeck.o cp/typeck2.o \
- cp/vtable-class-hierarchy.o $(CXX_C_OBJS)
+ cp/vls-eval.o cp/vtable-class-hierarchy.o $(CXX_C_OBJS)
ifeq ($(if $(wildcard ../stage_current),$(shell cat \
../stage_current)),stageautofeedback)
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -42,6 +42,7 @@
#include "intl.h"
#include "toplev.h"
#include "contracts.h"
+#include "vls-eval.h"
static bool verify_constant (tree, bool, bool *, bool *);
#define VERIFY_CONSTANT(X) \
@@ -4277,6 +4278,10 @@
return t;
}
+ vls_eval::call observed;
+ if (flag_vls_observe && get_function_named_in_call (t) == orig_fun)
+ observed.enter (fun);
+
/* We can't defer instantiating the function any longer. */
if (!DECL_INITIAL (fun)
&& (DECL_TEMPLOID_INSTANTIATION (fun) || DECL_DEFAULTED_FN (fun))
@@ -4350,7 +4355,11 @@
new_obj = cxx_fold_indirect_ref (ctx, loc, DECL_CONTEXT (fun), new_obj,
&empty_base, jump_target);
if (*jump_target)
- return NULL_TREE;
+ {
+ if (observed.active ())
+ observed.outcome (throws (jump_target) ? "throw" : "jump");
+ return NULL_TREE;
+ }
/* If we're initializing an empty class, don't set constness, because
cxx_fold_indirect_ref will return the wrong object to set constness
of. */
@@ -4439,7 +4448,10 @@
{
bool cacheable = !!entry;
if (result && result != error_mark_node)
- /* OK */;
+ {
+ if (observed.active ())
+ observed.cached ();
+ }
else if (!DECL_SAVED_TREE (fun))
{
/* When at_eof >= 3, cgraph has started throwing away
@@ -4522,12 +4534,18 @@
jump_target);
ggc_free (activate);
if (*jump_target)
- return NULL_TREE;
+ {
+ if (observed.active ())
+ observed.outcome (throws (jump_target) ? "throw" : "jump");
+ return NULL_TREE;
+ }
}
ctx->global->metafns_called = false;
tree jmp_target = NULL_TREE;
+ if (observed.active ())
+ observed.body ();
cxx_eval_constant_expression (&call_ctx, body,
vc_discard, non_constant_p, overflow_p,
&jmp_target);
@@ -4550,6 +4568,9 @@
else
{
result = ctx->global->get_value (res);
+ if (observed.active () && result && !*non_constant_p
+ && !*overflow_p && !*jump_target)
+ observed.value (result);
if (result == NULL_TREE && !*non_constant_p
&& !DECL_DESTRUCTOR_P (fun))
{
@@ -4686,6 +4707,21 @@
clear_no_implicit_zero (result);
pop_cx_call_context ();
+ if (observed.active ())
+ {
+ if (*jump_target)
+ observed.outcome (throws (jump_target) ? "throw" : "jump");
+ else if (*overflow_p)
+ observed.outcome ("overflow");
+ else if (*non_constant_p || result == error_mark_node)
+ observed.outcome ("failed");
+ else if (DECL_CONSTRUCTOR_P (fun))
+ observed.outcome ("constructor");
+ else if (result == void_node)
+ observed.outcome ("void");
+ else
+ observed.outcome ("returned");
+ }
return result;
}
--- a/gcc/cp/lex.cc
+++ b/gcc/cp/lex.cc
@@ -32,6 +32,7 @@
#include "gcc-rich-location.h"
#include "cp-name-hint.h"
#include "langhooks.h"
+#include "vls-eval.h"
static int interface_strcmp (const char *);
static void init_cp_traits (void);
@@ -80,6 +81,8 @@
cxx_finish (void)
{
c_common_finish ();
+ if (flag_vls_observe)
+ vls_eval::finish ();
}
ovl_op_info_t ovl_op_info[2][OVL_OP_MAX] =
@@ -350,6 +353,9 @@
EXPR_STMT, OMP_DEPOBJ
};
+ if ((flag_vls_observe || flag_vls_step) && !vls_eval::start ())
+ return false;
+
memset (&statement_code_p, 0, sizeof (statement_code_p));
for (i = 0; i < ARRAY_SIZE (stmt_codes); i++)
statement_code_p[stmt_codes[i]] = true;
--- /dev/null
+++ b/gcc/cp/vls-eval.cc
@@ -0,0 +1,390 @@
+/* Bounded, opt-in evaluator observation for the private Linux cc1plus. */
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "cp-tree.h"
+#include "vls-eval.h"
+#include <poll.h>
+#include <time.h>
+
+namespace vls_eval {
+namespace {
+
+constexpr int control_fd = 3;
+constexpr int event_fd = 4;
+constexpr unsigned max_events = 4096;
+constexpr size_t max_trace = 1024 * 1024;
+constexpr size_t max_control = 4096;
+constexpr size_t terminal_reserve = 256;
+char nonce[33];
+unsigned sequence;
+size_t trace_bytes;
+unsigned top;
+bool observing;
+bool stepping;
+
+// Each event fits in one Linux PIPE_BUF. There are no unbounded fields.
+class record
+{
+public:
+ char bytes[4096];
+ size_t size = 0;
+ bool fits = true;
+
+ explicit record (const char *kind)
+ {
+ append ("{\"v\":1,\"nonce\":\"%s\",\"seq\":%u,\"kind\":\"%s\"",
+ nonce, sequence, kind);
+ }
+
+ void append (const char *format, ...) ATTRIBUTE_PRINTF_2
+ {
+ if (!fits)
+ return;
+ va_list ap;
+ va_start (ap, format);
+ int n = vsnprintf (bytes + size, sizeof bytes - size, format, ap);
+ va_end (ap);
+ if (n < 0 || (size_t) n >= sizeof bytes - size)
+ fits = false;
+ else
+ size += n;
+ }
+
+ // v1 metadata accepts printable ASCII only. Unrepresentable names/paths
+ // are JSON null; quote and backslash are escaped. No source string is a
+ // format string, and all scanning is bounded before any formatting.
+ void text (const char *s)
+ {
+ size_t n = s ? strnlen (s, 513) : 0;
+ if (!s || n > 512)
+ return append ("null");
+ for (size_t i = 0; i < n; ++i)
+ if ((unsigned char) s[i] < 32 || (unsigned char) s[i] > 126)
+ return append ("null");
+ append ("\"");
+ for (size_t i = 0; i < n; ++i)
+ {
+ if (s[i] == '"' || s[i] == '\\')
+ append ("\\");
+ append ("%c", s[i]);
+ }
+ append ("\"");
+ }
+
+ void frame (unsigned id, unsigned parent)
+ {
+ append (",\"frame\":%u,\"parent\":", id);
+ if (parent)
+ append ("%u", parent);
+ else
+ append ("null");
+ }
+};
+
+long long
+millis ()
+{
+ struct timespec t;
+ if (clock_gettime (CLOCK_MONOTONIC, &t) != 0)
+ _exit (126);
+ return (long long) t.tv_sec * 1000 + t.tv_nsec / 1000000;
+}
+
+// Recompute the remaining interval across interrupts and partial frames.
+bool
+ready (int fd, short events, long long deadline)
+{
+ struct pollfd p = {fd, events, 0};
+ for (;;)
+ {
+ long long left = deadline - millis ();
+ if (left <= 0)
+ return false;
+ int n = poll (&p, 1, (int) left);
+ if (n > 0)
+ return (p.revents & (events | POLLHUP | POLLERR)) != 0;
+ if (n == 0 || errno != EINTR)
+ return false;
+ }
+}
+
+void
+send_record (const record &r)
+{
+ size_t done = 0;
+ long long deadline = millis () + 5000;
+ while (done < r.size)
+ {
+ ssize_t n = write (event_fd, r.bytes + done, r.size - done);
+ if (n > 0)
+ done += n;
+ else if (n == 0 || (errno != EINTR && errno != EAGAIN)
+ || !ready (event_fd, POLLOUT, deadline))
+ _exit (126); // The reader retains only its verified complete prefix.
+ }
+ trace_bytes += r.size;
+ ++sequence;
+}
+
+void ATTRIBUTE_NORETURN
+terminate_probe (const char *reason, unsigned stop = 0)
+{
+ record r ("terminal");
+ r.append (",\"reason\":\"%s\"", reason);
+ if (stop)
+ r.append (",\"stop\":%u", stop);
+ r.append ("}\n");
+ gcc_assert (r.fits && r.size <= terminal_reserve);
+ send_record (r);
+ _exit (strcmp (reason, "cancelled") == 0 ? 125 : 126);
+}
+
+unsigned
+publish (record &r)
+{
+ r.append ("}\n");
+ if (!r.fits || sequence >= max_events - 1
+ || trace_bytes + r.size > max_trace - terminal_reserve)
+ terminate_probe ("truncated");
+ unsigned issued = sequence;
+ send_record (r);
+ return issued;
+}
+
+bool
+same_pipe (const struct stat &a, const struct stat &b)
+{
+ return a.st_dev == b.st_dev && a.st_ino == b.st_ino;
+}
+
+bool
+pipe_mode (int fd, int mode, struct stat &st)
+{
+ int flags = fcntl (fd, F_GETFL);
+ return fstat (fd, &st) == 0 && S_ISFIFO (st.st_mode)
+ && flags >= 0 && (flags & O_ACCMODE) == mode;
+}
+
+bool
+set_nonblocking (int fd)
+{
+ int flags = fcntl (fd, F_GETFL);
+ return flags >= 0 && fcntl (fd, F_SETFL, flags | O_NONBLOCK) == 0;
+}
+
+bool
+valid_pipes ()
+{
+ struct stat control, events;
+ if (!pipe_mode (control_fd, O_RDONLY, control)
+ || !pipe_mode (event_fd, O_WRONLY, events) || same_pipe (control, events))
+ return false;
+ for (int fd = 0; fd <= 2; ++fd)
+ {
+ struct stat io;
+ if (fstat (fd, &io) == 0
+ && (same_pipe (io, events) || same_pipe (io, control)))
+ return false;
+ }
+ return set_nonblocking (control_fd) && set_nonblocking (event_fd);
+}
+
+bool
+valid_nonce (const char *s)
+{
+ if (!s || strnlen (s, sizeof nonce) != sizeof nonce - 1)
+ return false;
+ for (size_t i = 0; i < sizeof nonce - 1; ++i)
+ if (!(s[i] >= '0' && s[i] <= '9') && !(s[i] >= 'a' && s[i] <= 'f'))
+ return false;
+ return true;
+}
+
+void
+await_control (unsigned id, unsigned parent)
+{
+ record paused ("stopped");
+ paused.frame (id, parent);
+ unsigned stop = publish (paused);
+ char prefix[64];
+ size_t prefix_size = snprintf (prefix, sizeof prefix, "%s %u ", nonce, stop);
+ char line[max_control];
+ size_t used = 0;
+ size_t consumed = 0;
+ long long deadline = millis () + 60000;
+ for (;;)
+ {
+ if (!ready (control_fd, POLLIN, deadline))
+ terminate_probe ("controlTimeout", stop);
+ char c;
+ ssize_t n = read (control_fd, &c, 1);
+ if (n == 0)
+ terminate_probe ("controlEOF", stop);
+ if (n < 0)
+ {
+ if (errno == EINTR || errno == EAGAIN)
+ continue;
+ terminate_probe ("controlError", stop);
+ }
+ if (++consumed > 4 * max_control || used == sizeof line)
+ terminate_probe ("controlLimit", stop);
+ line[used++] = c;
+ if (c != '\n')
+ continue;
+ const size_t length = used;
+ used = 0;
+ if (length <= prefix_size || memcmp (line, prefix, prefix_size) != 0)
+ continue;
+ const char *action = nullptr;
+ const char *command = line + prefix_size;
+ size_t size = length - prefix_size;
+ if (size == 5 && memcmp (command, "step\n", 5) == 0)
+ action = "step";
+ else if (size == 9 && memcmp (command, "continue\n", 9) == 0)
+ {
+ stepping = false;
+ action = "continue";
+ }
+ else if (size == 7 && memcmp (command, "cancel\n", 7) == 0)
+ terminate_probe ("cancelled", stop);
+ else
+ continue;
+ record resumed ("resumed");
+ resumed.frame (id, parent);
+ resumed.append (",\"stop\":%u,\"action\":\"%s\"", stop, action);
+ publish (resumed);
+ return;
+ }
+}
+
+} // anonymous namespace
+
+bool
+start ()
+{
+ const char *s = getenv ("VLS_GCC_NONCE");
+ if (!flag_vls_observe || !valid_nonce (s) || !valid_pipes ()
+ || signal (SIGPIPE, SIG_IGN) == SIG_ERR)
+ {
+ error ("invalid private evaluator observer setup");
+ return false;
+ }
+ memcpy (nonce, s, sizeof nonce);
+ observing = true;
+ stepping = flag_vls_step;
+ record r ("hello");
+ r.append (",\"backend\":\"gcc-16.2.0/vls-eval-1\",\"pid\":%ld,"
+ "\"capabilities\":[\"integralReturn\",\"cooperativeStep\"],"
+ "\"kinds\":[\"hello\",\"enter\",\"body\",\"value\",\"cached\","
+ "\"stopped\",\"resumed\",\"leave\",\"terminal\",\"frontendEnd\"]",
+ (long) getpid ());
+ publish (r);
+ return true;
+}
+
+void
+finish ()
+{
+ if (observing)
+ {
+ record r ("frontendEnd");
+ publish (r);
+ observing = false;
+ }
+}
+
+void
+call::enter (tree decl)
+{
+ if (!observing || DECL_ARTIFICIAL (decl) || !DECL_NAME (decl))
+ return;
+ location_t loc = DECL_SOURCE_LOCATION (decl);
+ if (RESERVED_LOCATION_P (loc) || in_system_header_at (loc))
+ return;
+ m_parent = top;
+ top = m_frame = sequence; // hello consumed zero; each enter is unique.
+ record r ("enter");
+ r.frame (m_frame, m_parent);
+ r.append (",\"name\":");
+ r.text (IDENTIFIER_POINTER (DECL_NAME (decl)));
+ // GCC logical declaration location; consumers must map it to a snapshot
+ // before using it as an edit or a physical source identity.
+ expanded_location x = expand_location (loc);
+ if (!from_macro_expansion_at (loc) && x.file && x.line > 0 && x.column > 0)
+ {
+ r.append (",\"sourceKind\":\"logicalDeclaration\",\"source\":");
+ r.text (x.file);
+ r.append (",\"line\":%d,\"byteColumn\":%d", x.line, x.column);
+ }
+ else
+ r.append (",\"sourceKind\":\"unavailable\"");
+ publish (r);
+}
+
+void
+call::body () const
+{
+ record r ("body");
+ r.frame (m_frame, m_parent);
+ publish (r);
+}
+
+void
+call::cached () const
+{
+ record r ("cached");
+ r.frame (m_frame, m_parent);
+ publish (r);
+}
+
+void
+call::value (tree result) const
+{
+ record r ("value");
+ r.frame (m_frame, m_parent);
+ tree type = TREE_TYPE (result);
+ if (TREE_CODE (result) != INTEGER_CST || !type || !INTEGRAL_TYPE_P (type)
+ || TREE_OVERFLOW (result) || TYPE_PRECISION (type) == 0
+ || TYPE_PRECISION (type) > 64)
+ {
+ r.append (",\"value\":{\"kind\":\"unavailable\","
+ "\"reason\":\"unsupportedScalar\"}");
+ publish (r);
+ return;
+ }
+
+ unsigned precision = TYPE_PRECISION (type);
+ unsigned HOST_WIDE_INT bits = TREE_INT_CST_LOW (result);
+ // The low limb is sign-extended for narrow signed types. Copy exactly the
+ // type width, including partial high nibbles and the full 64-bit case.
+ if (precision < HOST_BITS_PER_WIDE_INT)
+ bits &= (HOST_WIDE_INT_1U << precision) - 1;
+ unsigned digits = (precision + 3) / 4;
+ char hex[17];
+ hex[digits] = 0;
+ for (unsigned i = digits; i; --i)
+ {
+ hex[i - 1] = "0123456789abcdef"[bits & 15];
+ bits >>= 4;
+ }
+ r.append (",\"value\":{\"kind\":\"integer\",\"precision\":%u,"
+ "\"signed\":%s,\"bitsHex\":\"%s\"}", precision,
+ TYPE_UNSIGNED (type) ? "false" : "true", hex);
+ publish (r);
+ if (stepping)
+ await_control (m_frame, m_parent);
+}
+
+void
+call::leave ()
+{
+ gcc_assert (top == m_frame);
+ top = m_parent;
+ record r ("leave");
+ r.frame (m_frame, m_parent);
+ r.append (",\"outcome\":\"%s\"", m_outcome);
+ publish (r);
+}
+
+} // namespace vls_eval
--- /dev/null
+++ b/gcc/cp/vls-eval.h
@@ -0,0 +1,32 @@
+/* Private live constexpr observer for GCC 16.2.0. */
+#ifndef GCC_CP_VLS_EVAL_H
+#define GCC_CP_VLS_EVAL_H
+
+namespace vls_eval {
+
+bool start ();
+void finish ();
+
+// A dynamic attempt in this invocation. Only numeric IDs and static outcome
+// tags survive a hook. GCC owns all trees, including the result declaration.
+class call
+{
+ unsigned m_frame = 0;
+ unsigned m_parent;
+ const char *m_outcome = "failed";
+ void leave ();
+public:
+ call () = default;
+ call (const call &) = delete;
+ call &operator= (const call &) = delete;
+ ~call () { if (active ()) leave (); }
+ bool active () const { return m_frame != 0; }
+ void enter (tree);
+ void body () const;
+ void cached () const;
+ void value (tree) const;
+ void outcome (const char *tag) { m_outcome = tag; }
+};
+
+} // namespace vls_eval
+#endif
@@ -0,0 +1,521 @@
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -2501,6 +2501,9 @@
C++ ObjC++ Var(flag_visibility_ms_compat)
Changes visibility to match Microsoft Visual Studio by default.
+fvls-ide
+C++ Var(flag_vls_ide) Undocumented
+
fvls-observe
C++ Var(flag_vls_observe) Undocumented
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -7059,6 +7059,8 @@
/* Whether we parsed an ellipsis (`...') just before the declarator,
to indicate this is a parameter pack. */
BOOL_BITFIELD parameter_pack_p : 1;
+ /* The private observer saw a plain identifier token at this cdk_id. */
+ BOOL_BITFIELD vls_name_token_p : 1;
/* If this declarator is parenthesized, this the open-paren. It is
UNKNOWN_LOCATION when not parenthesized. */
location_t parenthesized;
--- a/gcc/cp/lex.cc
+++ b/gcc/cp/lex.cc
@@ -353,7 +353,8 @@
EXPR_STMT, OMP_DEPOBJ
};
- if ((flag_vls_observe || flag_vls_step) && !vls_eval::start ())
+ if ((flag_vls_observe || flag_vls_step || flag_vls_ide)
+ && !vls_eval::start ())
return false;
memset (&statement_code_p, 0, sizeof (statement_code_p));
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -24,6 +24,7 @@
#include "system.h"
#include "coretypes.h"
#include "cp-tree.h"
+#include "vls-eval.h"
#include "c-family/c-common.h"
#include "timevar.h"
#include "stringpool.h"
@@ -51,6 +52,35 @@
#include "builtins.h"
#include "contracts.h"
#include "analyzer/analyzer-language.h"
+
+/* A commit of the topmost context does not commit its parents. A token
+ in a discarded outer parse must never enter the IDE candidate table. */
+static bool
+vls_committed (const cp_parser *parser)
+{
+ for (const cp_parser_context *c = parser->context; c && c->next; c = c->next)
+ if (c->status != CP_PARSER_STATUS_KIND_COMMITTED)
+ {
+ vls_eval::ide::tentative ();
+ return false;
+ }
+ return !processing_template_decl;
+}
+
+/* Use the actual lexical declarator from this parse, even if GCC merged
+ DECL into an older declaration with a different source location. */
+static void
+vls_witness_declarator (const cp_parser *parser, tree decl,
+ const cp_declarator *id, bool definition)
+{
+ if (!decl || (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != FIELD_DECL))
+ return;
+ while (id && id->kind != cdk_id)
+ id = id->declarator;
+ if (id && id->vls_name_token_p && id->u.id.unqualified_name == DECL_NAME (decl)
+ && vls_committed (parser))
+ vls_eval::ide::witness (decl, id->id_loc, definition);
+}
/* The lexer. */
@@ -1901,6 +1931,7 @@
declarator->std_attributes = NULL_TREE;
declarator->declarator = NULL;
declarator->parameter_pack_p = false;
+ declarator->vls_name_token_p = false;
declarator->id_loc = UNKNOWN_LOCATION;
declarator->init_loc = UNKNOWN_LOCATION;
@@ -8954,6 +8985,25 @@
tree stripped_expression
= tree_strip_any_location_wrapper (postfix_expression);
+ /* Keep the terminal identifier while the callee still has its
+ lexical range. The completed call has its caret at '('. */
+ tree vls_name = NULL_TREE;
+ location_t vls_token = UNKNOWN_LOCATION;
+ if (flag_vls_ide
+ && (TREE_CODE (stripped_expression) == FUNCTION_DECL
+ || TREE_CODE (stripped_expression) == OVERLOAD
+ || identifier_p (stripped_expression)))
+ {
+ cp_token *last = cp_lexer_safe_previous_token (parser->lexer);
+ if (last && last->type == CPP_NAME && !last->tree_check_p
+ && get_pure_location (last->location)
+ == get_pure_location (postfix_expression.get_location ())
+ && get_finish (last->location) == postfix_expression.get_finish ())
+ {
+ vls_name = last->u.value;
+ vls_token = last->location;
+ }
+ }
is_builtin_constant_p
= DECL_IS_BUILTIN_CONSTANT_P (stripped_expression);
if (is_builtin_constant_p)
@@ -9130,6 +9180,11 @@
disallow_virtual,
koenig_p,
complain);
+ if (vls_name && TREE_CODE (postfix_expression) == CALL_EXPR
+ && vls_committed (parser))
+ vls_eval::ide::occurrence
+ (cp_get_callee_fndecl_nofold (postfix_expression),
+ TREE_TYPE (postfix_expression), vls_name, vls_token);
}
if (close_paren_loc != UNKNOWN_LOCATION)
@@ -9528,6 +9583,8 @@
bool dependent_p;
bool pseudo_destructor_p;
tree scope = NULL_TREE;
+ tree vls_name = NULL_TREE;
+ location_t vls_token = UNKNOWN_LOCATION;
location_t start_loc = postfix_expression.get_start ();
/* If this is a `->' operator, dereference the pointer. */
@@ -9660,6 +9717,18 @@
&template_p,
/*declarator_p=*/false,
/*optional_p=*/false));
+
+ /* The first token may be a qualifier with the same spelling as the
+ field (b.x::x). Only the terminal name belongs to the field use. */
+ if (flag_vls_ide && !splice_p && !template_keyword_p)
+ {
+ cp_token *last = cp_lexer_safe_previous_token (parser->lexer);
+ if (last && last->type == CPP_NAME && !last->tree_check_p)
+ {
+ vls_name = last->u.value;
+ vls_token = last->location;
+ }
+ }
/* In general, build a SCOPE_REF if the member name is qualified.
However, if the name was not dependent and has already been
@@ -9746,6 +9815,11 @@
&& (cp_parser_non_integral_constant_expression
(parser, token_type == CPP_DEREF ? NIC_ARROW : NIC_POINT)))
postfix_expression = error_mark_node;
+
+ if (vls_name && TREE_CODE (postfix_expression) == COMPONENT_REF
+ && vls_committed (parser))
+ vls_eval::ide::occurrence (TREE_OPERAND (postfix_expression, 1),
+ TREE_TYPE (postfix_expression), vls_name, vls_token);
return postfix_expression;
}
@@ -26283,6 +26357,8 @@
&& declarator->id_loc != UNKNOWN_LOCATION
&& DECL_SOURCE_LOCATION (decl) == input_location)
DECL_SOURCE_LOCATION (decl) = declarator->id_loc;
+ if (flag_vls_ide && decl && TREE_CODE (decl) == FUNCTION_DECL)
+ vls_witness_declarator (parser, decl, declarator, false);
}
/* Perform deferred access control checks, now that we know in which
@@ -27156,6 +27232,11 @@
declarator = make_id_declarator (qualifying_scope,
unqualified_name,
sfk, token->location);
+ if (flag_vls_ide && token == declarator_id_start_token
+ && token->type == CPP_NAME && !token->tree_check_p
+ && !qualifying_scope && sfk == sfk_none
+ && token->u.value == unqualified_name)
+ declarator->vls_name_token_p = true;
declarator->std_attributes = attrs;
declarator->parameter_pack_p = pack_expansion_p;
@@ -31583,6 +31664,8 @@
decl = grokfield (declarator, &decl_specifiers,
initializer, /*init_const_expr_p=*/true,
asm_specification, attributes);
+ if (flag_vls_ide && decl && TREE_CODE (decl) == FIELD_DECL)
+ vls_witness_declarator (parser, decl, declarator, true);
if (parser->fully_implicit_function_template_p)
{
@@ -36071,6 +36154,8 @@
? TV_PARSE_INLINE : TV_PARSE_FUNC);
fn = cp_parser_function_definition_after_declarator (parser,
/*inline_p=*/false);
+ if (flag_vls_ide && !seen_error ())
+ vls_witness_declarator (parser, fn, declarator, true);
}
return fn;
--- a/gcc/cp/vls-eval.cc
+++ b/gcc/cp/vls-eval.cc
@@ -260,10 +260,19 @@
} // anonymous namespace
+// Shares the bounded v1 writer, but has a distinct handshake and vocabulary.
+#include "vls-ide.inc"
+
bool
start ()
{
const char *s = getenv ("VLS_GCC_NONCE");
+ if (flag_vls_ide && (!flag_vls_observe || flag_vls_step
+ || !ide::snapshot_setup ()))
+ {
+ error ("invalid private IDE observer setup");
+ return false;
+ }
if (!flag_vls_observe || !valid_nonce (s) || !valid_pipes ()
|| signal (SIGPIPE, SIG_IGN) == SIG_ERR)
{
@@ -274,6 +283,12 @@
observing = true;
stepping = flag_vls_step;
record r ("hello");
+ if (flag_vls_ide)
+ {
+ ide::hello (r);
+ publish (r);
+ return true;
+ }
r.append (",\"backend\":\"gcc-16.2.0/vls-eval-1\",\"pid\":%ld,"
"\"capabilities\":[\"integralReturn\",\"cooperativeStep\"],"
"\"kinds\":[\"hello\",\"enter\",\"body\",\"value\",\"cached\","
@@ -288,6 +303,8 @@
{
if (observing)
{
+ if (flag_vls_ide)
+ ide::finish ();
record r ("frontendEnd");
publish (r);
observing = false;
@@ -297,7 +314,7 @@
void
call::enter (tree decl)
{
- if (!observing || DECL_ARTIFICIAL (decl) || !DECL_NAME (decl))
+ if (!observing || flag_vls_ide || DECL_ARTIFICIAL (decl) || !DECL_NAME (decl))
return;
location_t loc = DECL_SOURCE_LOCATION (decl);
if (RESERVED_LOCATION_P (loc) || in_system_header_at (loc))
--- a/gcc/cp/vls-eval.h
+++ b/gcc/cp/vls-eval.h
@@ -6,6 +6,12 @@
bool start ();
void finish ();
+
+namespace ide {
+void tentative ();
+void witness (tree, location_t, bool);
+void occurrence (tree, tree, tree, location_t);
+}
// A dynamic attempt in this invocation. Only numeric IDs and static outcome
// tags survive a hook. GCC owns all trees, including the result declaration.
--- /dev/null
+++ b/gcc/cp/vls-ide.inc
@@ -0,0 +1,244 @@
+/* Private, read-only GCC 16.2 primary-file occurrence probe. Included in
+ vls-eval.cc to share its bounded record writer and invocation nonce. */
+namespace ide {
+namespace {
+
+constexpr unsigned capacity = 256;
+constexpr unsigned max_name = 64;
+char snapshot[65];
+bool at_capacity, withheld_tentative, withheld_origin, withheld_semantics;
+bool withheld_conflict;
+
+/* One-based physical byte columns; end is exclusive. No line map, tree,
+ parser, or spelling pointer escapes a parser hook. */
+struct span
+{
+ unsigned line, start, end;
+ bool same (const span &s) const
+ { return line == s.line && start == s.start && end == s.end; }
+ void write (record &r) const
+ {
+ r.append ("{\"line\":%u,\"startByte\":%u,\"endByte\":%u}", line, start, end);
+ }
+};
+
+struct witness_entry
+{
+ unsigned uid;
+ span where;
+ bool definition;
+ bool conflict;
+};
+struct use_entry
+{
+ unsigned uid;
+ span where;
+ char name[max_name + 1];
+ bool field;
+ bool is_double;
+ bool conflict;
+};
+witness_entry targets[capacity];
+use_entry uses[capacity];
+unsigned target_count, use_count;
+
+bool
+plain_name (tree decl)
+{
+ if (!decl || (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != FIELD_DECL)
+ || DECL_ARTIFICIAL (decl) || !DECL_NAME (decl))
+ return false;
+ if (TREE_CODE (decl) == FUNCTION_DECL
+ && (!TREE_TYPE (decl) || TREE_CODE (TREE_TYPE (decl)) != FUNCTION_TYPE
+ || (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
+ || (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))))
+ return false;
+ tree id = DECL_NAME (decl);
+ unsigned length = IDENTIFIER_LENGTH (id);
+ if (!length || length > max_name)
+ return false;
+ const char *name = IDENTIFIER_POINTER (id);
+ for (unsigned i = 0; i != length; ++i)
+ if (!(name[i] >= 'a' && name[i] <= 'z') && !(name[i] >= 'A' && name[i] <= 'Z')
+ && !(i && name[i] >= '0' && name[i] <= '9') && name[i] != '_')
+ return false;
+ return true;
+}
+
+bool
+primary_token (location_t token, unsigned length, span &out)
+{
+ location_t start = get_pure_location (get_start (token));
+ location_t last = get_pure_location (get_finish (token));
+ if (RESERVED_LOCATION_P (start) || RESERVED_LOCATION_P (last)
+ || get_pure_location (token) != start
+ || from_macro_expansion_at (start) || from_macro_expansion_at (last))
+ return false;
+ const line_map *m = linemap_lookup (line_table, start);
+ if (!m || !MAP_ORDINARY_P (m) || linemap_lookup (line_table, last) != m)
+ return false;
+ const line_map_ordinary *map = linemap_check_ordinary (m);
+ if (!MAIN_FILE_P (map) || map->sysp || !map->to_file || !main_input_filename
+ || strcmp (map->to_file, main_input_filename) != 0)
+ return false;
+ unsigned line = SOURCE_LINE (map, start);
+ unsigned column = SOURCE_COLUMN (map, start);
+ unsigned final = SOURCE_COLUMN (map, last);
+ if (!line || !column || SOURCE_LINE (map, last) != line || final < column
+ || final == UINT_MAX || final - column + 1 != length)
+ return false;
+ out = {line, column, final + 1};
+ return true;
+}
+
+witness_entry *
+find_target (unsigned uid)
+{
+ for (unsigned i = 0; i < target_count; ++i)
+ if (targets[i].uid == uid)
+ return &targets[i];
+ return nullptr;
+}
+
+} // anonymous namespace
+
+bool
+snapshot_setup ()
+{
+ const char *s = getenv ("VLS_GCC_SNAPSHOT");
+ if (!s || strnlen (s, sizeof snapshot) != sizeof snapshot - 1)
+ return false;
+ for (unsigned i = 0; i < sizeof snapshot - 1; ++i)
+ if (!(s[i] >= '0' && s[i] <= '9') && !(s[i] >= 'a' && s[i] <= 'f'))
+ return false;
+ memcpy (snapshot, s, sizeof snapshot);
+ return true;
+}
+
+void
+hello (record &r)
+{
+ r.append (",\"backend\":\"gcc-16.2.0/vls-ide-1\",\"pid\":%ld,"
+ "\"capabilities\":[\"primaryFileOccurrences\"],"
+ "\"kinds\":[\"hello\",\"occurrence\",\"ideCoverage\","
+ "\"terminal\",\"frontendEnd\"],\"snapshot\":\"%s\"",
+ (long) getpid (), snapshot);
+}
+
+void
+tentative ()
+{
+ withheld_tentative = true;
+}
+
+void
+witness (tree decl, location_t token, bool definition)
+{
+ if (at_capacity || !plain_name (decl))
+ return;
+ span where;
+ if (!primary_token (token, IDENTIFIER_LENGTH (DECL_NAME (decl)), where))
+ {
+ withheld_origin = true;
+ return;
+ }
+ unsigned uid = DECL_UID (decl);
+ if (witness_entry *old = find_target (uid))
+ {
+ if (definition && !old->definition)
+ *old = {uid, where, true, false};
+ else if (definition && !old->where.same (where))
+ old->conflict = withheld_conflict = true;
+ return;
+ }
+ if (target_count == capacity)
+ at_capacity = true;
+ else
+ targets[target_count++] = {uid, where, definition, false};
+}
+
+void
+occurrence (tree decl, tree type, tree token_name, location_t token)
+{
+ if (at_capacity)
+ return;
+ if (!plain_name (decl) || DECL_NAME (decl) != token_name
+ || (type != integer_type_node && type != double_type_node))
+ {
+ withheld_semantics = true;
+ return;
+ }
+ span where;
+ unsigned length = IDENTIFIER_LENGTH (token_name);
+ if (!primary_token (token, length, where))
+ {
+ withheld_origin = true;
+ return;
+ }
+ unsigned uid = DECL_UID (decl);
+ bool field = TREE_CODE (decl) == FIELD_DECL;
+ bool is_double = type == double_type_node;
+ for (unsigned i = 0; i < use_count; ++i)
+ if (uses[i].where.same (where))
+ {
+ if (uses[i].uid != uid || uses[i].field != field || uses[i].is_double != is_double)
+ uses[i].conflict = withheld_conflict = true;
+ return;
+ }
+ if (use_count == capacity)
+ {
+ at_capacity = true;
+ return;
+ }
+ use_entry &u = uses[use_count++];
+ u = {uid, where, {}, field, is_double, false};
+ memcpy (u.name, IDENTIFIER_POINTER (token_name), length);
+}
+
+void
+finish ()
+{
+ /* A same-name #line can give two distinct tokens identical logical
+ filename/line/column, even if their bytes are identical. Suppress the
+ entire set before publishing its first member. Includes can also set
+ this flag. The IDE harness supplies one include-free primary snapshot. */
+ const char *reason = nullptr;
+ if (line_table->seen_line_directive)
+ reason = "lineDirective";
+ else if (seen_error ())
+ reason = "compileErrors";
+ else if (at_capacity)
+ reason = "capacity";
+ if (!reason)
+ for (unsigned i = 0; i < use_count; ++i)
+ {
+ const use_entry &u = uses[i];
+ if (u.conflict)
+ continue;
+ const witness_entry *w = find_target (u.uid);
+ const bool known = w && !w->conflict;
+ record r ("occurrence");
+ r.append (",\"sourceKind\":\"primaryFileToken\",\"role\":\"%s\","
+ "\"declUid\":%u,\"name\":", u.field ? "field" : "call", u.uid);
+ r.text (u.name);
+ r.append (",\"resultType\":\"%s\",\"use\":", u.is_double ? "double" : "int");
+ u.where.write (r);
+ const char *kind = known ? (w->definition ? "definition" : "declaration") : "unavailable";
+ r.append (",\"targetKind\":\"%s\",\"target\":", kind);
+ if (known)
+ w->where.write (r);
+ else
+ r.append ("null");
+ publish (r);
+ }
+ record coverage ("ideCoverage");
+ coverage.append (",\"source\":");
+ coverage.text (main_input_filename);
+ coverage.append (",\"state\":\"%s\",\"reason\":", reason ? "unavailable" : "partial");
+ coverage.text (reason);
+ coverage.append (",\"tentative\":%s,\"unmapped\":%s,\"unsupported\":%s,\"conflict\":%s",
+ withheld_tentative ? "true" : "false", withheld_origin ? "true" : "false",
+ withheld_semantics ? "true" : "false", withheld_conflict ? "true" : "false");
+ publish (coverage);
+}
+} // namespace ide
@@ -0,0 +1,98 @@
--- /dev/null
+++ b/libcpp/include/vls-primary-origin.h
@@ -0,0 +1,9 @@
+/* Source origin for the private VLS GCC frontend. */
+#ifndef LIBCPP_VLS_PRIMARY_ORIGIN_H
+#define LIBCPP_VLS_PRIMARY_ORIGIN_H
+
+struct cpp_reader;
+/* Bytes skipped on the first physical line, or -1 for an unverified input. */
+extern int cpp_vls_primary_utf8_prefix (const cpp_reader *);
+
+#endif
--- a/libcpp/files.cc
+++ b/libcpp/files.cc
@@ -23,6 +23,7 @@
#include "config.h"
#include "system.h"
#include "cpplib.h"
+#include "vls-primary-origin.h"
#include "internal.h"
#include "mkdeps.h"
#include "obstack.h"
@@ -102,6 +103,10 @@
/* Number of times the file has been stacked for preprocessing. */
unsigned short stack_count;
+
+ /* For the VLS observer, 0 means unknown. Otherwise this records one
+ plus the byte prefix consumed on line one of the actual UTF-8 input. */
+ unsigned char vls_primary_utf8_prefix;
/* If opened with #import or contains #pragma once. */
bool once_only : 1;
@@ -796,12 +801,19 @@
cpp_error_at (pfile, CPP_DL_WARNING, loc,
"%s is shorter than expected", file->path);
+ const bool record_origin = (pfile && file == pfile->main_file && input_charset
+ && !strcasecmp (input_charset, "UTF-8"));
+ const int prefix = record_origin ? cpp_check_utf8_bom ((const char *) buf, total) : 0;
file->buffer = _cpp_convert_input (pfile,
input_charset,
buf, size + pad, total,
&file->buffer_start,
&file->st.st_size);
file->buffer_valid = file->buffer;
+ if (record_origin && file->buffer_valid
+ && file->buffer - file->buffer_start == prefix
+ && file->st.st_size == (off_t) (total - prefix))
+ file->vls_primary_utf8_prefix = 1 + prefix;
return file->buffer_valid;
}
@@ -2360,6 +2372,16 @@
}
}
+/* The conversion result is retained after the preprocessor releases its
+ input buffer. Asking for an origin never reopens a mutable pathname. */
+int
+cpp_vls_primary_utf8_prefix (const cpp_reader *pfile)
+{
+ if (!pfile || !pfile->main_file)
+ return -1;
+ return (int) pfile->main_file->vls_primary_utf8_prefix - 1;
+}
+
/* Return the file name associated with FILE. */
const char *
_cpp_get_file_name (_cpp_file *file)
--- a/gcc/cp/vls-eval.cc
+++ b/gcc/cp/vls-eval.cc
@@ -4,6 +4,8 @@
#include "coretypes.h"
#include "cp-tree.h"
#include "vls-eval.h"
+#include "c-family/c-pragma.h"
+#include "vls-primary-origin.h"
#include <poll.h>
#include <time.h>
--- a/gcc/cp/vls-ide.inc
+++ b/gcc/cp/vls-ide.inc
@@ -87,7 +87,13 @@
if (!line || !column || SOURCE_LINE (map, last) != line || final < column
|| final == UINT_MAX || final - column + 1 != length)
return false;
- out = {line, column, final + 1};
+ const int skipped = cpp_vls_primary_utf8_prefix (parse_in);
+ if (skipped < 0)
+ return false;
+ const unsigned prefix = line == 1 ? (unsigned) skipped : 0;
+ if (prefix > UINT_MAX - (final + 1))
+ return false;
+ out = {line, column + prefix, final + 1 + prefix};
return true;
}
@@ -0,0 +1,103 @@
--- a/gcc/cp/reflect.cc
+++ b/gcc/cp/reflect.cc
@@ -31,6 +31,7 @@
#include "c-family/c-pragma.h" // for parse_in
#include "gimplify.h" // for unshare_expr
#include "metafns.h"
+#include "vls-eval.h"
static tree eval_is_function_type (tree);
static tree eval_is_object_type (location_t, const constexpr_ctx *, tree,
@@ -8770,6 +8771,7 @@
return error_mark_node;
refl = REFLECT_EXPR_HANDLE (refl);
+ vls_eval::splice (loc, refl);
/* Function templates are wrapped in OVERLOAD from name lookup
and a lot of places assume that. Furthermore, if reflection comes
from ^^fntmpl, it is wrapped with OVERLOAD already, only when
--- a/gcc/cp/vls-eval.cc
+++ b/gcc/cp/vls-eval.cc
@@ -294,7 +294,8 @@
r.append (",\"backend\":\"gcc-16.2.0/vls-eval-1\",\"pid\":%ld,"
"\"capabilities\":[\"integralReturn\",\"cooperativeStep\"],"
"\"kinds\":[\"hello\",\"enter\",\"body\",\"value\",\"cached\","
- "\"stopped\",\"resumed\",\"leave\",\"terminal\",\"frontendEnd\"]",
+ "\"stopped\",\"resumed\",\"leave\",\"terminal\",\"frontendEnd\","
+ "\"splice\"]",
(long) getpid ());
publish (r);
return true;
@@ -406,4 +407,59 @@
publish (r);
}
+// One splice record carries both ends of the first provenance link: the
+// editable splice site and the reflected entity it designates. Identity is
+// composed by the consumer from the target kind, name and location; the
+// compiler never invents a source spelling.
+void
+splice (location_t loc, tree entity)
+{
+ if (!observing || flag_vls_ide || RESERVED_LOCATION_P (loc)
+ || in_system_header_at (loc) || from_macro_expansion_at (loc))
+ return;
+ expanded_location x = expand_location (loc);
+ if (!x.file || x.line <= 0 || x.column <= 0)
+ return;
+ record r ("splice");
+ r.append (",\"source\":");
+ r.text (x.file);
+ r.append (",\"line\":%d,\"byteColumn\":%d", x.line, x.column);
+ const char *kind = "value";
+ tree name = NULL_TREE;
+ location_t target_loc = UNKNOWN_LOCATION;
+ if (entity && DECL_P (entity))
+ {
+ kind = "declaration";
+ name = DECL_NAME (entity);
+ target_loc = DECL_SOURCE_LOCATION (entity);
+ }
+ else if (entity && TYPE_P (entity))
+ {
+ kind = "type";
+ name = TYPE_IDENTIFIER (entity);
+ if (!name && TYPE_NAME (entity) && DECL_P (TYPE_NAME (entity)))
+ {
+ name = DECL_NAME (TYPE_NAME (entity));
+ target_loc = DECL_SOURCE_LOCATION (TYPE_NAME (entity));
+ }
+ }
+ r.append (",\"targetKind\":\"%s\",\"targetName\":", kind);
+ r.text (name ? IDENTIFIER_POINTER (name) : nullptr);
+ if (!RESERVED_LOCATION_P (target_loc))
+ {
+ expanded_location y = expand_location (target_loc);
+ if (y.file && y.line > 0 && y.column > 0)
+ {
+ r.append (",\"targetSource\":");
+ r.text (y.file);
+ r.append (",\"targetLine\":%d,\"targetByteColumn\":%d", y.line, y.column);
+ publish (r);
+ return;
+ }
+ }
+ r.append (",\"targetSource\":null,\"targetLine\":null,"
+ "\"targetByteColumn\":null");
+ publish (r);
+}
+
} // namespace vls_eval
--- a/gcc/cp/vls-eval.h
+++ b/gcc/cp/vls-eval.h
@@ -7,6 +7,10 @@
bool start ();
void finish ();
+// Records one evaluated splice: the splice site and the entity it names.
+// Only the observe invocation and only non-system, non-macro locations.
+void splice (location_t, tree);
+
namespace ide {
void tentative ();
void witness (tree, location_t, bool);
@@ -0,0 +1,3 @@
# GCC 16.2.0 configure options recorded from the verified private build. --disable-fixincludes
# @PREFIX@ is the private install prefix selected by tools/prepare-private-gcc. --disable-fixincludes
--with-native-system-header-dir=/nix/store/2f69qaci676cq5kr8svry3gbf6i6iqzi-glibc-2.44-57-dev/include --prefix=@PREFIX@ --disable-bootstrap --disable-multilib --enable-checking=release --disable-nls --disable-libsanitizer --disable-libgomp --disable-libquadmath --disable-libssp --disable-libvtv --without-isl --with-gmp-include=/nix/store/fs234b3nv0bv3jij5nf6jkpj5n575g8i-gmp-with-cxx-6.3.0-dev/include --with-gmp-lib=/nix/store/x4n20j5hd4y4f6a0lhqikyzypqf4lk7q-gmp-6.3.0/lib --with-mpfr-include=/nix/store/sm1kd9fm3i78kml51vylmnd084gxa274-mpfr-4.2.2-dev/include --with-mpfr-lib=/nix/store/qfhbm2s6dzsx3f296kkbmvjfzrpmlylf-mpfr-4.2.2/lib --with-mpc=/nix/store/bcxjqlilnadv2viv17zk47lz3900dc75-libmpc-1.4.1 --enable-languages=c,c++,lto --disable-fixincludes