@@ -4,6 +4,7 @@ private import semmle.code.cpp.ir.implementation.internal.OperandTag
4
4
private import semmle.code.cpp.ir.internal.CppType
5
5
private import semmle.code.cpp.models.interfaces.SideEffect
6
6
private import InstructionTag
7
+ private import SideEffects
7
8
private import TranslatedElement
8
9
private import TranslatedExpr
9
10
private import TranslatedFunction
@@ -424,12 +425,15 @@ class TranslatedCallSideEffects extends TranslatedSideEffects, TTranslatedCallSi
424
425
}
425
426
426
427
class TranslatedStructorCallSideEffects extends TranslatedCallSideEffects {
427
- TranslatedStructorCallSideEffects ( ) { getParent ( ) .( TranslatedStructorCall ) .hasQualifier ( ) }
428
+ TranslatedStructorCallSideEffects ( ) {
429
+ getParent ( ) .( TranslatedStructorCall ) .hasQualifier ( ) and
430
+ getASideEffectOpcode ( expr , - 1 ) instanceof WriteSideEffectOpcode
431
+ }
428
432
429
433
override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType t ) {
430
- opcode instanceof Opcode:: IndirectMayWriteSideEffect and
431
434
tag instanceof OnlyInstructionTag and
432
- t = getTypeForPRValue ( expr .getTarget ( ) .getDeclaringType ( ) )
435
+ t = getTypeForPRValue ( expr .getTarget ( ) .getDeclaringType ( ) ) and
436
+ opcode = getASideEffectOpcode ( expr , - 1 ) .( WriteSideEffectOpcode )
433
437
}
434
438
435
439
override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
@@ -460,9 +464,11 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
460
464
Call call ;
461
465
Expr arg ;
462
466
int index ;
463
- boolean write ;
467
+ SideEffectOpcode sideEffectOpcode ;
464
468
465
- TranslatedSideEffect ( ) { this = TTranslatedArgumentSideEffect ( call , arg , index , write ) }
469
+ TranslatedSideEffect ( ) {
470
+ this = TTranslatedArgumentSideEffect ( call , arg , index , sideEffectOpcode )
471
+ }
466
472
467
473
override Locatable getAST ( ) { result = arg }
468
474
@@ -472,13 +478,13 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
472
478
473
479
int getArgumentIndex ( ) { result = index }
474
480
475
- predicate isWrite ( ) { write = true }
481
+ predicate isWrite ( ) { sideEffectOpcode instanceof WriteSideEffectOpcode }
476
482
477
483
override string toString ( ) {
478
- write = true and
484
+ isWrite ( ) and
479
485
result = "(write side effect for " + arg .toString ( ) + ")"
480
486
or
481
- write = false and
487
+ not isWrite ( ) and
482
488
result = "(read side effect for " + arg .toString ( ) + ")"
483
489
}
484
490
@@ -489,29 +495,31 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
489
495
override Instruction getFirstInstruction ( ) { result = getInstruction ( OnlyInstructionTag ( ) ) }
490
496
491
497
override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType type ) {
492
- isWrite ( ) and
493
- hasSpecificWriteSideEffect ( opcode ) and
494
- tag = OnlyInstructionTag ( ) and
495
498
(
496
- opcode instanceof BufferAccessOpcode and
497
- type = getUnknownType ( )
498
- or
499
- not opcode instanceof BufferAccessOpcode and
500
- exists ( Type baseType | baseType = arg .getUnspecifiedType ( ) .( DerivedType ) .getBaseType ( ) |
501
- if baseType instanceof VoidType
502
- then type = getUnknownType ( )
503
- else type = getTypeForPRValueOrUnknown ( baseType )
499
+ tag = OnlyInstructionTag ( ) and
500
+ opcode = sideEffectOpcode
501
+ ) and
502
+ (
503
+ isWrite ( ) and
504
+ (
505
+ opcode instanceof BufferAccessOpcode and
506
+ type = getUnknownType ( )
507
+ or
508
+ not opcode instanceof BufferAccessOpcode and
509
+ exists ( Type baseType | baseType = arg .getUnspecifiedType ( ) .( DerivedType ) .getBaseType ( ) |
510
+ if baseType instanceof VoidType
511
+ then type = getUnknownType ( )
512
+ else type = getTypeForPRValueOrUnknown ( baseType )
513
+ )
514
+ or
515
+ index = - 1 and
516
+ not arg .getUnspecifiedType ( ) instanceof DerivedType and
517
+ type = getTypeForPRValueOrUnknown ( arg .getUnspecifiedType ( ) )
504
518
)
505
519
or
506
- index = - 1 and
507
- not arg .getUnspecifiedType ( ) instanceof DerivedType and
508
- type = getTypeForPRValueOrUnknown ( arg .getUnspecifiedType ( ) )
520
+ not isWrite ( ) and
521
+ type = getVoidType ( )
509
522
)
510
- or
511
- not isWrite ( ) and
512
- hasSpecificReadSideEffect ( opcode ) and
513
- tag = OnlyInstructionTag ( ) and
514
- type = getVoidType ( )
515
523
}
516
524
517
525
override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
@@ -535,7 +543,7 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
535
543
536
544
override CppType getInstructionMemoryOperandType ( InstructionTag tag , TypedOperandTag operandTag ) {
537
545
not isWrite ( ) and
538
- if hasSpecificReadSideEffect ( any ( BufferAccessOpcode op ) )
546
+ if sideEffectOpcode instanceof BufferAccessOpcode
539
547
then
540
548
result = getUnknownType ( ) and
541
549
tag instanceof OnlyInstructionTag and
@@ -557,56 +565,6 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
557
565
)
558
566
}
559
567
560
- predicate hasSpecificWriteSideEffect ( Opcode op ) {
561
- exists ( boolean buffer , boolean mustWrite |
562
- if exists ( call .getTarget ( ) .( SideEffectFunction ) .getParameterSizeIndex ( index ) )
563
- then
564
- call .getTarget ( ) .( SideEffectFunction ) .hasSpecificWriteSideEffect ( index , true , mustWrite ) and
565
- buffer = true and
566
- (
567
- mustWrite = false and op instanceof Opcode:: SizedBufferMayWriteSideEffect
568
- or
569
- mustWrite = true and op instanceof Opcode:: SizedBufferMustWriteSideEffect
570
- )
571
- else (
572
- call .getTarget ( ) .( SideEffectFunction ) .hasSpecificWriteSideEffect ( index , buffer , mustWrite ) and
573
- (
574
- buffer = true and mustWrite = false and op instanceof Opcode:: BufferMayWriteSideEffect
575
- or
576
- buffer = false and mustWrite = false and op instanceof Opcode:: IndirectMayWriteSideEffect
577
- or
578
- buffer = true and mustWrite = true and op instanceof Opcode:: BufferMustWriteSideEffect
579
- or
580
- buffer = false and mustWrite = true and op instanceof Opcode:: IndirectMustWriteSideEffect
581
- )
582
- )
583
- )
584
- or
585
- not call .getTarget ( ) instanceof SideEffectFunction and
586
- getArgumentIndex ( ) != - 1 and
587
- op instanceof Opcode:: BufferMayWriteSideEffect
588
- or
589
- not call .getTarget ( ) instanceof SideEffectFunction and
590
- getArgumentIndex ( ) = - 1 and
591
- op instanceof Opcode:: IndirectMayWriteSideEffect
592
- }
593
-
594
- predicate hasSpecificReadSideEffect ( Opcode op ) {
595
- exists ( boolean buffer |
596
- call .getTarget ( ) .( SideEffectFunction ) .hasSpecificReadSideEffect ( index , buffer ) and
597
- if exists ( call .getTarget ( ) .( SideEffectFunction ) .getParameterSizeIndex ( index ) )
598
- then buffer = true and op instanceof Opcode:: SizedBufferReadSideEffect
599
- else (
600
- buffer = true and op instanceof Opcode:: BufferReadSideEffect
601
- or
602
- buffer = false and op instanceof Opcode:: IndirectReadSideEffect
603
- )
604
- )
605
- or
606
- not call .getTarget ( ) instanceof SideEffectFunction and
607
- op instanceof Opcode:: BufferReadSideEffect
608
- }
609
-
610
568
override Instruction getPrimaryInstructionForSideEffect ( InstructionTag tag ) {
611
569
tag = OnlyInstructionTag ( ) and
612
570
result = getTranslatedCallInstruction ( call )
0 commit comments