-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C++: New range analysis #633
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 all commits
a06a20d
ed68f91
fe32aea
ae4ffd9
89148a9
2f8ca88
b2cd9a2
567eee1
8c9c316
0040a2d
af8a3f2
c39de75
c455db9
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,80 @@ | ||
| import cpp | ||
| private import semmle.code.cpp.ir.IR | ||
| private import semmle.code.cpp.ir.ValueNumbering | ||
|
|
||
| private newtype TBound = | ||
| TBoundZero() or | ||
| TBoundValueNumber(ValueNumber vn) { | ||
| exists(Instruction i | | ||
| vn.getAnInstruction() = i and | ||
| ( | ||
| i.getResultType() instanceof IntegralType or | ||
| i.getResultType() instanceof PointerType | ||
| ) and | ||
| not vn.getAnInstruction() instanceof ConstantInstruction | ||
| | | ||
| i instanceof PhiInstruction | ||
| or | ||
| i instanceof InitializeParameterInstruction | ||
| or | ||
| i instanceof CallInstruction | ||
| or | ||
| i instanceof VariableAddressInstruction | ||
| or | ||
| i instanceof FieldAddressInstruction | ||
| or | ||
| i.(LoadInstruction).getSourceAddress() instanceof VariableAddressInstruction | ||
| or | ||
| i.(LoadInstruction).getSourceAddress() instanceof FieldAddressInstruction | ||
| or | ||
| i.getAUse() instanceof ArgumentOperand | ||
| ) | ||
| } | ||
|
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. If
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 had thought that bounding relative to
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. It also looks like
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. Right. I think the set of interesting bounds in C++ is going to be bigger than in Java, but I haven't narrowed it down fully. Also, @dave-bartolomeo suggested that
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 absolutely don't think value numbers in general should be part of
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. Right, sorry, just now read the commit with the code change above to use value numbers. When restricted to atomic things, then it looks like it might be fine. I'm slightly concerned by the
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. Yes; Consider the following code: I think we will need to be able to have bounds relative to arbitrary
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. Ok, I can see why it can be useful. Then let me just say that the size of the
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'm starting on performance testing; it looks like the main stage of range analysis is about 50% slower with the |
||
|
|
||
| /** | ||
| * A bound that may be inferred for an expression plus/minus an integer delta. | ||
| */ | ||
| abstract class Bound extends TBound { | ||
| abstract string toString(); | ||
|
|
||
| /** Gets an expression that equals this bound plus `delta`. */ | ||
| abstract Instruction getInstruction(int delta); | ||
|
|
||
| /** Gets an expression that equals this bound. */ | ||
| Instruction getInstruction() { result = getInstruction(0) } | ||
|
|
||
| abstract Location getLocation(); | ||
| } | ||
|
|
||
| /** | ||
| * The bound that corresponds to the integer 0. This is used to represent all | ||
| * integer bounds as bounds are always accompanied by an added integer delta. | ||
| */ | ||
| class ZeroBound extends Bound, TBoundZero { | ||
| override string toString() { result = "0" } | ||
|
|
||
| override Instruction getInstruction(int delta) { result.(ConstantValueInstruction).getValue().toInt() = delta } | ||
|
|
||
| override Location getLocation() { | ||
| result instanceof UnknownDefaultLocation | ||
| } | ||
| } | ||
| /** | ||
| * A bound corresponding to the value of an `Instruction`. | ||
| */ | ||
| class ValueNumberBound extends Bound, TBoundValueNumber { | ||
| ValueNumber vn; | ||
|
|
||
| ValueNumberBound() { | ||
| this = TBoundValueNumber(vn) | ||
| } | ||
|
|
||
| /** Gets the SSA variable that equals this bound. */ | ||
| override Instruction getInstruction(int delta) { this = TBoundValueNumber(valueNumber(result)) and delta = 0} | ||
|
|
||
| override string toString() { result = vn.getExampleInstruction().toString() } | ||
|
|
||
| override Location getLocation() { | ||
| result = vn.getLocation() | ||
| } | ||
| } | ||
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.
QLDoc, please.