mirror of
https://github.com/github/codeql.git
synced 2026-04-26 01:05:15 +02:00
C++: Initial telemetry queries and tests
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
| 'this' may only be used inside a nonstatic member function | 1.0 |
|
||||
| There was an error during this compilation | 1.0 |
|
||||
| expected a ')' | 1.0 |
|
||||
| expected a ';' | 1.0 |
|
||||
| expected an expression | 1.0 |
|
||||
| identifier 'no_such_function' is undefined | 1.0 |
|
||||
| identifier 'nsf2' is undefined | 1.0 |
|
||||
| identifier 'so_is_this' is undefined | 1.0 |
|
||||
| identifier 'uint32_t' is undefined | 1.0 |
|
||||
| too few arguments in function call | 1.0 |
|
||||
@@ -0,0 +1 @@
|
||||
Telemetry/CompilerErrors.ql
|
||||
@@ -0,0 +1,9 @@
|
||||
| Percentage of calls with a target | 50.0 |
|
||||
| Percentage of compilation units without errors | 50.0 |
|
||||
| Percentage of expressions with a known type | 30.0 |
|
||||
| Percentage of functions without errors | 75.0 |
|
||||
| Percentage of lines of code without errors | 63.1578947368421 |
|
||||
| Percentage of non-error expressions | 30.0 |
|
||||
| Percentage of source files without errors | 66.66666666666667 |
|
||||
| Percentage of successfully resolved #include directives | 100.0 |
|
||||
| Percentage of variables with a known type | 90.0 |
|
||||
@@ -0,0 +1 @@
|
||||
Telemetry/DatabaseQuality.ql
|
||||
@@ -0,0 +1,20 @@
|
||||
| #include directives | 2.0 |
|
||||
| calls | 2.0 |
|
||||
| calls with a target | 1.0 |
|
||||
| compilation units | 2.0 |
|
||||
| compilation units without errors | 1.0 |
|
||||
| compiler errors | 10.0 |
|
||||
| expressions | 10.0 |
|
||||
| expressions with a known type | 3.0 |
|
||||
| functions | 8.0 |
|
||||
| functions without errors | 6.0 |
|
||||
| lines of code | 19.0 |
|
||||
| lines of code without errors | 12.0 |
|
||||
| lines of text | 26.0 |
|
||||
| non-error expressions | 3.0 |
|
||||
| source files | 3.0 |
|
||||
| source files without errors | 2.0 |
|
||||
| successfully resolved #include directives | 2.0 |
|
||||
| syntax errors | 3.0 |
|
||||
| variables | 10.0 |
|
||||
| variables with a known type | 9.0 |
|
||||
@@ -0,0 +1 @@
|
||||
Telemetry/ExtractionMetrics.ql
|
||||
@@ -0,0 +1 @@
|
||||
Telemetry/MissingIncludes.ql
|
||||
@@ -0,0 +1,79 @@
|
||||
#-----| [CopyAssignmentOperator] __va_list_tag& __va_list_tag::operator=(__va_list_tag const&)
|
||||
#-----| <params>:
|
||||
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
|
||||
#-----| Type = [LValueReferenceType] const __va_list_tag &
|
||||
#-----| [MoveAssignmentOperator] __va_list_tag& __va_list_tag::operator=(__va_list_tag&&)
|
||||
#-----| <params>:
|
||||
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
|
||||
#-----| Type = [RValueReferenceType] __va_list_tag &&
|
||||
test.c:
|
||||
# 3| [TopLevelFunction] void g()
|
||||
# 3| <params>:
|
||||
# 3| getEntryPoint(): [BlockStmt] { ... }
|
||||
# 4| getStmt(0): [DeclStmt] declaration
|
||||
# 4| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x
|
||||
# 4| Type = [IntType] int
|
||||
# 4| getVariable().getInitializer(): [Initializer] initializer for x
|
||||
# 4| getExpr(): [FunctionCall] call to no_such_function
|
||||
# 4| Type = [IntType] int
|
||||
# 4| ValueCategory = prvalue
|
||||
# 5| getStmt(1): [ReturnStmt] return ...
|
||||
# 4| [TopLevelFunction] int no_such_function()
|
||||
# 4| <params>:
|
||||
test.cpp:
|
||||
# 5| [TopLevelFunction] void function_with_errors()
|
||||
# 5| <params>:
|
||||
# 5| getEntryPoint(): [BlockStmt] { ... }
|
||||
# 6| getStmt(0): [DeclStmt] declaration
|
||||
# 6| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x
|
||||
# 6| Type = [ErroneousType] error
|
||||
# 6| getVariable().getInitializer(): [Initializer] initializer for x
|
||||
# 6| getExpr(): [ErrorExpr] <error expr>
|
||||
# 6| Type = [ErroneousType] error
|
||||
# 6| ValueCategory = prvalue
|
||||
# 7| getStmt(1): [ExprStmt] ExprStmt
|
||||
#-----| getExpr(): [ErrorExpr] <error expr>
|
||||
#-----| Type = [ErroneousType] error
|
||||
#-----| ValueCategory = prvalue
|
||||
# 8| getStmt(2): [ExprStmt] ExprStmt
|
||||
#-----| getExpr(): [ErrorExpr] <error expr>
|
||||
#-----| Type = [ErroneousType] error
|
||||
#-----| ValueCategory = prvalue
|
||||
# 9| getStmt(3): [ExprStmt] ExprStmt
|
||||
#-----| getExpr(): [ErrorExpr] <error expr>
|
||||
#-----| Type = [ErroneousType] error
|
||||
#-----| ValueCategory = prvalue
|
||||
# 10| getStmt(4): [ExprStmt] ExprStmt
|
||||
# 10| getExpr(): [FunctionCall] call to f
|
||||
# 10| Type = [IntType] int
|
||||
# 10| ValueCategory = prvalue
|
||||
# 10| getArgument(0): [Literal] 1
|
||||
# 10| Type = [IntType] int
|
||||
# 10| Value = [Literal] 1
|
||||
# 10| ValueCategory = prvalue
|
||||
# 11| getStmt(5): [ExprStmt] ExprStmt
|
||||
#-----| getExpr(): [ErrorExpr] <error expr>
|
||||
#-----| Type = [ErroneousType] error
|
||||
#-----| ValueCategory = prvalue
|
||||
# 12| getStmt(6): [ReturnStmt] return ...
|
||||
# 14| [TopLevelFunction] error fn2()
|
||||
# 14| <params>:
|
||||
# 14| getEntryPoint(): [BlockStmt] { ... }
|
||||
# 15| getStmt(0): [ExprStmt] ExprStmt
|
||||
#-----| getExpr(): [ErrorExpr] <error expr>
|
||||
#-----| Type = [ErroneousType] error
|
||||
#-----| ValueCategory = prvalue
|
||||
# 16| getStmt(1): [ExprStmt] ExprStmt
|
||||
#-----| getExpr(): [ErrorExpr] <error expr>
|
||||
#-----| Type = [ErroneousType] error
|
||||
#-----| ValueCategory = prvalue
|
||||
# 17| getStmt(2): [ReturnStmt] return ...
|
||||
test.h:
|
||||
# 4| [TopLevelFunction] int f(int)
|
||||
# 4| <params>:
|
||||
# 4| getParameter(0): [Parameter] (unnamed parameter 0)
|
||||
# 4| Type = [IntType] int
|
||||
# 4| [TopLevelFunction] int f(int)
|
||||
# 4| <params>:
|
||||
# 4| getParameter(0): [Parameter] (unnamed parameter 0)
|
||||
# 4| Type = [IntType] int
|
||||
@@ -0,0 +1 @@
|
||||
semmle/code/cpp/PrintAST.ql
|
||||
@@ -0,0 +1 @@
|
||||
| "test.h" | 2.0 |
|
||||
@@ -0,0 +1 @@
|
||||
Telemetry/SucceededIncludes.ql
|
||||
10
cpp/ql/test/library-tests/extraction_errors/diags.expected
Normal file
10
cpp/ql/test/library-tests/extraction_errors/diags.expected
Normal file
@@ -0,0 +1,10 @@
|
||||
| file://:0:0:0:0 | There was an error during this compilation |
|
||||
| test.cpp:6:14:6:14 | identifier 'no_such_function' is undefined |
|
||||
| test.cpp:9:14:9:14 | identifier 'nsf2' is undefined |
|
||||
| test.cpp:11:7:11:7 | too few arguments in function call |
|
||||
| test.cpp:14:1:14:1 | identifier 'uint32_t' is undefined |
|
||||
| test.cpp:15:5:15:5 | 'this' may only be used inside a nonstatic member function |
|
||||
| test.cpp:15:10:15:10 | expected a ';' |
|
||||
| test.cpp:16:5:16:5 | identifier 'so_is_this' is undefined |
|
||||
| test.cpp:16:16:16:16 | expected a ')' |
|
||||
| test.cpp:16:16:16:16 | expected an expression |
|
||||
4
cpp/ql/test/library-tests/extraction_errors/diags.ql
Normal file
4
cpp/ql/test/library-tests/extraction_errors/diags.ql
Normal file
@@ -0,0 +1,4 @@
|
||||
import cpp
|
||||
|
||||
from Diagnostic d
|
||||
select d
|
||||
@@ -0,0 +1 @@
|
||||
| test.cpp:14:10:14:12 | fn2 |
|
||||
@@ -0,0 +1,5 @@
|
||||
import cpp
|
||||
|
||||
from Function fn
|
||||
where fn.getType() instanceof ErroneousType or not exists(fn.getType())
|
||||
select fn
|
||||
@@ -0,0 +1 @@
|
||||
| test.cpp:6:13:6:31 | <error expr> |
|
||||
@@ -0,0 +1,6 @@
|
||||
import cpp
|
||||
|
||||
from Expr e
|
||||
where e.getType() instanceof ErroneousType
|
||||
and e.fromSource()
|
||||
select e
|
||||
@@ -0,0 +1 @@
|
||||
| test.cpp:6:10:6:10 | x | This variable does not have a type. |
|
||||
@@ -0,0 +1,5 @@
|
||||
import cpp
|
||||
|
||||
from Variable v
|
||||
where v.getType() instanceof ErroneousType or not exists(v.getType())
|
||||
select v, "This variable does not have a type."
|
||||
@@ -0,0 +1,6 @@
|
||||
| test.c:3:6:3:6 | g |
|
||||
| test.c:4:13:4:13 | no_such_function |
|
||||
| test.cpp:5:6:5:25 | function_with_errors |
|
||||
| test.cpp:14:10:14:12 | fn2 |
|
||||
| test.h:4:5:4:5 | f |
|
||||
| test.h:4:5:4:5 | f |
|
||||
5
cpp/ql/test/library-tests/extraction_errors/functions.ql
Normal file
5
cpp/ql/test/library-tests/extraction_errors/functions.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
import cpp
|
||||
|
||||
from Function fn
|
||||
where fn.fromSource()
|
||||
select fn
|
||||
5
cpp/ql/test/library-tests/extraction_errors/test.c
Normal file
5
cpp/ql/test/library-tests/extraction_errors/test.c
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "test.h"
|
||||
|
||||
void g() {
|
||||
int x = no_such_function();
|
||||
}
|
||||
17
cpp/ql/test/library-tests/extraction_errors/test.cpp
Normal file
17
cpp/ql/test/library-tests/extraction_errors/test.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
// semmle-extractor-options: --expect_errors
|
||||
|
||||
#include "test.h"
|
||||
|
||||
void function_with_errors() {
|
||||
auto x = no_such_function();
|
||||
x+2;
|
||||
no_such_function();
|
||||
ADD(x+1, nsf2());
|
||||
f(1);
|
||||
f();
|
||||
}
|
||||
|
||||
uint32_t fn2() {
|
||||
this is a syntax error;
|
||||
so_is_this(;
|
||||
}
|
||||
4
cpp/ql/test/library-tests/extraction_errors/test.h
Normal file
4
cpp/ql/test/library-tests/extraction_errors/test.h
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
#define ADD(A,B) ((A)+(B))
|
||||
|
||||
int f(int);
|
||||
Reference in New Issue
Block a user