@@ -65,28 +65,49 @@ class UnsafeMacro extends FunctionLikeMacro {
65
65
int getAnUnsafeArgumentIndex ( ) { result = unsafeArgumentIndex }
66
66
}
67
67
68
+ /**
69
+ * An invocation of a potentially unsafe macro.
70
+ */
71
+ class UnsafeMacroInvocation extends MacroInvocation {
72
+ UnsafeMacroInvocation ( ) {
73
+ this .getMacro ( ) instanceof UnsafeMacro and not exists ( this .getParentInvocation ( ) )
74
+ }
75
+
76
+ /**
77
+ * Gets a side-effect for a potentially unsafe argument to the macro.
78
+ */
79
+ SideEffect getSideEffectForUnsafeArg ( int index ) {
80
+ index = this .getMacro ( ) .( UnsafeMacro ) .getAnUnsafeArgumentIndex ( ) and
81
+ exists ( Expr e , string arg |
82
+ arg = this .getExpandedArgument ( index ) and
83
+ e = this .getAnExpandedElement ( ) and
84
+ result = getASideEffect ( e ) and
85
+ (
86
+ result instanceof CrementEffect and
87
+ exists ( arg .indexOf ( result .( CrementOperation ) .getOperator ( ) ) )
88
+ or
89
+ result instanceof FunctionCallEffect and
90
+ exists ( arg .indexOf ( result .( FunctionCall ) .getTarget ( ) .getName ( ) + "(" ) )
91
+ )
92
+ )
93
+ }
94
+ }
95
+
68
96
from
69
- UnsafeMacro flm , MacroInvocation mi , Expr e , SideEffect sideEffect , int i , string arg ,
70
- string sideEffectDesc
97
+ UnsafeMacroInvocation unsafeMacroInvocation , SideEffect sideEffect , int i , string sideEffectDesc
71
98
where
72
- not isExcluded ( e , SideEffects4Package:: sideEffectsInArgumentsToUnsafeMacrosQuery ( ) ) and
73
- sideEffect = getASideEffect ( e ) and
74
- flm .getAnInvocation ( ) = mi and
75
- not exists ( mi .getParentInvocation ( ) ) and
76
- mi .getAnExpandedElement ( ) = e and
77
- i = flm .getAnUnsafeArgumentIndex ( ) and
78
- arg = mi .getExpandedArgument ( i ) and
99
+ not isExcluded ( sideEffect , SideEffects4Package:: sideEffectsInArgumentsToUnsafeMacrosQuery ( ) ) and
100
+ sideEffect = unsafeMacroInvocation .getSideEffectForUnsafeArg ( i ) and
79
101
(
80
102
sideEffect instanceof CrementEffect and
81
- exists ( arg .indexOf ( sideEffect .( CrementOperation ) .getOperator ( ) ) ) and
82
103
sideEffectDesc = "the use of the " + sideEffect .( CrementOperation ) .getOperator ( ) + " operator"
83
104
or
84
105
sideEffect instanceof FunctionCallEffect and
85
- exists ( arg .indexOf ( sideEffect .( FunctionCall ) .getTarget ( ) .getName ( ) + "(" ) ) and
86
106
sideEffectDesc =
87
107
"a call to the function '" + sideEffect .( FunctionCall ) .getTarget ( ) .getName ( ) + "'"
88
108
)
89
109
select sideEffect ,
90
- "Argument " + mi .getUnexpandedArgument ( i ) + " to unsafe macro '" + flm .getName ( ) +
91
- "' is expanded to '" + arg + "' multiple times and includes " + sideEffectDesc +
92
- " as a side-effect."
110
+ "Argument " + unsafeMacroInvocation .getUnexpandedArgument ( i ) + " to unsafe macro '" +
111
+ unsafeMacroInvocation .getMacroName ( ) + "' is expanded to '" +
112
+ unsafeMacroInvocation .getExpandedArgument ( i ) + "' multiple times and includes " + sideEffectDesc
113
+ + " as a side-effect."
0 commit comments