Implement bitwise builtin variants (l, ll) and improve constant evaluation#945
Implement bitwise builtin variants (l, ll) and improve constant evaluation#945
Conversation
This commit implements the missing `long` (`l`) and `long long` (`ll`) variants for the following bitwise builtins: - `__builtin_popcount` - `__builtin_clz` - `__builtin_ctz` - `__builtin_ffs` Key changes: - Added specific AST variants for each builtin in `ParsedNodeKind` and `NodeKind`. - Updated the parser to distinguish between these variants. - Implemented proper type checking in the semantic analyzer, ensuring arguments are correctly promoted to `unsigned long` or `unsigned long long` where appropriate, while results remain `int`. - Enhanced constant evaluation to be bit-width aware. Specifically, `clz` now correctly accounts for the bit-width of its argument type (32 for `int`, 64 for `long long`). - Updated MIR generation to lower these builtins to their corresponding integer operations. - Expanded `__has_builtin` support in the preprocessor to include all newly implemented variants and other existing supported builtins. - Added comprehensive unit tests in `src/tests/bitwise_builtins.rs` covering constant evaluation and runtime behavior. Co-authored-by: bungcip <72723+bungcip@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
I have implemented the
longandlong longvariants for the core bitwise builtins (popcount,clz,ctz,ffs) in the Cendol compiler. This implementation spans the entire compiler pipeline, from parsing to code generation, and includes bit-width aware constant evaluation and expanded__has_builtinsupport. Comprehensive tests were added to verify correctness.PR created automatically by Jules for task 13042398019651368740 started by @bungcip