Skip to content

Conversation

@magicant
Copy link
Owner

@magicant magicant commented Dec 5, 2025

Implements the idea suggested in #208.

Summary by Copilot

This pull request replaces all instances of the assert(false) pattern with a new UNREACHABLE() macro throughout the codebase. The UNREACHABLE() 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 in common.h and is now used in place of assert(false) in various source files.

Macro introduction and usage update:

Copyright update:

  • Updated copyright years in arith.c and common.h to 2025. [1] [2]

This change improves code clarity and maintainability by standardizing unreachable code handling and leveraging compiler features where available.

@magicant magicant requested a review from Copilot December 5, 2025 14:09
@magicant magicant self-assigned this Dec 5, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in common.h that uses __builtin_unreachable() when supported
  • Replaced all assert(false) calls with UNREACHABLE() 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.

@magicant magicant merged commit a86121e into trunk Dec 5, 2025
6 checks passed
@magicant magicant deleted the unreachable branch December 5, 2025 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants