@@ -434,6 +434,50 @@ module SemanticExprConfig {
434
434
435
435
/** Gets the expression associated with `instr`. */
436
436
SemExpr getSemanticExpr ( IR:: Instruction instr ) { result = Equiv:: getEquivalenceClass ( instr ) }
437
+
438
+ private predicate typeBounds ( SemType t , float lb , float ub ) {
439
+ exists ( SemIntegerType integralType , float limit |
440
+ integralType = t and limit = 2 .pow ( 8 * integralType .getByteSize ( ) )
441
+ |
442
+ if integralType instanceof SemBooleanType
443
+ then lb = 0 and ub = 1
444
+ else
445
+ if integralType .isSigned ( )
446
+ then (
447
+ lb = - ( limit / 2 ) and ub = ( limit / 2 ) - 1
448
+ ) else (
449
+ lb = 0 and ub = limit - 1
450
+ )
451
+ )
452
+ or
453
+ // This covers all floating point types. The range is (-Inf, +Inf).
454
+ t instanceof SemFloatingPointType and lb = - ( 1.0 / 0.0 ) and ub = 1.0 / 0.0
455
+ }
456
+
457
+ /**
458
+ * Holds if `upper = true` and `e <= bound` or `upper = false` and `e >= bound` based
459
+ * only on type information.
460
+ */
461
+ predicate hasConstantBoundConstantSpecific ( Expr e , float bound , boolean upper ) {
462
+ exists (
463
+ SemType converted , SemType unconverted , float unconvertedLb , float convertedLb ,
464
+ float unconvertedUb , float convertedUb
465
+ |
466
+ unconverted = getSemanticType ( e .getUnconverted ( ) .getResultIRType ( ) ) and
467
+ converted = getSemanticType ( e .getConverted ( ) .getResultIRType ( ) ) and
468
+ typeBounds ( unconverted , unconvertedLb , unconvertedUb ) and
469
+ typeBounds ( converted , convertedLb , convertedUb ) and
470
+ (
471
+ upper = true and
472
+ unconvertedUb < convertedUb and
473
+ bound = unconvertedUb
474
+ or
475
+ upper = false and
476
+ unconvertedLb > convertedLb and
477
+ bound = unconvertedLb
478
+ )
479
+ )
480
+ }
437
481
}
438
482
439
483
predicate getSemanticExpr = SemanticExprConfig:: getSemanticExpr / 1 ;
@@ -457,3 +501,5 @@ IRBound::Bound getCppBound(SemBound bound) { bound = result }
457
501
SemGuard getSemanticGuard ( IRGuards:: IRGuardCondition guard ) { result = guard }
458
502
459
503
IRGuards:: IRGuardCondition getCppGuard ( SemGuard guard ) { guard = result }
504
+
505
+ predicate hasConstantBoundConstantSpecific = SemanticExprConfig:: hasConstantBoundConstantSpecific / 3 ;
0 commit comments