Skip to content

Conversation

@jgarzik
Copy link
Contributor

@jgarzik jgarzik commented Dec 26, 2025

No description provided.

1. cc/ir/linearize.rs (lines 1748-1794): Fixed linearize_if() to use current_bb instead of allocated block IDs when linking to merge_bb, with reachability check
  2. cc/ir/test_linearize.rs: Added test_nested_if_cfg_linking() which verifies that nested if-else statements produce correct CFG structure with proper parent/child relationships
@jgarzik jgarzik requested a review from Copilot December 26, 2025 06:30
@jgarzik jgarzik self-assigned this Dec 26, 2025
@jgarzik jgarzik added bug Something isn't working enhancement New feature or request labels Dec 26, 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 implements several bug fixes and new features for the C compiler, primarily focusing on GNU extensions and improved C99 compliance. The main additions are statement expressions (({ }) syntax), __builtin_offsetof/offsetof, and various builtin function recognitions, along with fixes for nested if-else CFG linking and enhanced error checking for bitfields, for-loop declarations, and variadic functions.

Key Changes:

  • Added support for GNU statement expressions and __builtin_offsetof/offsetof
  • Fixed nested if-else CFG linking issues in IR linearization
  • Enhanced preprocessor to recognize additional builtins (__builtin_ctz*, __builtin_clz*, __builtin_popcount*) and report GNU extension support via __has_feature/__has_extension
  • Added validation and warnings for empty enums, bitfield edge cases, for-loop storage class specifiers, and variadic functions without named parameters

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
cc/token/preprocess.rs Added builtin function names (ctz, clz, popcount, offsetof, unreachable) and implemented __has_feature/__has_extension to report statement_expressions support
cc/parse/parser.rs Implemented parsing for __builtin_offsetof, statement expressions, added for-loop init declaration validation, enhanced bitfield checks, and added warnings for empty enums and variadic functions
cc/parse/ast.rs Added AST nodes for StmtExpr and OffsetOf expressions with supporting OffsetOfPath enum
cc/ir/linearize.rs Fixed nested if-else CFG linking bug by tracking reachable blocks correctly; added linearization for OffsetOf and StmtExpr
cc/ir/test_linearize.rs Added comprehensive tests for nested control flow, switch statements, loops, goto/labels, pointer arithmetic, floating-point operations, and new features
cc/tests/features/stmt_expr.rs Added integration tests for statement expressions including basic usage, nested expressions, and control flow
cc/tests/features/offsetof.rs Added integration tests for offsetof with basic structs, nested members, and array indexing
cc/tests/features/mod.rs Added module declarations for new test files
cc/tests/features/has_feature.rs Updated tests to verify __has_builtin(offsetof) and __has_feature(statement_expressions) return true
cc/doc/BUILTIN.md Documented __builtin_offsetof and offsetof in the structure layout section

@jgarzik jgarzik merged commit 6651c5f into main Dec 26, 2025
4 checks passed
@jgarzik jgarzik deleted the updates branch December 26, 2025 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants