@@ -7,6 +7,7 @@ private import semmle.code.cpp.ir.IR as IR
7
7
private import Semantic
8
8
private import experimental.semmle.code.cpp.rangeanalysis.Bound as IRBound
9
9
private import semmle.code.cpp.controlflow.IRGuards as IRGuards
10
+ private import semmle.code.cpp.ir.ValueNumbering
10
11
11
12
module SemanticExprConfig {
12
13
class Location = Cpp:: Location ;
@@ -119,8 +120,17 @@ module SemanticExprConfig {
119
120
int getBasicBlockUniqueId ( BasicBlock block ) { idOf ( block .getFirstInstruction ( ) .getAst ( ) , result ) }
120
121
121
122
newtype TSsaVariable =
122
- TSsaInstruction ( IR:: Instruction instr ) { instr .hasMemoryResult ( ) } or
123
- TSsaOperand ( IR:: Operand op ) { op .isDefinitionInexact ( ) }
123
+ TSsaInstruction ( IR:: Instruction instr ) {
124
+ instr .hasMemoryResult ( )
125
+ } or
126
+ TSsaOperand ( IR:: Operand op ) { op .isDefinitionInexact ( ) } or
127
+ TSsaPointerArithmeticGuard ( IR:: PointerArithmeticInstruction instr ) {
128
+ exists ( Guard g , IR:: Operand use | use = instr .getAUse ( ) |
129
+ g .comparesLt ( use , _, _, _, _) or
130
+ g .comparesLt ( _, use , _, _, _) or
131
+ g .comparesEq ( use , _, _, _, _) or
132
+ g .comparesEq ( _, use , _, _, _) )
133
+ }
124
134
125
135
class SsaVariable extends TSsaVariable {
126
136
string toString ( ) { none ( ) }
@@ -129,6 +139,8 @@ module SemanticExprConfig {
129
139
130
140
IR:: Instruction asInstruction ( ) { none ( ) }
131
141
142
+ IR:: PointerArithmeticInstruction asPointerArithGuard ( ) { none ( ) }
143
+
132
144
IR:: Operand asOperand ( ) { none ( ) }
133
145
}
134
146
@@ -144,6 +156,18 @@ module SemanticExprConfig {
144
156
final override IR:: Instruction asInstruction ( ) { result = instr }
145
157
}
146
158
159
+ class SsaPointerArithmeticGuard extends SsaVariable , TSsaPointerArithmeticGuard {
160
+ IR:: PointerArithmeticInstruction instr ;
161
+
162
+ SsaPointerArithmeticGuard ( ) { this = TSsaPointerArithmeticGuard ( instr ) }
163
+
164
+ final override string toString ( ) { result = instr .toString ( ) }
165
+
166
+ final override Location getLocation ( ) { result = instr .getLocation ( ) }
167
+
168
+ final override IR:: PointerArithmeticInstruction asPointerArithGuard ( ) { result = instr }
169
+ }
170
+
147
171
class SsaOperand extends SsaVariable , TSsaOperand {
148
172
IR:: Operand op ;
149
173
@@ -168,7 +192,11 @@ module SemanticExprConfig {
168
192
)
169
193
}
170
194
171
- Expr getAUse ( SsaVariable v ) { result .( IR:: LoadInstruction ) .getSourceValue ( ) = v .asInstruction ( ) }
195
+ Expr getAUse ( SsaVariable v ) {
196
+ result .( IR:: LoadInstruction ) .getSourceValue ( ) = v .asInstruction ( )
197
+ or
198
+ result = valueNumber ( v .asPointerArithGuard ( ) ) .getAnInstruction ( )
199
+ }
172
200
173
201
SemType getSsaVariableType ( SsaVariable v ) {
174
202
result = getSemanticType ( v .asInstruction ( ) .getResultIRType ( ) )
@@ -208,7 +236,9 @@ module SemanticExprConfig {
208
236
209
237
final override predicate hasRead ( SsaVariable v ) {
210
238
exists ( IR:: Operand operand |
211
- operand .getDef ( ) = v .asInstruction ( ) and
239
+ operand .getDef ( ) = v .asInstruction ( ) or
240
+ operand .getDef ( ) = valueNumber ( v .asPointerArithGuard ( ) ) .getAnInstruction ( )
241
+ |
212
242
not operand instanceof IR:: PhiInputOperand and
213
243
operand .getUse ( ) .getBlock ( ) = block
214
244
)
@@ -227,7 +257,9 @@ module SemanticExprConfig {
227
257
228
258
final override predicate hasRead ( SsaVariable v ) {
229
259
exists ( IR:: PhiInputOperand operand |
230
- operand .getDef ( ) = v .asInstruction ( ) and
260
+ operand .getDef ( ) = v .asInstruction ( ) or
261
+ operand .getDef ( ) = valueNumber ( v .asPointerArithGuard ( ) ) .getAnInstruction ( )
262
+ |
231
263
operand .getPredecessorBlock ( ) = pred and
232
264
operand .getUse ( ) .getBlock ( ) = succ
233
265
)
0 commit comments