[clang] [LifetimeSafety] Trace assignment history for use-after-scope errors (PR #188467)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 26 04:43:17 PDT 2026
https://github.com/usx95 commented:
Great work on implementing flow history tracing! This would significantly improves the diagnostics. A few suggestions for enhancement:
1. **Simplify source highlighting and improve wording**: Rather than highlighting both sides of each step in the flow chain, we should only highlight the destination (left-hand side). Additionally, make the diagnostic text configurable based on what we know: use `"variable 'x'"` when we have a named variable, `"function call result"` for call expressions, `"temporary object"` for temporaries, etc. (Apologies for not mentioning this in the original issue!)
For example, given:
The desired diagnostic output would be:
For chained member/arrow operations, we should highlight each step in the chain (with distinct ranges):
Would produce:
Notice how:
- We only highlight the destination (`a`, `b`, `e`, function call, `s`, `x`) in each step of the flow
- Each note traces back to the original source (`tgt` or the temporary)
- For chained operations, we highlight progressively longer prefixes showing the flow through the chain in a single statement.
- Function calls and member accesses are described appropriately when they appear in the flow
- All involved entities use distinct source ranges (avoiding duplicate reports for the same range)
2. **Extend to other error types**: This tracing mechanism would be valuable for:
- Use-after-return errors
- Lifetime annotation suggestions
- Dangling field/global warnings
Consider refactoring the tracing logic to be reusable across these different diagnostic paths.
The implementation looks solid overall. Will take a deeper look at the tracking logic after the functional changes.
Feel free to ask follow up questions.
https://github.com/llvm/llvm-project/pull/188467
More information about the cfe-commits
mailing list