Files
Language-Server/compiler-patches/gcc-16.2.0/0003-physical-utf8-origin.patch
T
faumaray da8003f6d4 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.
2026-12-05 14:06:50 +03:00

99 lines
3.0 KiB
Diff

--- /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;
}