- Notifications
You must be signed in to change notification settings - Fork1.9k
Comments
C/C++: Disable constant folding of address-vs-null comparisons#21258
Open
C/C++: Disable constant folding of address-vs-null comparisons#21258
Conversation
15ff5d6 toa7c6736Comparea7c6736 to8cfa0a3CompareContributor
There was a problem hiding this 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 addresses an issue where the EDG frontend constant-folds address-vs-null comparisons (e.g.,&var == NULL), causing the intermediate representation (IR) to loseVariableAddressInstruction nodes. The fix adds acontainsAddressOf predicate to prevent constant folding of expressions containing address-of operators, ensuring that address operations remain visible in the IR for proper analysis.
Changes:
- Added
containsAddressOfpredicate to detect expressions containing address-of operations - Modified
isIRConstantto exclude expressions containing address-of operators - Added comprehensive test coverage for address-vs-null comparisons with global, local, and parameter variables
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll | AddedcontainsAddressOf predicate and integrated it intoisIRConstant to prevent constant folding of expressions containing address-of operators |
| cpp/ql/test/library-tests/ir/address_constant_folding/test.c | Comprehensive test file with various address-vs-null comparison scenarios covering global, local, and parameter variables |
| cpp/ql/test/library-tests/ir/address_constant_folding/variable_addresses.ql | Test query to verifyVariableAddressInstruction nodes are present in the IR |
| cpp/ql/test/library-tests/ir/address_constant_folding/variable_addresses.expected | Auto-generated test expectations file (empty, will be populated when tests run) |
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 freeto 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.
Uh oh!
There was an error while loading.Please reload this page.
The EDG frontend constant-folds address-vs-null comparisons (e.g.,
&var == NULL) cause the IR to lose theVariableAddressInstruction.This PR adds a
containsAddressOfpredicate used inisIRConstantso these expressions are expanded instead of collapsed.