File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
cpp/ql/lib/semmle/code/cpp/ir
implementation/raw/internal Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -1088,15 +1088,31 @@ private module GetConvertedResultExpression {
1088
1088
}
1089
1089
1090
1090
private Expr getConvertedResultExpressionImpl0 ( Instruction instr ) {
1091
+ // For an expression such as `i += 2` we pretend that the generated
1092
+ // `StoreInstruction` contains the result of the expression even though
1093
+ // this isn't totally aligned with the C/C++ standard.
1091
1094
exists ( TranslatedAssignOperation tao |
1092
1095
result = tao .getExpr ( ) and
1093
1096
instr = tao .getInstruction ( any ( AssignmentStoreTag tag ) )
1094
1097
)
1095
1098
or
1099
+ // Similarly for `i++` and `++i` we pretend that the generated
1100
+ // `StoreInstruction` is contains the result of the expression even though
1101
+ // this isn't totally aligned with the C/C++ standard.
1096
1102
exists ( TranslatedCrementOperation tco |
1097
1103
result = tco .getExpr ( ) and
1098
1104
instr = tco .getInstruction ( any ( CrementStoreTag tag ) )
1099
1105
)
1106
+ or
1107
+ // IR construction inserts an additional cast to a `size_t` on the extent
1108
+ // of a `new[]` expression. The resulting `ConvertInstruction` doesn't have
1109
+ // a result for `getConvertedResultExpression`. We remap this here so that
1110
+ // this `ConvertInstruction` maps to the result of the expression that
1111
+ // represents the extent.
1112
+ exists ( TranslatedNonConstantAllocationSize tas |
1113
+ result = tas .getExtent ( ) .getExpr ( ) and
1114
+ instr = tas .getInstruction ( any ( AllocationExtentConvertTag tag ) )
1115
+ )
1100
1116
}
1101
1117
1102
1118
private Expr getConvertedResultExpressionImpl ( Instruction instr ) {
Original file line number Diff line number Diff line change @@ -1956,9 +1956,7 @@ class TranslatedNonConstantAllocationSize extends TranslatedAllocationSize {
1956
1956
result = this .getExtent ( ) .getResult ( )
1957
1957
}
1958
1958
1959
- private TranslatedExpr getExtent ( ) {
1960
- result = getTranslatedExpr ( expr .getExtent ( ) .getFullyConverted ( ) )
1961
- }
1959
+ TranslatedExpr getExtent ( ) { result = getTranslatedExpr ( expr .getExtent ( ) .getFullyConverted ( ) ) }
1962
1960
}
1963
1961
1964
1962
/**
You can’t perform that action at this time.
0 commit comments