mirror of
https://github.com/github/codeql.git
synced 2026-01-07 03:30:24 +01:00
CPP: Resolve #endif FPs.
This commit is contained in:
@@ -47,12 +47,27 @@ private predicate looksLikeCode(string line) {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if there is a preprocessor directive on the line indicated by
|
||||
* `f` and `line`.
|
||||
*/
|
||||
private predicate preprocLine(File f, int line) {
|
||||
exists(PreprocessorDirective pd, Location l |
|
||||
pd.getLocation() = l and
|
||||
l.getFile() = f and
|
||||
l.getStartLine() = line
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The line of a C++-style comment within its file `f`.
|
||||
*/
|
||||
private int lineInFile(CppStyleComment c, File f) {
|
||||
f = c.getFile() and
|
||||
result = c.getLocation().getStartLine()
|
||||
result = c.getLocation().getStartLine() and
|
||||
|
||||
// Ignore comments on the same line as a preprocessor directive.
|
||||
not preprocLine(f, result)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,9 +104,17 @@ private int commentId(CppStyleComment c, File f, int line) {
|
||||
*/
|
||||
class CommentBlock extends Comment {
|
||||
CommentBlock() {
|
||||
this instanceof CppStyleComment
|
||||
implies
|
||||
not exists(CppStyleComment pred, File f | lineInFile(pred, f) + 1 = lineInFile(this, f))
|
||||
(
|
||||
this instanceof CppStyleComment
|
||||
implies
|
||||
not exists(CppStyleComment pred, File f | lineInFile(pred, f) + 1 = lineInFile(this, f))
|
||||
) and (
|
||||
// Ignore comments on the same line as a preprocessor directive.
|
||||
not exists(Location l |
|
||||
l = this.getLocation() and
|
||||
preprocLine(l.getFile(), l.getStartLine())
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user