Repository navigation
fix(native): keep undecoded swift-demangle echoes out of demangled status - #4287
viniciusdsandrade wants to merge 3 commits into
Conversation
…atus swift-demangle removes one underscore from a name starting with __ and prefixes $ to an argument starting with S, s or e before demangling. A name it cannot decode is printed in that adjusted spelling, so the parser saw output that differed from the input and reported it as demangled: __T0Bogus became _T0Bogus, and ___stack_chk_fail or strlen were reported as demangled names. Treat that adjusted spelling as an undecoded echo. Undecoded results keep the caller's input as output, and invalid is decided on the name the demangler examined, so __T0Bogus is invalid and non-Swift names stay unchanged. Fixes morluto#4215 Signed-off-by: Vinícius DS Andrade <[email protected]>
Assert that the underscore-stripped and $-prefixed spellings swift-demangle prints for names it cannot decode keep invalid or unchanged status with the caller's input as output, while a linkage underscore or a missing $ on a decodable name still demangles. Signed-off-by: Vinícius DS Andrade <[email protected]>
Send __T0Bogus, ___stack_chk_fail and strlen through the production demangle_swift tool with the real swift-demangle and require invalid, unchanged and unchanged with the caller's input as output. Signed-off-by: Vinícius DS Andrade <[email protected]>
Recognize known undecoded producer spellings without treating them as successful demangles. Preserve actual producer output and derive symbol types from the domain contract instead of duplicating its validation schema. Compare retained output with the real demangler through MCP, while preserving CLI malformed-input and line-ending coverage. Refs: #4215, #4287 Co-authored-by: Vinícius DS Andrade <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The PR appears safe to merge; no actionable defects were found. SummaryFixes
Reviews (1) · Last reviewed commit: "test(native): demangle undecoded linkage..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 580c38e1c1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| ? "invalid" | ||
| : "unchanged" | ||
| : "demangled", | ||
| output: decoded ? value : input, |
There was a problem hiding this comment.
Keep the actual undecoded spelling in output
When an undecoded argument is rewritten by the producer (the added cases pass __T0Bogus and receive _T0Bogus, or strlen and $strlen), this ternary replaces value with input. #demangle returns only this parsed result plus invocation metadata, so the actual stdout spelling is no longer present anywhere in the Evidence; callers therefore see an output value the command did not emit, and toolchain-specific behavior cannot be audited. Keep value as output and use decoded only for status classification.
AGENTS.md reference: AGENTS.md:L13-L13
Useful? React with 👍 / 👎.
| : "unchanged" | ||
| : "demangled", | ||
| output: decoded ? value : input, | ||
| status: decoded |
There was a problem hiding this comment.
Derive parsed symbols from the domain contract
This bug fix changes the adapter's interpretation while continuing to validate and export it through resultSchema, an independent copy of the symbol item in demangleSwiftSchema (src/domain/native/nativeInspection.ts:183-190). Because no type relationship connects them, a domain contract change can leave this parser compiling and publishing a different status/output shape until a runtime parse fails; derive DemangledSymbol and its validation from the canonical domain contract and remove the local schema as part of this producing-boundary fix.
AGENTS.md reference: AGENTS.md:L27-L27
Useful? React with 👍 / 👎.
|
Conflict check from the CI & conflict-fix track: this branch conflicts with main, and main's 808339f ("fix(native): distinguish undecoded Swift spelling adjustments") references #4287 and is co-authored from this PR, so the change has already landed there. Resolving the conflict would reduce this branch to main's version, so I left it untouched. A maintainer may want to close this as superseded. |
|
Conflict check from the CI/conflict track. I did not push anything. #4215 was closed by
So the bug in #4215 is fixed on The |
|
Closing as superseded by 808339f on main. |
Summary
Fixes #4215
Keep
demangle_swiftfrom reporting a name asdemangledwhenswift-demangleonly printed its adjusted spelling of a name it could not decode.__T0Bogusnow reportsinvalid, and non-Swift names such as___stack_chk_failandstrlenreportunchanged. Undecoded results keep the caller's input asoutput.Problem and expected behavior
parseDemangledSymbolstreated any output line that differed from its input as a successful decode.swift-demangleadjusts some names before demangling and prints that adjusted spelling when demangling fails (tools/swift-demangle/swift-demangle.cppin swiftlang/swift):__loses one underscore (hadLeadingUnderscore,name.substr(1)), so__T0Bogusprints_T0Bogusand___stack_chk_failprints__stack_chk_fail;S,soregets a$prefix (correctedName), sostrlenprints$strlen.REA passes symbols as arguments (
--compact -- ...symbols), so each of these becamedemangledwith an output that is not a demangling. The issue reproduced__T0Bogus -> _T0Bogus, demangledwith Xcode 27. The___stack_chk_failandstrlencases follow from the same source and are not separately reproduced here.Expected behavior: an undecoded name is
invalidwhen it is a Swift mangling andunchangedotherwise, and itsoutputis the caller's input.Change and scope
src/native/parsers/demangle.ts: compare the output with both the input and the spellingswift-demangleprints for an undecoded name. Decideinvalidon the name the demangler examined after removing the linkage underscore, using the existingisSwiftMangledSymbolName. Names that genuinely decode, including__T04main3FooVands4main3FooV, staydemangled.swift-demangleargument handling, such as the tool skipping a lone_argument.Contract and boundary impact
swift-demangleoutput interpretation insrc/native/parsers/demangle.ts.statusnow matches the documented demangled, unchanged or invalid meaning for these inputs.swift-demangle.outputfor undecoded names is the caller's input; the printed spelling is a fixed transform of that input.docs/public/product-catalog.json), package, or installation impact: none.Expected effects:
Evidence and regression coverage
src/native/parsers/demangle.test.ts: the underscore-stripped and$-prefixed spellings for__T0Bogus,__$sBogus,___stack_chk_fail,strlen,Symbolandentrykeepinvalidorunchangedwith the input as output;__T04main3FooVands4main3FooVstill demangle.tests/boundary/mcp/nativeDemangleMcp.test.ts(darwin):__T0Bogus,___stack_chk_failandstrlenthrough the productiondemangle_swifttool returninvalid,unchangedandunchangedwith the input as output.__T0Bogus -> _T0Bogus, demangled. The other cases are derived from the citedswift-demanglesource.{"input":"__T0Bogus","output":"__T0Bogus","status":"invalid"}instead of{"input":"__T0Bogus","output":"_T0Bogus","status":"demangled"}.swift-demanglewas not run locally; the darwin MCP test runs it in CI where available.For evidence-bearing changes:
Validation performed
Compatibility, safety, and release
swift-demangleis invoked.Before merge
type(scope): outcome.