Skip to content

Commit 4117252

Browse files
authored
Merge pull request #4 from github/main
update
2 parents fd8e170 + d048d39 commit 4117252

File tree

709 files changed

+65474
-45784
lines changed

Some content is hidden

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

709 files changed

+65474
-45784
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/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 |

cpp/ql/test/library-tests/dataflow/fields/ir-path-flow.expected

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ edges
193193
| C.cpp:18:12:18:18 | call to C [s3] | C.cpp:18:12:18:18 | *new [s3] | provenance | |
194194
| C.cpp:19:5:19:5 | *c [s1] | C.cpp:27:8:27:11 | *this [s1] | provenance | |
195195
| C.cpp:19:5:19:5 | *c [s3] | C.cpp:27:8:27:11 | *this [s3] | provenance | |
196+
| C.cpp:22:3:22:3 | *C [post update] [s1] | C.cpp:22:3:22:3 | *this [Return] [s1] | provenance | |
196197
| C.cpp:22:3:22:3 | *this [Return] [s1] | C.cpp:18:12:18:18 | call to C [s1] | provenance | |
197198
| C.cpp:22:3:22:3 | *this [Return] [s3] | C.cpp:18:12:18:18 | call to C [s3] | provenance | |
198-
| C.cpp:22:3:22:3 | *this [post update] [s1] | C.cpp:22:3:22:3 | *this [Return] [s1] | provenance | |
199-
| C.cpp:22:12:22:21 | new | C.cpp:22:3:22:3 | *this [post update] [s1] | provenance | |
199+
| C.cpp:22:12:22:21 | new | C.cpp:22:3:22:3 | *C [post update] [s1] | provenance | |
200200
| C.cpp:22:12:22:21 | new | C.cpp:22:12:22:21 | new | provenance | |
201201
| C.cpp:24:5:24:8 | *this [post update] [s3] | C.cpp:22:3:22:3 | *this [Return] [s3] | provenance | |
202202
| C.cpp:24:5:24:25 | ... = ... | C.cpp:24:5:24:8 | *this [post update] [s3] | provenance | |
@@ -736,12 +736,12 @@ edges
736736
| constructors.cpp:19:22:19:23 | *this [b_] | constructors.cpp:19:22:19:23 | b_ | provenance | |
737737
| constructors.cpp:19:22:19:23 | b_ | constructors.cpp:19:9:19:9 | *b | provenance | |
738738
| constructors.cpp:19:22:19:23 | b_ | constructors.cpp:19:22:19:23 | b_ | provenance | |
739-
| constructors.cpp:23:5:23:7 | *this [post update] [a_] | constructors.cpp:23:5:23:7 | *this [Return] [a_] | provenance | |
740-
| constructors.cpp:23:5:23:7 | *this [post update] [b_] | constructors.cpp:23:5:23:7 | *this [Return] [b_] | provenance | |
739+
| constructors.cpp:23:5:23:7 | *Foo [post update] [a_] | constructors.cpp:23:5:23:7 | *this [Return] [a_] | provenance | |
740+
| constructors.cpp:23:5:23:7 | *Foo [post update] [b_] | constructors.cpp:23:5:23:7 | *this [Return] [b_] | provenance | |
741741
| constructors.cpp:23:13:23:13 | a | constructors.cpp:23:28:23:28 | a | provenance | |
742742
| constructors.cpp:23:20:23:20 | b | constructors.cpp:23:35:23:35 | b | provenance | |
743-
| constructors.cpp:23:28:23:28 | a | constructors.cpp:23:5:23:7 | *this [post update] [a_] | provenance | |
744-
| constructors.cpp:23:35:23:35 | b | constructors.cpp:23:5:23:7 | *this [post update] [b_] | provenance | |
743+
| constructors.cpp:23:28:23:28 | a | constructors.cpp:23:5:23:7 | *Foo [post update] [a_] | provenance | |
744+
| constructors.cpp:23:35:23:35 | b | constructors.cpp:23:5:23:7 | *Foo [post update] [b_] | provenance | |
745745
| constructors.cpp:26:15:26:15 | *f [a_] | constructors.cpp:28:10:28:10 | *f [a_] | provenance | |
746746
| constructors.cpp:26:15:26:15 | *f [b_] | constructors.cpp:29:10:29:10 | *f [b_] | provenance | |
747747
| constructors.cpp:28:10:28:10 | *f [a_] | constructors.cpp:18:9:18:9 | *this [a_] | provenance | |
@@ -1122,9 +1122,9 @@ nodes
11221122
| C.cpp:18:12:18:18 | call to C [s3] | semmle.label | call to C [s3] |
11231123
| C.cpp:19:5:19:5 | *c [s1] | semmle.label | *c [s1] |
11241124
| C.cpp:19:5:19:5 | *c [s3] | semmle.label | *c [s3] |
1125+
| C.cpp:22:3:22:3 | *C [post update] [s1] | semmle.label | *C [post update] [s1] |
11251126
| C.cpp:22:3:22:3 | *this [Return] [s1] | semmle.label | *this [Return] [s1] |
11261127
| C.cpp:22:3:22:3 | *this [Return] [s3] | semmle.label | *this [Return] [s3] |
1127-
| C.cpp:22:3:22:3 | *this [post update] [s1] | semmle.label | *this [post update] [s1] |
11281128
| C.cpp:22:12:22:21 | new | semmle.label | new |
11291129
| C.cpp:22:12:22:21 | new | semmle.label | new |
11301130
| C.cpp:24:5:24:8 | *this [post update] [s3] | semmle.label | *this [post update] [s3] |
@@ -1678,10 +1678,10 @@ nodes
16781678
| constructors.cpp:19:22:19:23 | *this [b_] | semmle.label | *this [b_] |
16791679
| constructors.cpp:19:22:19:23 | b_ | semmle.label | b_ |
16801680
| constructors.cpp:19:22:19:23 | b_ | semmle.label | b_ |
1681+
| constructors.cpp:23:5:23:7 | *Foo [post update] [a_] | semmle.label | *Foo [post update] [a_] |
1682+
| constructors.cpp:23:5:23:7 | *Foo [post update] [b_] | semmle.label | *Foo [post update] [b_] |
16811683
| constructors.cpp:23:5:23:7 | *this [Return] [a_] | semmle.label | *this [Return] [a_] |
16821684
| constructors.cpp:23:5:23:7 | *this [Return] [b_] | semmle.label | *this [Return] [b_] |
1683-
| constructors.cpp:23:5:23:7 | *this [post update] [a_] | semmle.label | *this [post update] [a_] |
1684-
| constructors.cpp:23:5:23:7 | *this [post update] [b_] | semmle.label | *this [post update] [b_] |
16851685
| constructors.cpp:23:13:23:13 | a | semmle.label | a |
16861686
| constructors.cpp:23:20:23:20 | b | semmle.label | b |
16871687
| constructors.cpp:23:28:23:28 | a | semmle.label | a |

0 commit comments

Comments
 (0)