Skip to content

Commit c88db42

Browse files
authored
Merge pull request #343 from geoffw0/av-35-1.18
CPP: Fix hasXMacro performance.
2 parents 3522200 + de15560 commit c88db42

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

cpp/ql/src/jsf/4.07 Header Files/AV Rule 35.ql

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,17 @@ predicate defUndef(File f, string macroName) {
107107
}
108108

109109
/**
110-
* Header file `hf` looks like it contains an x-macro called
111-
* `macroName`. That is, a macro that is used to interpret the
110+
* Header file `hf` looks like it contains an x-macro.
111+
* That is, a macro that is used to interpret the
112112
* data in `hf`, usually defined just before including that file
113113
* and undefined immediately afterwards.
114114
*/
115-
predicate hasXMacro(HeaderFile hf, string macroName) {
116-
usesMacro(hf, macroName) and
117-
forex(Include i | i.getIncludedFile() = hf |
118-
defUndef(i.getFile(), macroName)
115+
predicate hasXMacro(HeaderFile hf) {
116+
exists(string macroName |
117+
usesMacro(hf, macroName) and
118+
forex(File f | f.getAnIncludedFile() = hf |
119+
defUndef(f, macroName)
120+
)
119121
)
120122
}
121123

@@ -135,7 +137,7 @@ where not hf instanceof IncludeGuardedHeader
135137
exists(UsingEntry ue | ue.getFile() = hf)
136138
)
137139
// Exclude files which look like they contain 'x-macros'
138-
and not hasXMacro(hf, _)
140+
and not hasXMacro(hf)
139141
// Exclude files which are always #imported.
140142
and not forex(Include i | i.getIncludedFile() = hf | i instanceof Import)
141143
// Exclude files which are only included once.

0 commit comments

Comments
 (0)