Skip to content

Commit 5c466f3

Browse files
committed
Java: Sync files and update other relavant files related to the new naming of shift.
1 parent 49a87e1 commit 5c466f3

File tree

14 files changed

+91
-73
lines changed

14 files changed

+91
-73
lines changed

java/ql/lib/semmle/code/java/Expr.qll

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,11 @@ class CompileTimeConstantExpr extends Expr {
366366
or
367367
b instanceof SubExpr and result = v1 - v2
368368
or
369-
b instanceof LShiftExpr and result = v1.bitShiftLeft(v2)
369+
b instanceof LeftShiftExpr and result = v1.bitShiftLeft(v2)
370370
or
371-
b instanceof RShiftExpr and result = v1.bitShiftRightSigned(v2)
371+
b instanceof RightShiftExpr and result = v1.bitShiftRightSigned(v2)
372372
or
373-
b instanceof URShiftExpr and result = v1.bitShiftRight(v2)
373+
b instanceof UnsignedRightShiftExpr and result = v1.bitShiftRight(v2)
374374
or
375375
b instanceof AndBitwiseExpr and result = v1.bitAnd(v2)
376376
or
@@ -623,26 +623,35 @@ class AssignXorExpr extends AssignOp, @assignxorexpr {
623623
}
624624

625625
/** A compound assignment expression using the `<<=` operator. */
626-
class AssignLShiftExpr extends AssignOp, @assignlshiftexpr {
626+
class AssignLeftShiftExpr extends AssignOp, @assignlshiftexpr {
627627
override string getOp() { result = "<<=" }
628628

629-
override string getAPrimaryQlClass() { result = "AssignLShiftExpr" }
629+
override string getAPrimaryQlClass() { result = "AssignLeftShiftExpr" }
630630
}
631631

632+
/** DEPRECATED: Alias for AssignLeftShiftExpr. */
633+
deprecated class AssignLShiftExpr = AssignLeftShiftExpr;
634+
632635
/** A compound assignment expression using the `>>=` operator. */
633-
class AssignRShiftExpr extends AssignOp, @assignrshiftexpr {
636+
class AssignRightShiftExpr extends AssignOp, @assignrshiftexpr {
634637
override string getOp() { result = ">>=" }
635638

636-
override string getAPrimaryQlClass() { result = "AssignRShiftExpr" }
639+
override string getAPrimaryQlClass() { result = "AssignRightShiftExpr" }
637640
}
638641

642+
/** DEPRECATED: Alias for AssignRightShiftExpr. */
643+
deprecated class AssignRShiftExpr = AssignRightShiftExpr;
644+
639645
/** A compound assignment expression using the `>>>=` operator. */
640-
class AssignURShiftExpr extends AssignOp, @assignurshiftexpr {
646+
class AssignUnsignedRightShiftExpr extends AssignOp, @assignurshiftexpr {
641647
override string getOp() { result = ">>>=" }
642648

643-
override string getAPrimaryQlClass() { result = "AssignURShiftExpr" }
649+
override string getAPrimaryQlClass() { result = "AssignUnsignedRightShiftExpr" }
644650
}
645651

652+
/** DEPRECATED: Alias for AssignUnsignedRightShiftExpr. */
653+
deprecated class AssignURShiftExpr = AssignUnsignedRightShiftExpr;
654+
646655
/** A common super-class to represent constant literals. */
647656
class Literal extends Expr, @literal {
648657
/**
@@ -904,26 +913,35 @@ class SubExpr extends BinaryExpr, @subexpr {
904913
}
905914

906915
/** A binary expression using the `<<` operator. */
907-
class LShiftExpr extends BinaryExpr, @lshiftexpr {
916+
class LeftShiftExpr extends BinaryExpr, @lshiftexpr {
908917
override string getOp() { result = " << " }
909918

910-
override string getAPrimaryQlClass() { result = "LShiftExpr" }
919+
override string getAPrimaryQlClass() { result = "LeftShiftExpr" }
911920
}
912921

922+
/** DEPRECATED: Alias for LeftShiftExpr. */
923+
deprecated class LShiftExpr = LeftShiftExpr;
924+
913925
/** A binary expression using the `>>` operator. */
914-
class RShiftExpr extends BinaryExpr, @rshiftexpr {
926+
class RightShiftExpr extends BinaryExpr, @rshiftexpr {
915927
override string getOp() { result = " >> " }
916928

917-
override string getAPrimaryQlClass() { result = "RShiftExpr" }
929+
override string getAPrimaryQlClass() { result = "RightShiftExpr" }
918930
}
919931

932+
/** DEPRECATED: Alias for RightShiftExpr. */
933+
deprecated class RShiftExpr = RightShiftExpr;
934+
920935
/** A binary expression using the `>>>` operator. */
921-
class URShiftExpr extends BinaryExpr, @urshiftexpr {
936+
class UnsignedRightShiftExpr extends BinaryExpr, @urshiftexpr {
922937
override string getOp() { result = " >>> " }
923938

924-
override string getAPrimaryQlClass() { result = "URShiftExpr" }
939+
override string getAPrimaryQlClass() { result = "UnsignedRightShiftExpr" }
925940
}
926941

942+
/** DEPRECATED: Alias for UnsignedRightShiftExpr. */
943+
deprecated class URShiftExpr = UnsignedRightShiftExpr;
944+
927945
/** A binary expression using the `&` operator. */
928946
class AndBitwiseExpr extends BinaryExpr, @andbitexpr {
929947
override string getOp() { result = " & " }

java/ql/lib/semmle/code/java/dataflow/ModulusAnalysis.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private predicate evenlyDivisibleExpr(Expr e, int factor) {
105105
exists(ConstantIntegerExpr c, int k | k = c.getIntValue() |
106106
e.(MulExpr).getAnOperand() = c and factor = k.abs() and factor >= 2
107107
or
108-
e.(LShiftExpr).getRhs() = c and factor = 2.pow(k) and k > 0
108+
e.(LeftShiftExpr).getRhs() = c and factor = 2.pow(k) and k > 0
109109
or
110110
e.(BitwiseAndExpr).getAnOperand() = c and factor = max(int f | andmaskFactor(k, f))
111111
)

java/ql/lib/semmle/code/java/dataflow/RangeAnalysis.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,11 @@ private predicate boundFlowStepMul(Expr e2, Expr e1, int factor) {
528528
or
529529
exists(AssignMulExpr e | e = e2 and e.getDest() = c and e.getRhs() = e1 and factor = k)
530530
or
531-
exists(LShiftExpr e |
531+
exists(LeftShiftExpr e |
532532
e = e2 and e.getLeftOperand() = e1 and e.getRightOperand() = c and factor = 2.pow(k)
533533
)
534534
or
535-
exists(AssignLShiftExpr e |
535+
exists(AssignLeftShiftExpr e |
536536
e = e2 and e.getDest() = e1 and e.getRhs() = c and factor = 2.pow(k)
537537
)
538538
)
@@ -552,19 +552,19 @@ private predicate boundFlowStepDiv(Expr e2, Expr e1, int factor) {
552552
or
553553
exists(AssignDivExpr e | e = e2 and e.getDest() = e1 and e.getRhs() = c and factor = k)
554554
or
555-
exists(RShiftExpr e |
555+
exists(RightShiftExpr e |
556556
e = e2 and e.getLeftOperand() = e1 and e.getRightOperand() = c and factor = 2.pow(k)
557557
)
558558
or
559-
exists(AssignRShiftExpr e |
559+
exists(AssignRightShiftExpr e |
560560
e = e2 and e.getDest() = e1 and e.getRhs() = c and factor = 2.pow(k)
561561
)
562562
or
563-
exists(URShiftExpr e |
563+
exists(UnsignedRightShiftExpr e |
564564
e = e2 and e.getLeftOperand() = e1 and e.getRightOperand() = c and factor = 2.pow(k)
565565
)
566566
or
567-
exists(AssignURShiftExpr e |
567+
exists(AssignUnsignedRightShiftExpr e |
568568
e = e2 and e.getDest() = e1 and e.getRhs() = c and factor = 2.pow(k)
569569
)
570570
)

java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/ModulusAnalysisSpecific.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ module Private {
7272
}
7373

7474
/** A left shift or an assign-lshift expression. */
75-
class LShiftExpr extends J::Expr {
76-
LShiftExpr() { this instanceof J::LShiftExpr or this instanceof J::AssignLShiftExpr }
75+
class LeftShiftExpr extends J::Expr {
76+
LeftShiftExpr() { this instanceof J::LeftShiftExpr or this instanceof J::AssignLeftShiftExpr }
7777

7878
/** Gets the RHS operand of this shift. */
7979
Expr getRhs() {
80-
result = this.(J::LShiftExpr).getRightOperand() or
81-
result = this.(J::AssignLShiftExpr).getRhs()
80+
result = this.(J::LeftShiftExpr).getRightOperand() or
81+
result = this.(J::AssignLeftShiftExpr).getRhs()
8282
}
8383
}
8484

java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/Sign.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ newtype TBinarySignOperation =
1818
TBitAndOp() or
1919
TBitOrOp() or
2020
TBitXorOp() or
21-
TLShiftOp() or
22-
TRShiftOp() or
23-
TURShiftOp()
21+
TLeftShiftOp() or
22+
TRightShiftOp() or
23+
TUnsignedRightShiftOp()
2424

2525
/** Class representing expression signs (+, -, 0). */
2626
class Sign extends TSign {
@@ -271,10 +271,10 @@ class Sign extends TSign {
271271
or
272272
op = TBitXorOp() and result = bitxor(s)
273273
or
274-
op = TLShiftOp() and result = lshift(s)
274+
op = TLeftShiftOp() and result = lshift(s)
275275
or
276-
op = TRShiftOp() and result = rshift(s)
276+
op = TRightShiftOp() and result = rshift(s)
277277
or
278-
op = TURShiftOp() and result = urshift(s)
278+
op = TUnsignedRightShiftOp() and result = urshift(s)
279279
}
280280
}

java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/SignAnalysisSpecific.qll

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ module Private {
102102
this instanceof J::AssignOrExpr or
103103
this instanceof J::XorBitwiseExpr or
104104
this instanceof J::AssignXorExpr or
105-
this instanceof J::LShiftExpr or
106-
this instanceof J::AssignLShiftExpr or
107-
this instanceof J::RShiftExpr or
108-
this instanceof J::AssignRShiftExpr or
109-
this instanceof J::URShiftExpr or
110-
this instanceof J::AssignURShiftExpr
105+
this instanceof J::LeftShiftExpr or
106+
this instanceof J::AssignLeftShiftExpr or
107+
this instanceof J::RightShiftExpr or
108+
this instanceof J::AssignRightShiftExpr or
109+
this instanceof J::UnsignedRightShiftExpr or
110+
this instanceof J::AssignUnsignedRightShiftExpr
111111
}
112112

113113
/** Returns the operation representing this expression. */
@@ -144,17 +144,17 @@ module Private {
144144
or
145145
this instanceof J::AssignXorExpr and result = TBitXorOp()
146146
or
147-
this instanceof J::LShiftExpr and result = TLShiftOp()
147+
this instanceof J::LeftShiftExpr and result = TLeftShiftOp()
148148
or
149-
this instanceof J::AssignLShiftExpr and result = TLShiftOp()
149+
this instanceof J::AssignLeftShiftExpr and result = TLeftShiftOp()
150150
or
151-
this instanceof J::RShiftExpr and result = TRShiftOp()
151+
this instanceof J::RightShiftExpr and result = TRightShiftOp()
152152
or
153-
this instanceof J::AssignRShiftExpr and result = TRShiftOp()
153+
this instanceof J::AssignRightShiftExpr and result = TRightShiftOp()
154154
or
155-
this instanceof J::URShiftExpr and result = TURShiftOp()
155+
this instanceof J::UnsignedRightShiftExpr and result = TUnsignedRightShiftOp()
156156
or
157-
this instanceof J::AssignURShiftExpr and result = TURShiftOp()
157+
this instanceof J::AssignUnsignedRightShiftExpr and result = TUnsignedRightShiftOp()
158158
}
159159

160160
Expr getLeftOperand() {

java/ql/src/Likely Bugs/Arithmetic/LShiftLargerThanTypeWidth.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int integralTypeWidth(IntegralType t) {
1414
if t.hasName("long") or t.hasName("Long") then result = 64 else result = 32
1515
}
1616

17-
from LShiftExpr shift, IntegralType t, int v, string typname, int width
17+
from LeftShiftExpr shift, IntegralType t, int v, string typname, int width
1818
where
1919
shift.getLeftOperand().getType() = t and
2020
shift.getRightOperand().(CompileTimeConstantExpr).getIntValue() = v and

java/ql/src/Likely Bugs/Arithmetic/WhitespaceContradictsPrecedence.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class ArithmeticExpr extends BinaryExpr {
3333
*/
3434
class ShiftExpr extends BinaryExpr {
3535
ShiftExpr() {
36-
this instanceof LShiftExpr or
37-
this instanceof RShiftExpr or
38-
this instanceof URShiftExpr
36+
this instanceof LeftShiftExpr or
37+
this instanceof RightShiftExpr or
38+
this instanceof UnsignedRightShiftExpr
3939
}
4040
}
4141

java/ql/src/Likely Bugs/Comparison/UselessComparisonTest.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Expr overFlowCand() {
9999
|
100100
bin instanceof AddExpr or
101101
bin instanceof MulExpr or
102-
bin instanceof LShiftExpr
102+
bin instanceof LeftShiftExpr
103103
)
104104
or
105105
exists(AssignOp op |
@@ -109,7 +109,7 @@ Expr overFlowCand() {
109109
|
110110
op instanceof AssignAddExpr or
111111
op instanceof AssignMulExpr or
112-
op instanceof AssignLShiftExpr
112+
op instanceof AssignLeftShiftExpr
113113
)
114114
or
115115
exists(AddExpr add, CompileTimeConstantExpr c |

java/ql/src/Security/CWE/CWE-190/ArithmeticCommon.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ predicate upcastToWiderType(Expr e) {
153153
/** Holds if the result of `exp` has certain bits filtered by a bitwise and. */
154154
private predicate inBitwiseAnd(Expr exp) {
155155
exists(AndBitwiseExpr a | a.getAnOperand() = exp) or
156-
inBitwiseAnd(exp.(LShiftExpr).getAnOperand()) or
157-
inBitwiseAnd(exp.(RShiftExpr).getAnOperand()) or
158-
inBitwiseAnd(exp.(URShiftExpr).getAnOperand())
156+
inBitwiseAnd(exp.(LeftShiftExpr).getAnOperand()) or
157+
inBitwiseAnd(exp.(RightShiftExpr).getAnOperand()) or
158+
inBitwiseAnd(exp.(UnsignedRightShiftExpr).getAnOperand())
159159
}
160160

161161
/** Holds if overflow/underflow is irrelevant for this expression. */

0 commit comments

Comments
 (0)