V3 nested-map append duplicates previous array element on Clang MemorySanitizer (staged owned RHS)

Open
#32,715 8 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
12/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c
Domain
compilers

Research direction

Start at vlib/v/transform/map.v, function lower_map_index_append_with_info_and_prelude around lines 3510-3615, then the failing assertion at vlib/v/tests/nested_map_mutation_missing_outer_key_test.v:510. Rebuild with ./v self and reproduce the minimal case appending [3,4] then [5,6] to a nested map, comparing literal, call and borrowed RHS and inspecting generated C map_append_rhs and array__push versus array__push_many. Done means the second element is [5,6] under Clang MSan and GCC/Clang without it, with a regression test added.

Written by the indexing model from the issue text.

Description

Executed master CI failure (not a queued/skipped result)

  • Failing master d8083d40873efc7689abdb15f4ca21b4f5d59f4a; completed 2026-11-21 20:02 UTC.
  • Clang MemorySanitizer job 136897142315, after 4,321 passing vlib tests / 762 skipped, one actual failing V test.
  • Original invocation from job: ./v -cc clang -gc none -d use_bundled_libgc -cflags -fno-omit-frame-pointer -cflags -maes -cflags -mpclmul -cflags -fsanitize=memory -silent vlib/v/tests/nested_map_mutation_missing_outer_key_test.v.
  • test_nested_append_releases_staged_owned_rhs, at vlib/v/tests/nested_map_mutation_missing_outer_key_test.v:510, expects [[3, 4], [5, 6]], actually gets [[3, 4], [3, 4]]. This is a logical value error, not an MSan use-of-uninitialized-memory diagnostic, a GitHub job timeout, or an intentionally failing test.

Source comparison and constrained hypothesis

The original test file has the same blob SHA 9ce67b59932adc686bd1571ffd7655c09987b5b8 on the failing revision and current master inspected 9621aa02fd7d7788700846e93242d08bd70a8aea. The fixture first appends make_nested_append_row() and then a literal [5, 6] to map[string]map[string][][]int; the second append repeats the first element.

Inspect vlib/v/transform/map.v lower_map_index_append_with_info_and_prelude (about lines 3510–3615): nested map RHS is staged to map_append_rhs before re-acquiring inner-map storage. The helper marks array literals as owned, creates append_rhs = t.make_ident(staged_rhs_name), annotates << as scalar vs push-many, then clones/releases staged RHS depending on mode. The explicit set_node_typ applied only later to cleanup identifiers is worth checking against annotate_left_shift's type selection; this is an unverified hypothesis, not a proven bug. The value could also be corrupted by array-copy ownership or storage aliasing. stable_map_lvalue_for_reuse and map_index_inner_map_slot re-acquire the stored inner map after staging; inspect that sequence too.

Minimal native discriminator and safe fix requirements

  1. Rebuild V on current master: ./v self. Run the original test with the exact Clang MSan command, MSAN_OPTIONS=track_origins=2, and -keepc -cg (or V's equivalent generated-C preservation). Also test GCC and Clang without MSan.
  2. Reduce to mut rows := map[string]map[string][][]int{}; rows['a']['b'] << [3,4]; rows['a']['b'] << [5,6]. Contrast literal RHS with fn mk() []int { return [5,6] } and x := [5,6]; rows['a']['b'] << x. Check generated C map_append_rhs type/value, emitted array__push versus array__push_many, copy/cloning, release order, and resulting pointer/length/capacity.
  3. Fix the proven storage/type ordering error minimally in V3 transform/Cgen. Add regression for two different scalar array elements in a nested map, literal versus call versus borrowed RHS, verify no aliasing/use-after-free under Clang MSan and GCC/Clang ASan, preserving current assertions.
  4. After compiler changes run ./v self, ./v fmt for modified files, compiler-errors, focused transform/map and original vlib test on the patched revision. No skip, assertion weakening or suppressions.

Status: unresolved / investigating, currently applicable as fixture unchanged; original native patched execution not yet available. Related older map families are not proof of this specific source corruption.

[!NOTE]
You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Dominant language
V
Stars
38.1k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
682

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vlang/v

All issues in vlang/v

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.