-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Go: Fix some Ql4Ql violations. #20327
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
Merged
+163
−174
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -347,183 +347,171 @@ float getALowerBound(Expr expr) { | |
* Gets a possible upper bound of SSA definition `def`. | ||
*/ | ||
float getAnSsaUpperBound(SsaDefinition def) { | ||
if recursiveSelfDef(def) | ||
then none() | ||
else ( | ||
if def instanceof SsaExplicitDefinition | ||
then | ||
exists(SsaExplicitDefinition explicitDef | explicitDef = def | | ||
//SSA definition coresponding to a `SimpleAssignStmt` | ||
if explicitDef.getInstruction() instanceof IR::AssignInstruction | ||
then | ||
exists(IR::AssignInstruction assignInstr, SimpleAssignStmt simpleAssign | | ||
assignInstr = explicitDef.getInstruction() and | ||
assignInstr.getRhs().(IR::EvalInstruction).getExpr() = simpleAssign.getRhs() and | ||
result = getAnUpperBound(simpleAssign.getRhs()) | ||
) | ||
or | ||
//SSA definition coresponding to a ValueSpec(used in a variable declaration) | ||
exists(IR::AssignInstruction declInstr, ValueSpec vs, int i, Expr init | | ||
declInstr = explicitDef.getInstruction() and | ||
declInstr = IR::initInstruction(vs, i) and | ||
init = vs.getInit(i) and | ||
result = getAnUpperBound(init) | ||
) | ||
or | ||
//SSA definition coresponding to an `AddAssignStmt` (x += y) or `SubAssignStmt` (x -= y) | ||
exists( | ||
IR::AssignInstruction assignInstr, SsaExplicitDefinition prevDef, | ||
CompoundAssignStmt compoundAssign, float prevBound, float delta | ||
| | ||
assignInstr = explicitDef.getInstruction() and | ||
getAUse(prevDef) = compoundAssign.getLhs() and | ||
assignInstr = IR::assignInstruction(compoundAssign, 0) and | ||
prevBound = getAnSsaUpperBound(prevDef) and | ||
if compoundAssign instanceof AddAssignStmt | ||
then | ||
delta = getAnUpperBound(compoundAssign.getRhs()) and | ||
result = addRoundingUp(prevBound, delta) | ||
else | ||
if compoundAssign instanceof SubAssignStmt | ||
then | ||
delta = getALowerBound(compoundAssign.getRhs()) and | ||
result = addRoundingUp(prevBound, -delta) | ||
else none() | ||
not recursiveSelfDef(def) and | ||
( | ||
def instanceof SsaExplicitDefinition and | ||
exists(SsaExplicitDefinition explicitDef | explicitDef = def | | ||
//SSA definition coresponding to a `SimpleAssignStmt` | ||
if explicitDef.getInstruction() instanceof IR::AssignInstruction | ||
then | ||
exists(IR::AssignInstruction assignInstr, SimpleAssignStmt simpleAssign | | ||
assignInstr = explicitDef.getInstruction() and | ||
assignInstr.getRhs().(IR::EvalInstruction).getExpr() = simpleAssign.getRhs() and | ||
result = getAnUpperBound(simpleAssign.getRhs()) | ||
) | ||
or | ||
//SSA definition coresponding to a ValueSpec(used in a variable declaration) | ||
exists(IR::AssignInstruction declInstr, ValueSpec vs, int i, Expr init | | ||
declInstr = explicitDef.getInstruction() and | ||
declInstr = IR::initInstruction(vs, i) and | ||
init = vs.getInit(i) and | ||
result = getAnUpperBound(init) | ||
) | ||
or | ||
//SSA definition coresponding to an `AddAssignStmt` (x += y) or `SubAssignStmt` (x -= y) | ||
exists( | ||
IR::AssignInstruction assignInstr, SsaExplicitDefinition prevDef, | ||
CompoundAssignStmt compoundAssign, float prevBound, float delta | ||
| | ||
assignInstr = explicitDef.getInstruction() and | ||
getAUse(prevDef) = compoundAssign.getLhs() and | ||
assignInstr = IR::assignInstruction(compoundAssign, 0) and | ||
prevBound = getAnSsaUpperBound(prevDef) and | ||
( | ||
compoundAssign instanceof AddAssignStmt and | ||
delta = getAnUpperBound(compoundAssign.getRhs()) and | ||
result = addRoundingUp(prevBound, delta) | ||
or | ||
compoundAssign instanceof SubAssignStmt and | ||
delta = getALowerBound(compoundAssign.getRhs()) and | ||
result = addRoundingUp(prevBound, -delta) | ||
) | ||
else | ||
//SSA definition coresponding to an `IncDecStmt` | ||
if explicitDef.getInstruction() instanceof IR::IncDecInstruction | ||
then | ||
exists(IncDecStmt incOrDec, IR::IncDecInstruction instr, float exprLB | | ||
instr = explicitDef.getInstruction() and | ||
exprLB = getAnUpperBound(incOrDec.getOperand()) and | ||
instr.getRhs().(IR::EvalIncDecRhsInstruction).getStmt() = incOrDec and | ||
( | ||
//IncStmt(x++) | ||
exists(IncStmt inc | | ||
inc = incOrDec and | ||
result = addRoundingUp(exprLB, 1) | ||
) | ||
or | ||
//DecStmt(x--) | ||
exists(DecStmt dec | | ||
dec = incOrDec and | ||
result = addRoundingUp(exprLB, -1) | ||
) | ||
) | ||
else | ||
//SSA definition coresponding to an `IncDecStmt` | ||
if explicitDef.getInstruction() instanceof IR::IncDecInstruction | ||
then | ||
exists(IncDecStmt incOrDec, IR::IncDecInstruction instr, float exprLB | | ||
instr = explicitDef.getInstruction() and | ||
exprLB = getAnUpperBound(incOrDec.getOperand()) and | ||
instr.getRhs().(IR::EvalIncDecRhsInstruction).getStmt() = incOrDec and | ||
( | ||
//IncStmt(x++) | ||
exists(IncStmt inc | | ||
inc = incOrDec and | ||
result = addRoundingUp(exprLB, 1) | ||
) | ||
) | ||
else | ||
//SSA definition coreponding to the init of the parameter | ||
if explicitDef.getInstruction() instanceof IR::InitParameterInstruction | ||
then | ||
exists(IR::InitParameterInstruction instr, Parameter p | | ||
instr = explicitDef.getInstruction() and | ||
IR::initParamInstruction(p) = instr and | ||
result = typeMaxValue(p.getType()) | ||
or | ||
//DecStmt(x--) | ||
exists(DecStmt dec | | ||
dec = incOrDec and | ||
result = addRoundingUp(exprLB, -1) | ||
) | ||
else none() | ||
) | ||
else | ||
//this SSA definition is a phi node. | ||
if def instanceof SsaPhiNode | ||
then | ||
exists(SsaPhiNode phi | | ||
phi = def and | ||
result = getAnSsaUpperBound(phi.getAnInput().getDefinition()) | ||
) | ||
) | ||
else ( | ||
//SSA definition coreponding to the init of the parameter | ||
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. Misspelling: 'coreponding' should be 'corresponding'. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
explicitDef.getInstruction() instanceof IR::InitParameterInstruction and | ||
exists(IR::InitParameterInstruction instr, Parameter p | | ||
instr = explicitDef.getInstruction() and | ||
IR::initParamInstruction(p) = instr and | ||
result = typeMaxValue(p.getType()) | ||
) | ||
) | ||
else none() | ||
) | ||
or | ||
//this SSA definition is a phi node. | ||
def instanceof SsaPhiNode and | ||
exists(SsaPhiNode phi | | ||
phi = def and | ||
result = getAnSsaUpperBound(phi.getAnInput().getDefinition()) | ||
) | ||
) | ||
} | ||
|
||
/** | ||
* Gets a possible lower bound of SSA definition `def`. | ||
*/ | ||
float getAnSsaLowerBound(SsaDefinition def) { | ||
if recursiveSelfDef(def) | ||
then none() | ||
else ( | ||
if def instanceof SsaExplicitDefinition | ||
then | ||
exists(SsaExplicitDefinition explicitDef | explicitDef = def | | ||
if explicitDef.getInstruction() instanceof IR::AssignInstruction | ||
then | ||
//SimpleAssignStmt | ||
exists(IR::AssignInstruction assignInstr, SimpleAssignStmt simpleAssign | | ||
assignInstr = explicitDef.getInstruction() and | ||
assignInstr.getRhs().(IR::EvalInstruction).getExpr() = simpleAssign.getRhs() and | ||
result = getALowerBound(simpleAssign.getRhs()) | ||
) | ||
or | ||
//ValueSpec | ||
exists(IR::AssignInstruction declInstr, ValueSpec vs, int i, Expr init | | ||
declInstr = explicitDef.getInstruction() and | ||
declInstr = IR::initInstruction(vs, i) and | ||
init = vs.getInit(i) and | ||
result = getALowerBound(init) | ||
) | ||
or | ||
//AddAssignStmt(x += y) | ||
exists( | ||
IR::AssignInstruction assignInstr, SsaExplicitDefinition prevDef, | ||
CompoundAssignStmt compoundAssign, float prevBound, float delta | ||
| | ||
assignInstr = explicitDef.getInstruction() and | ||
getAUse(prevDef) = compoundAssign.getLhs() and | ||
assignInstr = IR::assignInstruction(compoundAssign, 0) and | ||
prevBound = getAnSsaLowerBound(prevDef) and | ||
if compoundAssign instanceof AddAssignStmt | ||
then | ||
delta = getALowerBound(compoundAssign.getRhs()) and | ||
result = addRoundingDown(prevBound, delta) | ||
else | ||
if compoundAssign instanceof SubAssignStmt | ||
then | ||
delta = getAnUpperBound(compoundAssign.getRhs()) and | ||
result = addRoundingDown(prevBound, -delta) | ||
else none() | ||
not recursiveSelfDef(def) and | ||
( | ||
def instanceof SsaExplicitDefinition and | ||
exists(SsaExplicitDefinition explicitDef | explicitDef = def | | ||
if explicitDef.getInstruction() instanceof IR::AssignInstruction | ||
then | ||
//SimpleAssignStmt | ||
exists(IR::AssignInstruction assignInstr, SimpleAssignStmt simpleAssign | | ||
assignInstr = explicitDef.getInstruction() and | ||
assignInstr.getRhs().(IR::EvalInstruction).getExpr() = simpleAssign.getRhs() and | ||
result = getALowerBound(simpleAssign.getRhs()) | ||
) | ||
or | ||
//ValueSpec | ||
exists(IR::AssignInstruction declInstr, ValueSpec vs, int i, Expr init | | ||
declInstr = explicitDef.getInstruction() and | ||
declInstr = IR::initInstruction(vs, i) and | ||
init = vs.getInit(i) and | ||
result = getALowerBound(init) | ||
) | ||
or | ||
//AddAssignStmt(x += y) | ||
exists( | ||
IR::AssignInstruction assignInstr, SsaExplicitDefinition prevDef, | ||
CompoundAssignStmt compoundAssign, float prevBound, float delta | ||
| | ||
assignInstr = explicitDef.getInstruction() and | ||
getAUse(prevDef) = compoundAssign.getLhs() and | ||
assignInstr = IR::assignInstruction(compoundAssign, 0) and | ||
prevBound = getAnSsaLowerBound(prevDef) and | ||
( | ||
compoundAssign instanceof AddAssignStmt and | ||
delta = getALowerBound(compoundAssign.getRhs()) and | ||
result = addRoundingDown(prevBound, delta) | ||
or | ||
compoundAssign instanceof SubAssignStmt and | ||
delta = getAnUpperBound(compoundAssign.getRhs()) and | ||
result = addRoundingDown(prevBound, -delta) | ||
) | ||
else | ||
//IncDecStmt | ||
if explicitDef.getInstruction() instanceof IR::IncDecInstruction | ||
then | ||
exists(IncDecStmt incOrDec, IR::IncDecInstruction instr, float exprLB | | ||
instr = explicitDef.getInstruction() and | ||
exprLB = getALowerBound(incOrDec.getOperand()) and | ||
instr.getRhs().(IR::EvalIncDecRhsInstruction).getStmt() = incOrDec and | ||
( | ||
//IncStmt(x++) | ||
exists(IncStmt inc | | ||
inc = incOrDec and | ||
result = addRoundingDown(exprLB, 1) | ||
) | ||
or | ||
//DecStmt(x--) | ||
exists(DecStmt dec | | ||
dec = incOrDec and | ||
result = addRoundingDown(exprLB, -1) | ||
) | ||
) | ||
else | ||
//IncDecStmt | ||
if explicitDef.getInstruction() instanceof IR::IncDecInstruction | ||
then | ||
exists(IncDecStmt incOrDec, IR::IncDecInstruction instr, float exprLB | | ||
instr = explicitDef.getInstruction() and | ||
exprLB = getALowerBound(incOrDec.getOperand()) and | ||
instr.getRhs().(IR::EvalIncDecRhsInstruction).getStmt() = incOrDec and | ||
( | ||
//IncStmt(x++) | ||
exists(IncStmt inc | | ||
inc = incOrDec and | ||
result = addRoundingDown(exprLB, 1) | ||
) | ||
) | ||
else | ||
//init of the function parameter | ||
if explicitDef.getInstruction() instanceof IR::InitParameterInstruction | ||
then | ||
exists(IR::InitParameterInstruction instr, Parameter p | | ||
instr = explicitDef.getInstruction() and | ||
IR::initParamInstruction(p) = instr and | ||
result = typeMinValue(p.getType()) | ||
or | ||
//DecStmt(x--) | ||
exists(DecStmt dec | | ||
dec = incOrDec and | ||
result = addRoundingDown(exprLB, -1) | ||
) | ||
else none() | ||
) | ||
else | ||
//phi node | ||
if def instanceof SsaPhiNode | ||
then | ||
exists(SsaPhiNode phi | | ||
phi = def and | ||
result = getAnSsaLowerBound(phi.getAnInput().getDefinition()) | ||
) | ||
) | ||
else ( | ||
//init of the function parameter | ||
explicitDef.getInstruction() instanceof IR::InitParameterInstruction and | ||
exists(IR::InitParameterInstruction instr, Parameter p | | ||
instr = explicitDef.getInstruction() and | ||
IR::initParamInstruction(p) = instr and | ||
result = typeMinValue(p.getType()) | ||
) | ||
) | ||
else none() | ||
) | ||
or | ||
//phi node | ||
def instanceof SsaPhiNode and | ||
exists(SsaPhiNode phi | | ||
phi = def and | ||
result = getAnSsaLowerBound(phi.getAnInput().getDefinition()) | ||
) | ||
) | ||
} | ||
|
||
|
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.
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.
Misspelling: 'coresponding' should be 'corresponding'.
Copilot uses AI. Check for mistakes.