Suppress compiler warnings with __builtin_unreachable#217
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a new UNREACHABLE() macro to standardize handling of unreachable code paths throughout the codebase, replacing all instances of assert(false) with this more expressive and compiler-optimizable alternative. The macro leverages __builtin_unreachable() when available to provide compiler hints for optimization.
- Introduced
UNREACHABLE()macro incommon.hthat uses__builtin_unreachable()when supported - Replaced all
assert(false)calls withUNREACHABLE()across the entire codebase - Updated copyright years to 2025 in modified files
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| common.h | Defines the new UNREACHABLE() macro with conditional compiler intrinsic support |
| arith.c | Replaces assert(false) with UNREACHABLE() in arithmetic operation handlers |
| builtin.c | Updates unreachable code markers in builtin candidate generation |
| builtins/printf.c | Replaces unreachable code assertions in printf/echo option parsing |
| builtins/test.c | Updates unreachable markers in file test and expression evaluation |
| exec.c | Replaces assertions in command execution paths that should never return |
| expand.c | Updates unreachable markers in parameter expansion logic |
| history.c | Replaces assertions in history command execution paths |
| input.c | Updates unreachable markers in input handling and prompt generation |
| job.c | Replaces assertions in job status calculation functions |
| lineedit/compparse.c | Updates unreachable marker in parameter expansion parsing |
| lineedit/complete.c | Replaces assertions in completion option parsing |
| lineedit/display.c | Updates unreachable markers in search mode display logic |
| lineedit/editing.c | Replaces assertions in editing mode initialization and command execution |
| lineedit/keymap.c | Updates unreachable marker in binding mode character selection |
| lineedit/lineedit.c | Replaces assertions in readline state handling |
| option.c | Updates unreachable markers in option handling switch statements |
| parser.c | Replaces numerous assertions in parsing logic for various token types |
| path.c | Updates unreachable marker in umask operation handling |
| redir.c | Replaces assertions in redirection opening and process execution |
| variable.c | Updates unreachable markers in variable type handling and builtin operations |
| xgetopt.c | Replaces assertions in option argument parsing |
| yash.c | Updates unreachable markers after functions that never return |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the idea suggested in #208.
Summary by Copilot
This pull request replaces all instances of the
assert(false)pattern with a newUNREACHABLE()macro throughout the codebase. TheUNREACHABLE()macro provides a clearer indication of unreachable code and, when supported, uses compiler intrinsics to mark such code paths as unreachable, potentially aiding optimization and diagnostics. The macro is defined incommon.hand is now used in place ofassert(false)in various source files.Macro introduction and usage update:
UNREACHABLE()macro incommon.h, which asserts and uses__builtin_unreachable()when available, otherwise just asserts.assert(false)withUNREACHABLE()in logic branches that should never be reached, across multiple files includingarith.c,builtin.c,builtins/printf.c,builtins/test.c,exec.c,expand.c, andhistory.c. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28] [29] [30] [31] [32] [33] [34] [35]Copyright update:
arith.candcommon.hto 2025. [1] [2]This change improves code clarity and maintainability by standardizing unreachable code handling and leveraging compiler features where available.