Skip to content

Commit 6b2cd08

Browse files
committed
fix(pipeline): guard env-access CONFIGURES and throws sources against directory-module collisions
Follow-up to DeusData#787/DeusData#828, disclosed during DeusData#828's review: the same clobber class also affects two call sites DeusData#828 deliberately left out of scope. create_env_configures_for_file (pass_definitions.c) and resolve_file_throws (pass_parallel.c) both resolved their edge source via a direct cbm_gbuf_find_by_qn(enclosing_func_qn) lookup with no guard against the lookup landing on the shared Folder/Project node for directory-module languages (Java/Go) -- the exact DeusData#787 root cause, just unguarded at two more sites. A class-level construct (no enclosing function) has its enclosing_func_qn fall back to the MODULE QN, which for a directory-based module collides with the package's Folder node, conflating every same-package file's CONFIGURES/THROWS edges onto one arbitrary source. - create_env_configures_for_file: added the same cbm_pipeline_node_is_dir_container guard already used by the three DeusData#828-fixed finders, falling back to the per-file File node on a directory-container hit. - resolve_file_throws: was missing the `rel` parameter its sibling resolve_file_calls/usages/rw already carry, so it inlined a raw lookup instead of calling the shared, already-guarded find_source_node. Added `rel` and switched to find_source_node, matching its siblings exactly. Regression guard: tests/repro/repro_issue842.c, reproduce-first per the issue's request for "an DeusData#828-style multi-order red fixture": - CONFIGURES reproduces on a small 5-file sequential fixture (Go, since Java's System.getenv detection is separately broken -- extract_env_key_from_call reads a "function" field Java's method_invocation node doesn't have; noted in the test, out of scope here). - THROWS only reproduces past MIN_FILES_FOR_PARALLEL=50 (the worker-merge path) -- confirmed empirically that the small sequential fixture already attributes correctly even on unfixed HEAD, mirroring DeusData#787's own two-faced (sequential/parallel) bug. Padded with 60 filler classes, following repro_issue787.c's build_parallel_fixture precedent. RED on unfixed HEAD (both tests): 0 passed, 2 failed. GREEN with this fix: 2 passed, 0 failed. Full scripts/test.sh (5958 cases) passes clean with this change; scripts/lint.sh's two pre-existing failures (pass_lsp_cross.h parameter-name mismatch, extract_defs.c cppcheck AST parse) are unrelated and present identically on unfixed main. Fixes DeusData#842 Signed-off-by: Dhruvy0804 <dhruvgarg553@gmail.com>
1 parent 3747344 commit 6b2cd08

5 files changed

Lines changed: 419 additions & 4 deletions

File tree

‎Makefile.cbm‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ TEST_REPRO_SRCS = \
446446
tests/repro/repro_issue363.c \
447447
tests/repro/repro_issue581.c \
448448
tests/repro/repro_issue787.c \
449+
tests/repro/repro_issue842.c \
449450
tests/repro/repro_invariant_calls.c \
450451
tests/repro/repro_invariant_graph.c \
451452
tests/repro/repro_invariant_breadth.c \

‎src/pipeline/pass_definitions.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,12 @@ static int create_env_configures_for_file(cbm_pipeline_ctx_t *ctx, const CBMFile
425425
const cbm_gbuf_node_t *src = NULL;
426426
if (ea->enclosing_func_qn && ea->enclosing_func_qn[0]) {
427427
src = cbm_gbuf_find_by_qn(ctx->gbuf, ea->enclosing_func_qn);
428+
/* A class-level env access in a directory-module language carries
429+
* the DIRECTORY module QN, which hits the shared Folder/Project
430+
* node — attribute to this file's File node instead (#787, #842). */
431+
if (cbm_pipeline_node_is_dir_container(src)) {
432+
src = NULL;
433+
}
428434
}
429435
if (!src) {
430436
if (!file_qn) {

‎src/pipeline/pass_parallel.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,14 +2392,18 @@ static void resolve_file_usages(resolve_ctx_t *rc, resolve_worker_state_t *ws,
23922392

23932393
/* Resolve throws/raises for one file. */
23942394
static void resolve_file_throws(resolve_ctx_t *rc, resolve_worker_state_t *ws,
2395-
CBMFileResult *result, const char *module_qn, const char **imp_keys,
2396-
const char **imp_vals, int imp_count) {
2395+
CBMFileResult *result, const char *rel, const char *module_qn,
2396+
const char **imp_keys, const char **imp_vals, int imp_count) {
23972397
for (int t = 0; t < result->throws.count; t++) {
23982398
CBMThrow *thr = &result->throws.items[t];
23992399
if (!thr->exception_name || !thr->enclosing_func_qn) {
24002400
continue;
24012401
}
2402-
const cbm_gbuf_node_t *src = cbm_gbuf_find_by_qn(rc->main_gbuf, thr->enclosing_func_qn);
2402+
/* find_source_node falls back to the per-file File node when the
2403+
* lookup lands on a shared Folder/Project node (#787, #842) — same
2404+
* guard resolve_file_calls/usages/rw already use. */
2405+
const cbm_gbuf_node_t *src =
2406+
find_source_node(rc->main_gbuf, rc->project_name, rel, thr->enclosing_func_qn);
24032407
if (!src) {
24042408
continue;
24052409
}
@@ -2808,7 +2812,7 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
28082812

28092813
/* ── THROWS / RAISES ───────────────────────────────────── */
28102814
_ph_t0 = extract_now_ns();
2811-
resolve_file_throws(rc, ws, result, module_qn, imp_keys, imp_vals, imp_count);
2815+
resolve_file_throws(rc, ws, result, rel, module_qn, imp_keys, imp_vals, imp_count);
28122816
atomic_fetch_add_explicit(&rc->time_ns_throws, extract_now_ns() - _ph_t0,
28132817
memory_order_relaxed);
28142818

0 commit comments

Comments
 (0)