-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C++: Generate int-to-bool conversions in C code #18490
Draft
MathiasVP
wants to merge
18
commits into
github:main
Choose a base branch
from
MathiasVP:generate-int-to-bool-conversion-instructions-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
C++: Generate int-to-bool conversions in C code #18490
MathiasVP
wants to merge
18
commits into
github:main
from
MathiasVP:generate-int-to-bool-conversion-instructions-2
Conversation
This file contains 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
…plicit comparisons against 0 in C code.
MathiasVP
force-pushed
the
generate-int-to-bool-conversion-instructions-2
branch
from
January 15, 2025 16:28
446f6cb
to
d182a41
Compare
MathiasVP
force-pushed
the
generate-int-to-bool-conversion-instructions-2
branch
from
January 15, 2025 16:38
d182a41
to
d204810
Compare
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.
In C++ code we have int-to-bool conversions on
myInt
in examples like:That is, it's not
myInt
that is branched on, but rather the result ofmyInt != 0
. In the IR, this manifests as the IR looking like:(notice the
BranchNE
instruction).This information is important in guard conditions since branching on
myInt
doesn't tell us thatmyInt == 1
, but rather that(myInt != 0) == 1
.This is all well and good in C++. However, in C, there are no int-to-bool conversions. So when compiling the same code with a C compiler the IR looks like:
(notice that we're now branching on the value of
myInt
)Historically, we've worked around this problem in IRGuards specifically (see #16364 and #16533), but upon facing a related problem somewhere else I now feel like we should simply make the IR equivalent in C and C++.
So this PR inserts IR equivalent to what would have been generated for an int-to-bool conversion if it had been present in the database in the places I'm aware of this being a problem. It then removes the workarounds in the guards library that were added to handle these.
Commit-by-commit review recommended (especially for the IR construction related commits).
DCA reveals a few new results and a few lost results:
cpp/overrun-write
andcpp/path-injection
results are because both queries use any guard as a barrier, and we now recognize more barriers.cpp/redundant-null-check-simple
results are new TPs 🎉I've verified that the new TPs are real TPs caused by us recognizing more guards in C code (🎉), and I've verified that the removed results are