Skip to content

Commit 4c8058d

Browse files
authored
Merge branch 'github:main' into couchdb
2 parents 1e1fb43 + 636bbe3 commit 4c8058d

File tree

848 files changed

+101164
-79235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

848 files changed

+101164
-79235
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Some constants will now be represented by their unfolded expression trees. The `isConstant` predicate of `Expr` will no longer yield a result for those constants.

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaImplCommon.qll

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -688,15 +688,9 @@ private module Cached {
688688
conversionFlow(mid, instr, false, _)
689689
)
690690
or
691-
exists(int ind0 |
692-
exists(Operand address |
693-
isDereference(operand.getDef(), address, _) and
694-
isUseImpl(address, base, ind0)
695-
)
696-
or
697-
isUseImpl(operand.getDef().(InitializeParameterInstruction).getAnOperand(), base, ind0)
698-
|
699-
ind0 = ind - 1
691+
exists(Operand address |
692+
isDereference(operand.getDef(), address, _) and
693+
isUseImpl(address, base, ind - 1)
700694
)
701695
}
702696

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2679,7 +2679,7 @@ class TranslatedDestructorFieldDestruction extends TranslatedNonConstantExpr, St
26792679
final override Instruction getInstructionRegisterOperand(InstructionTag tag, OperandTag operandTag) {
26802680
tag = OnlyInstructionTag() and
26812681
operandTag instanceof UnaryOperandTag and
2682-
result = getTranslatedFunction(getEnclosingFunction(expr)).getInitializeThisInstruction()
2682+
result = getTranslatedFunction(getEnclosingFunction(expr)).getLoadThisInstruction()
26832683
}
26842684

26852685
final override Field getInstructionField(InstructionTag tag) {

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedFunction.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,11 @@ class TranslatedFunction extends TranslatedRootElement, TTranslatedFunction {
306306
final predicate hasReturnValue() { hasReturnValue(func) }
307307

308308
/**
309-
* Gets the single `InitializeThis` instruction for this function. Holds only
310-
* if the function is an instance member function, constructor, or destructor.
309+
* Gets the first load of `this` for this function. Holds only if the function
310+
* is an instance member function, constructor, or destructor.
311311
*/
312-
final Instruction getInitializeThisInstruction() {
313-
result = getTranslatedThisParameter(func).getInstruction(InitializerStoreTag())
312+
final Instruction getLoadThisInstruction() {
313+
result = getTranslatedThisParameter(func).getInstruction(InitializerIndirectAddressTag())
314314
}
315315

316316
/**
@@ -639,7 +639,7 @@ class TranslatedConstructorInitList extends TranslatedElement, InitializationCon
639639
}
640640

641641
override Instruction getTargetAddress() {
642-
result = getTranslatedFunction(func).getInitializeThisInstruction()
642+
result = getTranslatedFunction(func).getLoadThisInstruction()
643643
}
644644

645645
override Type getTargetType() { result = getTranslatedFunction(func).getThisType() }

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedInitialization.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ abstract class TranslatedBaseStructorCall extends TranslatedStructorCallFromStru
950950
final override Instruction getInstructionRegisterOperand(InstructionTag tag, OperandTag operandTag) {
951951
tag = OnlyInstructionTag() and
952952
operandTag instanceof UnaryOperandTag and
953-
result = getTranslatedFunction(this.getFunction()).getInitializeThisInstruction()
953+
result = getTranslatedFunction(this.getFunction()).getLoadThisInstruction()
954954
}
955955

956956
final override predicate getInstructionInheritance(
@@ -1000,7 +1000,7 @@ class TranslatedConstructorDelegationInit extends TranslatedConstructorCallFromC
10001000
}
10011001

10021002
final override Instruction getReceiver() {
1003-
result = getTranslatedFunction(this.getFunction()).getInitializeThisInstruction()
1003+
result = getTranslatedFunction(this.getFunction()).getLoadThisInstruction()
10041004
}
10051005
}
10061006

cpp/ql/lib/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,6 @@ private class UnsignedBitwiseAndExpr extends BitwiseAndExpr {
158158
}
159159
}
160160

161-
/**
162-
* Gets the floor of `v`, with additional logic to work around issues with
163-
* large numbers.
164-
*/
165-
bindingset[v]
166-
float safeFloor(float v) {
167-
// return the floor of v
168-
v.abs() < 2.pow(31) and
169-
result = v.floor()
170-
or
171-
// `floor()` doesn't work correctly on large numbers (since it returns an integer),
172-
// so fall back to unrounded numbers at this scale.
173-
not v.abs() < 2.pow(31) and
174-
result = v
175-
}
176-
177161
/** A `MulExpr` where exactly one operand is constant. */
178162
private class MulByConstantExpr extends MulExpr {
179163
float constant;
@@ -1266,7 +1250,7 @@ private float getLowerBoundsImpl(Expr expr) {
12661250
rsExpr = expr and
12671251
left = getFullyConvertedLowerBounds(rsExpr.getLeftOperand()) and
12681252
right = getValue(rsExpr.getRightOperand().getFullyConverted()).toInt() and
1269-
result = safeFloor(left / 2.pow(right))
1253+
result = (left / 2.pow(right)).floorFloat()
12701254
)
12711255
// Not explicitly modeled by a SimpleRangeAnalysisExpr
12721256
) and
@@ -1475,7 +1459,7 @@ private float getUpperBoundsImpl(Expr expr) {
14751459
rsExpr = expr and
14761460
left = getFullyConvertedUpperBounds(rsExpr.getLeftOperand()) and
14771461
right = getValue(rsExpr.getRightOperand().getFullyConverted()).toInt() and
1478-
result = safeFloor(left / 2.pow(right))
1462+
result = (left / 2.pow(right)).floorFloat()
14791463
)
14801464
// Not explicitly modeled by a SimpleRangeAnalysisExpr
14811465
) and

cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.ql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,16 @@ import UnsignedGEZero
2525
//
2626
// So to reduce the number of false positives, we do not report a result if
2727
// the comparison is in a macro expansion. Similarly for template
28-
// instantiations.
28+
// instantiations, static asserts, non-type template arguments, enum constants,
29+
// and constexprs.
2930
from ComparisonOperation cmp, SmallSide ss, float left, float right, boolean value, string reason
3031
where
3132
not cmp.isInMacroExpansion() and
3233
not cmp.isFromTemplateInstantiation(_) and
34+
not exists(StaticAssert s | s.getCondition() = cmp.getParent*()) and
35+
not exists(Declaration d | d.getATemplateArgument() = cmp.getParent*()) and
36+
not exists(Variable v | v.isConstexpr() | v.getInitializer().getExpr() = cmp.getParent*()) and
37+
not exists(EnumConstant e | e.getInitializer().getExpr() = cmp.getParent*()) and
3338
not functionContainsDisabledCode(cmp.getEnclosingFunction()) and
3439
reachablePointlessComparison(cmp, left, right, value, ss) and
3540
// a comparison between an enum and zero is always valid because whether
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `cpp/constant-comparison` query has been updated to not produce false positives for constants that are now represented by their unfolded expression trees.

cpp/ql/test/library-tests/constants/addresses/addresses.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ void constantAddresses(int param) {
2626
constexpr int *array2d = &int_arr_arr[1][1] + 1;
2727
constexpr int *const_ints = &int_arr_arr[int_const][extern_int_const];
2828

29-
// Commented out because clang and EDG disagree on whether this is
30-
// constant.
31-
//constexpr int *stmtexpr_int = &int_arr[ ({ 1; }) ];
29+
constexpr int *stmtexpr_int = &int_arr[ ({ 1; }) ];
3230

3331
constexpr int *comma_int = &int_arr[ ((void)0, 1) ];
3432
constexpr int *comma_addr = ((void)0, &int_var);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| addresses.cpp:29:35:29:54 | & ... | stmtexpr_int | misclassified as NOT constant |
2+
| addresses.cpp:31:32:31:55 | & ... | comma_int | misclassified as NOT constant |
3+
| addresses.cpp:36:39:36:70 | ... ? ... : ... | ternary_ptr_cond | misclassified as NOT constant |
4+
| addresses.cpp:37:35:37:69 | & ... | ptr_subtract | misclassified as NOT constant |
5+
| addresses.cpp:39:35:39:50 | ... + ... | constexpr_va | misclassified as NOT constant |

0 commit comments

Comments
 (0)