CodeQL library for C and C++¶
When analyzing C or C++ code, you can use the large collection of classes in the CodeQL library for C and C++.
About the CodeQL library for C and C++¶
There is an extensive library for analyzing CodeQL databases extracted from C/C++ projects. The classes in this library present the data from a database in an object-oriented form and provide abstractions and predicates to help you with common analysis tasks.The library is implemented as a set of QL modules, that is, files with the extension.qll
. The modulecpp.qll
imports all the core C/C++ library modules, so you can include the complete library by beginning your query with:
importcpp
The rest of this topic summarizes the available CodeQL classes and corresponding C/C++ constructs.
Commonly-used library classes¶
The most commonly used standard library classes are listed below. The listing is broken down by functionality. Each library class is annotated with a C/C++ construct it corresponds to.
Declaration classes¶
This table listsDeclaration classes representing C/C++ declarations.
Example syntax | CodeQL class | Remarks |
---|---|---|
| ||
| ||
| See alsoInitializer | |
| ||
| ||
template<typename T> void func( Tparam); | ||
int func(constchar* format,...) { …} | ||
func | ||
template<typename T> func <int, T>( …){ …} | ||
class C{ …int func(float param); …}; | ||
class C{ …int func(float param)const; …}; | ||
| ||
| ||
| ||
| ||
class C{ …C (const D& d){ …} …}; | ||
C | ||
C | ||
C | ||
C | ||
C | Default constructor | |
| ||
friendvoid func(int); friendclass B; | ||
int func(void){ …enum en{ val1, val2 …}; …} | ||
class C{ …enum en{ val1, val2 …} …} | ||
| ||
class C{ …virtualvoid func(int)=0; …}; | ||
| ||
| ||
template<typename T> class C< T, 5>{ …}; | ||
| ||
| ||
template<typename T> struct C: T{ …}; | Appears only inuninstantiatedtemplates | |
int func(void){ …struct S{ …}; …} | ||
class C{ …struct S{ …}; …}; | ||
| ||
| ||
| ||
int func(void){ …typedefint T; …} | ||
class C{ …typedefint T; …}; | ||
| ||
| ||
template<typename T> class C{ …}; | ||
| Since C++14 |
Statement classes¶
This table lists subclasses ofStmt representing C/C++ statements.
Example syntax | CodeQL class | Remarks |
---|---|---|
| Specific to a given CPU instruction set | |
| ||
| ||
| GNU extension; use withLabelLiteral | |
Typei | ||
| ||
Expr | ||
| Structured exception handling (SEH) under Windows | |
| Structured exception handling (SEH) under Windows | |
| ||
| ||
| ||
| ||
| ||
| ||
| ||
slabel | ||
C99 variable-length array |
Expression classes¶
This table lists subclasses ofExpr representing C/C++ expressions.
Example syntax | CodeQL class(es) | Remarks |
---|---|---|
| ||
| ||
| ||
| Microsoft extension | |
| C++11 C11 | |
| Microsoft extension | |
template<typename... T> auto sum( T…t) {return( t+...+0);} | Appears only inuninstantiatedtemplates | |
| ||
[=](float b)->float {return captured* b;} | C++11 | |
^int(int x,int y){ | Apple extension | |
| GNU extension; use withComputedGotoStmt | |
“%3d %s\n” | ||
0xdbceffca | ||
0167 | ||
‘c’ | ||
“abcdefgh”,L”wide” | ||
| ||
| ||
| ||
| ||
See alsoInitializer | ||
Expr `` | =``Expr | |
C99 C99 | ||
C99 | ||
GNU extension | ||
GNU extension | ||
C99 | ||
C99 C99 | ||
| ||
| ||
Expr | ||
| ||
Expr | ||
| ||
| GNU extension | |
| GNU extension | |
| ||
| ||
| GNU extension | |
| ||
int vect__attribute__ ((vector_size( 16))) ={ 3, 8, 32, 33}; | GNU extension | |
| ||
| ||
template<typename... T> int count( T&&... t) {returnsizeof...( t);} | ||
GNU/Clang extension | ||
| ||
| ||
| ||
| Microsoft extension |
Type classes¶
This table lists subclasses ofType representing C/C++ types.
Example syntax | CodeQL class | Remarks |
---|---|---|
| ||
| ||
| C11, C++11 | |
| C11, C++11 | |
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
Type | ||
Apple extension | ||
Type | ||
Type | ||
Type | ||
Type | ||
| ||
|
Preprocessor classes¶
This table listsPreprocessor classes representing C/C++ preprocessing directives.
Example syntax | CodeQL class | Remarks |
---|---|---|
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| Apple/NeXT extension | |
| Apple/NeXT extension | |
|