-
-
Couldn't load subscription status.
- Fork 1.3k
fix(es/compiler): Fix ARM64 segfault in nullish coalescing variable hoisting #11181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…oisting This fixes a critical segfault issue on ARM64 platforms (AWS Graviton, macOS Apple Silicon) that was introduced in the nullish coalescing merge (#11157). **Root Cause:** The `visit_mut_module_items` and `visit_mut_stmts` functions were unconditionally restoring saved variable vectors at the end, even after those vectors had been properly moved and emptied during the nullish coalescing processing loop. This created a use-after-free scenario where: 1. Saved vectors were taken (emptied) at the start 2. New items were added to the instance vectors during processing 3. The instance vectors were properly consumed via `.take()` 4. The saved (empty) vectors were restored, discarding the properly processed state On ARM64 architectures with stricter memory alignment requirements and different register calling conventions, this pattern exposed memory safety issues that manifested as segmentation faults. **Solution:** Move the variable restoration logic into each branch of the conditional, ensuring vectors are only restored in the appropriate control flow path and not after they've been properly consumed during nullish coalescing hoisting. Fixes #11129 Fixes #11176 Fixes #11177 Fixes #11178 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
|
|
1 similar comment
|
|
|
🤖 This pull request has been linked to DevBird Task #955 View the task details and manage the automated development workflow in DevBird. Learn more about DevBird here or the announcement blog post here. |
📋 DevBird Task PromptFix segfault issue described in #11129 This comment was automatically added by DevBird. You can disable this feature in DevBird Settings. |
|
Claude finished @DeLino[bot]'s task —— View job Code Review for ARM64 Segfault FixReviewing the pull request that fixes ARM64 segfault in nullish coalescing variable hoisting. Todo List:
Review SummaryThis PR correctly addresses a critical ARM64 segfault by fixing the control flow in variable restoration logic for nullish coalescing and logical assignment operators. ✅ Correctness and QualityRoot Cause Analysis is Accurate: The PR correctly identifies that the issue was caused by unconditional restoration of saved variable vectors at the end of functions, even after those vectors had been properly consumed during processing. Fix is Sound: The solution properly moves variable restoration into each conditional branch, ensuring vectors are only restored in the appropriate context:
Code Quality: The fix maintains good separation of concerns and follows the existing code patterns. Comments clearly explain the restoration logic. ✅ Memory SafetyAddresses Use-After-Free: The fix prevents the dangerous pattern where:
ARM64 Specific Considerations: The fix addresses ARM64's stricter memory alignment requirements and different ABI that made this pattern more likely to segfault. ✅ Performance ConsiderationsNo Performance Regression: The changes only move existing restoration logic into appropriate branches - no additional allocations or operations. Efficient Vector Operations: Continues to use ✅ SecurityNo Security Concerns: This is a memory safety fix that doesn't introduce any security vulnerabilities. The changes are localized to variable restoration logic.
|
CodSpeed Performance ReportMerging #11181 will not alter performanceComparing Summary
|
Summary
This PR fixes a critical segfault issue on ARM64 platforms (AWS Graviton, macOS Apple Silicon, GitHub Actions ARM runners) that was introduced in #11157 when nullish coalescing was merged into the Compiler.
Root Cause Analysis
The
visit_mut_module_itemsandvisit_mut_stmtsfunctions had a control flow issue where saved variable vectors were unconditionally restored at the end of the function, even after those vectors had been properly moved and emptied during the nullish coalescing processing loop.The problematic pattern was:
saved_vars = self.vars.take()self.varswith new declarationsself.varsvia.take()during hoistingOn ARM64 architectures with:
This pattern exposed memory safety issues that manifested as segmentation faults (exit code 139).
Solution
Move the variable restoration logic into each branch of the conditional statement, ensuring vectors are only restored in the appropriate control flow path and not after they've been properly consumed during nullish coalescing hoisting.
Changes
visit_mut_module_items()incrates/swc_ecma_compiler/src/lib.rs:607-709visit_mut_stmts()incrates/swc_ecma_compiler/src/lib.rs:727-825Test Plan
??)??=)Related Issues
Fixes #11129
Fixes #11176
Fixes #11177
Fixes #11178
🤖 Generated with Claude Code