Repository navigation
C++: Introduce getBitWidth predicate for Type
#22830
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
Changes from 3 commits
7a391d8
c6e00f0
ebb03f0
a00d282
09f3b19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| category: feature | ||
| --- | ||
| * Added a new predicate `getBitWidth` to the `Type` class, which yields the bit-width of the type. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -344,12 +344,12 @@ private int convertIntToType(int val, IntegralType t) { | |
| then if val = 0 then result = 0 else result = 1 | ||
| else | ||
| if t.isUnsigned() | ||
| then val >= 0 and val.bitShiftRight(t.getSize() * 8) = 0 and result = val | ||
| then val >= 0 and val.bitShiftRight(t.getBitWidth()) = 0 and result = val | ||
| else | ||
| if val >= 0 and val.bitShiftRight(t.getSize() * 8 - 1) = 0 | ||
| if val >= 0 and val.bitShiftRight(t.getBitWidth() - 1) = 0 | ||
| then result = val | ||
| else ( | ||
| (-(val + 1)).bitShiftRight(t.getSize() * 8 - 1) = 0 and result = val | ||
| (-(val + 1)).bitShiftRight(t.getBitWidth() - 1) = 0 and result = val | ||
|
Comment on lines
+349
to
+352
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I see no evidence of this in the documentation, but if this is the case, this was already a problem for larger types like
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think QL
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a weird way of phrasing things by Copilot then. In any case, pre-existing problem. |
||
| ) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ where | |
| then fct = va.getFullyConverted().getType().(ReferenceType).getBaseType() | ||
| else fct = va.getFullyConverted().getType() | ||
| ) and | ||
| fi.getNumBits() > fct.getSize() * 8 and | ||
| fi.getNumBits() > fct.getBitWidth() and | ||
| va.getExplicitlyConverted().getType().getSize() > fct.getSize() and | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in a00d282 |
||
| va.getTarget() = fi and | ||
| not fct.getUnspecifiedType() instanceof BoolType | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,10 +61,10 @@ class ImplicitConversion extends Expr { | |
| int getSourceSize() { | ||
| if this instanceof IntConstantExpr | ||
| then result = this.(IntConstantExpr).getRequiredSizeBits() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That has a FIXME with limitations on it in any case, so won't fix for now. |
||
| else result = this.getUnderlyingSourceType().getSize() * 8 | ||
| else result = this.getUnderlyingSourceType().getBitWidth() | ||
| } | ||
|
|
||
| int getTargetSize() { result = this.getUnderlyingTargetType().getSize() * 8 } | ||
| int getTargetSize() { result = this.getUnderlyingTargetType().getBitWidth() } | ||
|
|
||
| predicate isSourceSignedInt() { | ||
| if this instanceof IntConstantExpr | ||
|
|
||
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.
That's fair. Let me fix that (in the correct way).
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.
Fixed in a00d282