@@ -256,6 +256,26 @@ predicate hasTranslatedLoad(Expr expr) {
256
256
not ignoreLoad ( expr )
257
257
}
258
258
259
+ /**
260
+ * Holds if the specified `DeclarationEntry` needs an IR translation. An IR translation is only
261
+ * necessary for automatic local variables, or for static local variables with dynamic
262
+ * initialization.
263
+ */
264
+ private predicate translateDeclarationEntry ( DeclarationEntry entry ) {
265
+ exists ( DeclStmt declStmt , LocalVariable var |
266
+ translateStmt ( declStmt ) and
267
+ declStmt .getADeclarationEntry ( ) = entry and
268
+ // Only declarations of local variables need to be translated to IR.
269
+ var = entry .getDeclaration ( ) and
270
+ (
271
+ not var .isStatic ( )
272
+ or
273
+ // Ignore static variables unless they have a dynamic initializer.
274
+ var .( StaticLocalVariable ) .hasDynamicInitialization ( )
275
+ )
276
+ )
277
+ }
278
+
259
279
newtype TTranslatedElement =
260
280
// An expression that is not being consumed as a condition
261
281
TTranslatedValueExpr ( Expr expr ) {
@@ -393,27 +413,12 @@ newtype TTranslatedElement =
393
413
)
394
414
} or
395
415
// A local declaration
396
- TTranslatedDeclarationEntry ( DeclarationEntry entry ) {
397
- exists ( DeclStmt declStmt , LocalVariable var |
398
- translateStmt ( declStmt ) and
399
- declStmt .getADeclarationEntry ( ) = entry and
400
- // Only declarations of local variables need to be translated to IR.
401
- var = entry .getDeclaration ( ) and
402
- (
403
- not var .isStatic ( )
404
- or
405
- // Ignore static variables unless they have a dynamic initializer.
406
- var .( StaticLocalVariable ) .hasDynamicInitialization ( )
407
- )
408
- )
409
- } or
416
+ TTranslatedDeclarationEntry ( DeclarationEntry entry ) { translateDeclarationEntry ( entry ) } or
410
417
// The dynamic initialization of a static local variable. This is a separate object from the
411
418
// declaration entry.
412
419
TTranslatedStaticLocalVariableInitialization ( DeclarationEntry entry ) {
413
- exists ( TTranslatedDeclarationEntry translatedEntry |
414
- translatedEntry = TTranslatedDeclarationEntry ( entry ) and
415
- entry .getDeclaration ( ) instanceof StaticLocalVariable
416
- )
420
+ translateDeclarationEntry ( entry ) and
421
+ entry .getDeclaration ( ) instanceof StaticLocalVariable
417
422
} or
418
423
// A compiler-generated variable to implement a range-based for loop. These don't have a
419
424
// `DeclarationEntry` in the database, so we have to go by the `Variable` itself.
0 commit comments