@@ -4,6 +4,7 @@ private import semmle.code.cpp.ir.implementation.internal.OperandTag
44private import semmle.code.cpp.ir.internal.CppType
55private import semmle.code.cpp.models.interfaces.SideEffect
66private import InstructionTag
7+ private import SideEffects
78private import TranslatedElement
89private import TranslatedExpr
910private import TranslatedFunction
@@ -424,12 +425,15 @@ class TranslatedCallSideEffects extends TranslatedSideEffects, TTranslatedCallSi
424425}
425426
426427class TranslatedStructorCallSideEffects extends TranslatedCallSideEffects {
427- TranslatedStructorCallSideEffects ( ) { getParent ( ) .( TranslatedStructorCall ) .hasQualifier ( ) }
428+ TranslatedStructorCallSideEffects ( ) {
429+ getParent ( ) .( TranslatedStructorCall ) .hasQualifier ( ) and
430+ getASideEffectOpcode ( expr , - 1 ) instanceof WriteSideEffectOpcode
431+ }
428432
429433 override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType t ) {
430- opcode instanceof Opcode:: IndirectMayWriteSideEffect and
431434 tag instanceof OnlyInstructionTag and
432- t = getTypeForPRValue ( expr .getTarget ( ) .getDeclaringType ( ) )
435+ t = getTypeForPRValue ( expr .getTarget ( ) .getDeclaringType ( ) ) and
436+ opcode = getASideEffectOpcode ( expr , - 1 ) .( WriteSideEffectOpcode )
433437 }
434438
435439 override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
@@ -460,9 +464,11 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
460464 Call call ;
461465 Expr arg ;
462466 int index ;
463- boolean write ;
467+ SideEffectOpcode sideEffectOpcode ;
464468
465- TranslatedSideEffect ( ) { this = TTranslatedArgumentSideEffect ( call , arg , index , write ) }
469+ TranslatedSideEffect ( ) {
470+ this = TTranslatedArgumentSideEffect ( call , arg , index , sideEffectOpcode )
471+ }
466472
467473 override Locatable getAST ( ) { result = arg }
468474
@@ -472,13 +478,13 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
472478
473479 int getArgumentIndex ( ) { result = index }
474480
475- predicate isWrite ( ) { write = true }
481+ predicate isWrite ( ) { sideEffectOpcode instanceof WriteSideEffectOpcode }
476482
477483 override string toString ( ) {
478- write = true and
484+ isWrite ( ) and
479485 result = "(write side effect for " + arg .toString ( ) + ")"
480486 or
481- write = false and
487+ not isWrite ( ) and
482488 result = "(read side effect for " + arg .toString ( ) + ")"
483489 }
484490
@@ -489,29 +495,31 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
489495 override Instruction getFirstInstruction ( ) { result = getInstruction ( OnlyInstructionTag ( ) ) }
490496
491497 override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType type ) {
492- isWrite ( ) and
493- hasSpecificWriteSideEffect ( opcode ) and
494- tag = OnlyInstructionTag ( ) and
495498 (
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 ( ) )
504518 )
505519 or
506- index = - 1 and
507- not arg .getUnspecifiedType ( ) instanceof DerivedType and
508- type = getTypeForPRValueOrUnknown ( arg .getUnspecifiedType ( ) )
520+ not isWrite ( ) and
521+ type = getVoidType ( )
509522 )
510- or
511- not isWrite ( ) and
512- hasSpecificReadSideEffect ( opcode ) and
513- tag = OnlyInstructionTag ( ) and
514- type = getVoidType ( )
515523 }
516524
517525 override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
@@ -535,7 +543,7 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
535543
536544 override CppType getInstructionMemoryOperandType ( InstructionTag tag , TypedOperandTag operandTag ) {
537545 not isWrite ( ) and
538- if hasSpecificReadSideEffect ( any ( BufferAccessOpcode op ) )
546+ if sideEffectOpcode instanceof BufferAccessOpcode
539547 then
540548 result = getUnknownType ( ) and
541549 tag instanceof OnlyInstructionTag and
@@ -557,56 +565,6 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
557565 )
558566 }
559567
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-
610568 override Instruction getPrimaryInstructionForSideEffect ( InstructionTag tag ) {
611569 tag = OnlyInstructionTag ( ) and
612570 result = getTranslatedCallInstruction ( call )
0 commit comments