C++: Fix missing bool
-> int
conversions in C code
#20145
+133
−32
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 #18490 we fixed a number of discrepancies between IR generated from C code, and IR generated from C++ code. For example, the following code has a int-to-bool conversion in the AST on
x
at the conditional when compiled as C++, but not when compiled as C:#18490 removed this discrepancy in the IR by synthesizing the equivalent int-to-bool conversion when generating IR. One of the things we did was adjust the
IRType
returned by various operations (see here)However, when I was working on something else I noticed that this change introduced a type error in the IR on examples such as:
Because
a < b
has been overwritten to return a boolean, theStoreInstruction
corresponding to the initialization ofx
looks like:In particular, notice that we are storing a result of type
bool
into a memory address of typeglval<int>
. That's not allowed in the IR, and it gives some false negatives in the guards library.This PR fixes that by adding the necessary bool-to-int conversions when such type errors would have occurred in the IR.
Commit-by-commit review highly encouraged.
DCA shows a couple new results for
cpp/missing-check-scanf
. They look like FPs caused by insufficient guards logic (which we now need now that those conditionals are properly handled in the IR). I will take a look at once this PR has been merged.