Skip to content

Commit 3b6b404

Browse files
committed
Merge branch 'main' into topPack
2 parents af5a617 + 801eb53 commit 3b6b404

File tree

462 files changed

+8947
-1315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

462 files changed

+8947
-1315
lines changed

.github/workflows/check-change-note.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
name: Check change note
2+
13
on:
24
pull_request_target:
35
types: [labeled, unlabeled, opened, synchronize, reopened, ready_for_review]

.github/workflows/docs-review.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

cpp/autobuilder/Semmle.Autobuild.Cpp/Semmle.Autobuild.Cpp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.Build" Version="16.0.461" />
20+
<PackageReference Include="Microsoft.Build" Version="16.9.0" />
2121
</ItemGroup>
2222

2323
<ItemGroup>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* The 'Resource not released in destructor' (cpp/resource-not-released-in-destructor) query has been improved to recognize more releases of resources.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @name Extraction errors
3+
* @description List all extraction errors for files in the source code directory.
4+
* @kind diagnostic
5+
* @id cpp/diagnostics/extraction-errors
6+
*/
7+
8+
import cpp
9+
import ExtractionErrors
10+
11+
from ExtractionError error
12+
where
13+
error instanceof ExtractionUnknownError or
14+
exists(error.getFile().getRelativePath())
15+
select error, "Extraction failed in " + error.getFile() + " with error " + error.getErrorMessage(),
16+
error.getSeverity()
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/**
2+
* Provides a common hierarchy of all types of errors that can occur during extraction.
3+
*/
4+
5+
import cpp
6+
7+
/*
8+
* A note about how the C/C++ extractor emits diagnostics:
9+
* When the extractor frontend encounters an error, it emits a diagnostic message,
10+
* that includes a message, location and severity.
11+
* However, that process is best-effort and may fail (e.g. due to lack of memory).
12+
* Thus, if the extractor emitted at least one diagnostic of severity discretionary
13+
* error (or higher), it *also* emits a simple "There was an error during this compilation"
14+
* error diagnostic, without location information.
15+
* In the common case, this means that a compilation during which one or more errors happened also gets
16+
* the catch-all diagnostic.
17+
* This diagnostic has the empty string as file path.
18+
* We filter out these useless diagnostics if there is at least one error-level diagnostic
19+
* for the affected compilation in the database.
20+
* Otherwise, we show it to indicate that something went wrong and that we
21+
* don't know what exactly happened.
22+
*/
23+
24+
/**
25+
* An error that, if present, leads to a file being marked as non-successfully extracted.
26+
*/
27+
class ReportableError extends Diagnostic {
28+
ReportableError() {
29+
(
30+
this instanceof CompilerDiscretionaryError or
31+
this instanceof CompilerError or
32+
this instanceof CompilerCatastrophe
33+
) and
34+
// Filter for the catch-all diagnostic, see note above.
35+
not this.getFile().getAbsolutePath() = ""
36+
}
37+
}
38+
39+
private newtype TExtractionError =
40+
TReportableError(ReportableError err) or
41+
TCompilationFailed(Compilation c, File f) {
42+
f = c.getAFileCompiled() and not c.normalTermination()
43+
} or
44+
// Show the catch-all diagnostic (see note above) only if we haven't seen any other error-level diagnostic
45+
// for that compilation
46+
TUnknownError(CompilerError err) {
47+
not exists(ReportableError e | e.getCompilation() = err.getCompilation())
48+
}
49+
50+
/**
51+
* Superclass for the extraction error hierarchy.
52+
*/
53+
class ExtractionError extends TExtractionError {
54+
/** Gets the string representation of the error. */
55+
string toString() { none() }
56+
57+
/** Gets the error message for this error. */
58+
string getErrorMessage() { none() }
59+
60+
/** Gets the file this error occured in. */
61+
File getFile() { none() }
62+
63+
/** Gets the location this error occured in. */
64+
Location getLocation() { none() }
65+
66+
/** Gets the SARIF severity of this error. */
67+
int getSeverity() {
68+
// Unfortunately, we can't distinguish between errors and fatal errors in SARIF,
69+
// so all errors have severity 2.
70+
result = 2
71+
}
72+
}
73+
74+
/**
75+
* An unrecoverable extraction error, where extraction was unable to finish.
76+
* This can be caused by a multitude of reasons, for example:
77+
* - hitting a frontend assertion
78+
* - crashing due to dereferencing an invalid pointer
79+
* - stack overflow
80+
* - out of memory
81+
*/
82+
class ExtractionUnrecoverableError extends ExtractionError, TCompilationFailed {
83+
Compilation c;
84+
File f;
85+
86+
ExtractionUnrecoverableError() { this = TCompilationFailed(c, f) }
87+
88+
override string toString() {
89+
result = "Unrecoverable extraction error while compiling " + f.toString()
90+
}
91+
92+
override string getErrorMessage() { result = "unrecoverable compilation failure." }
93+
94+
override File getFile() { result = f }
95+
96+
override Location getLocation() { result = f.getLocation() }
97+
}
98+
99+
/**
100+
* A recoverable extraction error.
101+
* These are compiler errors from the frontend.
102+
* Upon encountering one of these, we still continue extraction, but the
103+
* database will be incomplete for that file.
104+
*/
105+
class ExtractionRecoverableError extends ExtractionError, TReportableError {
106+
ReportableError err;
107+
108+
ExtractionRecoverableError() { this = TReportableError(err) }
109+
110+
override string toString() { result = "Recoverable extraction error: " + err }
111+
112+
override string getErrorMessage() { result = err.getFullMessage() }
113+
114+
override File getFile() { result = err.getFile() }
115+
116+
override Location getLocation() { result = err.getLocation() }
117+
}
118+
119+
/**
120+
* An unknown error happened during extraction.
121+
* These are only displayed if we know that we encountered an error during extraction,
122+
* but, for some reason, failed to emit a proper diagnostic with location information
123+
* and error message.
124+
*/
125+
class ExtractionUnknownError extends ExtractionError, TUnknownError {
126+
CompilerError err;
127+
128+
ExtractionUnknownError() { this = TUnknownError(err) }
129+
130+
override string toString() { result = "Unknown extraction error: " + err }
131+
132+
override string getErrorMessage() { result = err.getFullMessage() }
133+
134+
override File getFile() { result = err.getFile() }
135+
136+
override Location getLocation() { result = err.getLocation() }
137+
}

cpp/ql/src/Diagnostics/FailedExtractions.ql renamed to cpp/ql/src/Diagnostics/FailedExtractorInvocations.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* @name Failed extractions
3-
* @description Gives the command-line of compilations for which extraction did not run to completion.
2+
* @name Failed extractor invocations
3+
* @description Gives the command line of compilations for which extraction did not run to completion.
44
* @kind diagnostic
5-
* @id cpp/diagnostics/failed-extractions
5+
* @id cpp/diagnostics/failed-extractor-invocations
66
*/
77

88
import cpp
@@ -19,4 +19,4 @@ string describe(Compilation c) {
1919

2020
from Compilation c
2121
where not c.normalTermination()
22-
select c, "Extraction failed for " + describe(c), 2
22+
select c, "Extraction aborted for " + describe(c), 2
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @name Successfully extracted files
3+
* @description Lists all files in the source code directory that were extracted without encountering an error in the file.
4+
* @kind diagnostic
5+
* @id cpp/diagnostics/successfully-extracted-files
6+
*/
7+
8+
import cpp
9+
import ExtractionErrors
10+
11+
from File f
12+
where
13+
not exists(ExtractionError e | e.getFile() = f) and
14+
exists(f.getRelativePath())
15+
select f, ""

cpp/ql/src/Summary/LinesOfCode.ql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @id cpp/summary/lines-of-code
3+
* @name Total lines of C/C++ code in the database
4+
* @description The total number of lines of C/C++ code across all files, including system headers, libraries, and auto-generated files. This is a useful metric of the size of a database. For all files that were seen during the build, this query counts the lines of code, excluding whitespace or comments.
5+
* @kind metric
6+
* @tags summary
7+
*/
8+
9+
import cpp
10+
11+
select sum(File f | f.fromSource() | f.getMetrics().getNumberOfLinesOfCode())

cpp/ql/src/jsf/4.10 Classes/AV Rule 79.ql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import cpp
1515
import Critical.NewDelete
16+
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
1617

1718
/**
1819
* An expression that acquires a resource, and the kind of resource that is acquired. The
@@ -98,7 +99,8 @@ private predicate exprReleases(Expr e, Expr released, string kind) {
9899
e.(FunctionCall).getTarget().(MemberFunction).getAnOverridingFunction+() = f
99100
) and
100101
e.(FunctionCall).getArgument(arg) = released and
101-
exprReleases(_, exprOrDereference(f.getParameter(arg).getAnAccess()), kind)
102+
exprReleases(_,
103+
exprOrDereference(globalValueNumber(f.getParameter(arg).getAnAccess()).getAnExpr()), kind)
102104
)
103105
or
104106
exists(Function f, ThisExpr innerThis |
@@ -110,7 +112,7 @@ private predicate exprReleases(Expr e, Expr released, string kind) {
110112
) and
111113
e.(FunctionCall).getQualifier() = exprOrDereference(released) and
112114
innerThis.getEnclosingFunction() = f and
113-
exprReleases(_, innerThis, kind)
115+
exprReleases(_, globalValueNumber(innerThis).getAnExpr(), kind)
114116
)
115117
}
116118

0 commit comments

Comments
 (0)