Skip to content

Commit 5e0601f

Browse files
committed
C++: Address review comments.
1 parent 144dcf1 commit 5e0601f

File tree

5 files changed

+41
-24
lines changed

5 files changed

+41
-24
lines changed

cpp/ql/src/Diagnostics/FailedCompilations.ql renamed to cpp/ql/src/Diagnostics/AbortedExtractions.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* @name Failed compiler invocations.
3-
* @description Gives the command-line of compilations for which extraction did not run to completion.
2+
* @name Aborted 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-compilations
5+
* @id cpp/diagnostics/aborted-extractions
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

cpp/ql/src/Diagnostics/FailedExtractions.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @name Failed extractions
3-
* @description Gives the command-line of compilations for which extraction did not run to completion.
3+
* @description List all files in the source code directory with extraction errors.
44
* @kind diagnostic
55
* @id cpp/diagnostics/failed-extractions
66
*/
@@ -12,5 +12,5 @@ from ExtractionError error
1212
where
1313
error instanceof ExtractionUnknownError or
1414
exists(error.getFile().getRelativePath())
15-
select error, "Extracting file $@ failed with $@ (at $@)", error.getFile(), error.getErrorMessage(),
16-
error.getLocation(), error.getSeverity()
15+
select error, "Extracting failed in " + error.getFile() + " with error " + error.getErrorMessage(),
16+
error.getSeverity()

cpp/ql/src/Diagnostics/FailedExtractions.qll

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
import cpp
22

3+
/*
4+
* A note about how the C/C++ extractor emits diagnostics:
5+
* When the extractor frontend encounters an error, it emits a diagnostic message,
6+
* that includes a message, location and severity.
7+
* However, that process is best-effort and may fail (e.g. due to lack of memory).
8+
* Thus, if the extractor emitted at least one diagnostic of severity discretionary
9+
* error (or higher), it *also* emits a simple "There was an error during this compilation"
10+
* error diagnostic, without location information.
11+
* In the common case, this means that a file with one (or more) errors also gets
12+
* the catch-all diagnostic.
13+
* This diagnostic has the empty string as file path.
14+
* We filter out these useless diagnostics if there is at least one error-level diagnostic
15+
* for the affected compilation in the database.
16+
* Otherwise, we show it to, to indicate that something went wrong, and we
17+
* don't know what exactly happened.
18+
*/
19+
320
/**
4-
* The class of errors upon we mark a file as non-successfully extracted.
21+
* An error that, if present, leads to a file being marked as non-successfully extracted.
522
*/
623
class ReportableError extends Diagnostic {
724
ReportableError() {
@@ -10,13 +27,7 @@ class ReportableError extends Diagnostic {
1027
this instanceof CompilerError or
1128
this instanceof CompilerCatastrophe
1229
) and
13-
// If the extractor encounters an error in a compilation, it always emits a
14-
// catch-all diagnostic "There was an error during this compilation", to ensure
15-
// that the error makes it to the database.
16-
// This error doesn't have a file path attached to it, and is thus
17-
// useless for us to report. Furthermore, in the common case, we will have a
18-
// proper diagnostic for this error we can show.
19-
// Instead, we synthesize `TUnknownError` if this is the only error that we can show to the user.
30+
// Filter for the catch-all diagnostic, see note above.
2031
not this.getFile().getAbsolutePath() = ""
2132
}
2233
}
@@ -26,8 +37,11 @@ private newtype TExtractionError =
2637
TCompilationFailed(Compilation c, File f) {
2738
f = c.getAFileCompiled() and not c.normalTermination()
2839
} or
29-
// Report generic extractor errors only if we haven't seen any other error-level diagnostic
30-
TUnknownError(CompilerError err) { not exists(ReportableError e) }
40+
// Show the catch-all diagnostic (see note above) only if we haven't seen any other error-level diagnostic
41+
// for that compilation
42+
TUnknownError(CompilerError err) {
43+
not exists(ReportableError e | e.getCompilation() = err.getCompilation())
44+
}
3145

3246
/**
3347
* Superclass for the extraction error hierarchy.
@@ -53,26 +67,26 @@ class ExtractionError extends TExtractionError {
5367
}
5468

5569
/**
56-
* An irrecoverable extraction failure, where extraction was unable to finish.
70+
* An unrecoverable extraction error, where extraction was unable to finish.
5771
* This can be caused by a multitude of reasons, for example:
5872
* - hitting a frontend assertion
5973
* - crashing due to dereferencing an invalid pointer
6074
* - stack overflow
6175
* - out of memory
6276
*/
63-
class ExtractionIrrecoverableError extends ExtractionError, TCompilationFailed {
77+
class ExtractionUnrecoverableError extends ExtractionError, TCompilationFailed {
6478
Compilation c;
6579
File f;
6680

67-
ExtractionIrrecoverableError() { this = TCompilationFailed(c, f) }
81+
ExtractionUnrecoverableError() { this = TCompilationFailed(c, f) }
6882

6983
override string toString() {
70-
result = "Irrecoverable extraction error while compiling " + f.toString()
84+
result = "Unrecoverable extraction error while compiling " + f.toString()
7185
}
7286

7387
override string getErrorMessage() {
7488
result =
75-
"Irrecoverable compilation failure, check logs/build-tracer.log in the database directory for more information."
89+
"Unrecoverable compilation failure; check logs/build-tracer.log in the database directory for more information."
7690
}
7791

7892
override File getFile() { result = f }

cpp/ql/src/Diagnostics/SuccessfulExtractions.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @name Successfully extracted files.
3-
* @description Lists all files in the database that were extracted without encountering an error.
2+
* @name Successfully extracted files
3+
* @description Lists all files in the source code directory that were extracted without encountering an error.
44
* @kind diagnostic
55
* @id cpp/diagnostics/successfully-extracted-files
66
*/

cpp/ql/src/semmle/code/cpp/Diagnostics.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import semmle.code.cpp.Location
66

77
/** A compiler-generated error, warning or remark. */
88
class Diagnostic extends Locatable, @diagnostic {
9+
/** Gets the compilation that generated this diagnostic. */
10+
Compilation getCompilation() { diagnostic_for(underlyingElement(this), result, _, _) }
11+
912
/**
1013
* Gets the severity of the message, on a range from 1 to 5: 1=remark,
1114
* 2=warning, 3=discretionary error, 4=error, 5=catastrophic error.

0 commit comments

Comments
 (0)