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 module cpp.qll imports all the core C/C++ library modules, so you can include the complete library by beginning your query with:
import cpp
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 lists Declaration classes representing C/C++ declarations.
Example syntax |
CodeQL class |
Remarks |
|---|---|---|
|
||
|
||
|
See also Initializer |
|
|
||
|
||
template < typename T >void func ( T param); |
||
int func (const char* 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 |
|
|
||
friend void func ( int );friend class B ; |
||
int func ( void ) { β¦enum en { val1 , val2 β¦ }; β¦ } |
||
class C { β¦enum en { val1 , val2 β¦ } β¦ } |
||
|
||
class C { β¦virtual void func ( int ) = 0; β¦ }; |
||
|
||
|
||
template < typename T >class C < T , 5 > { β¦ }; |
||
|
||
|
||
template < typename T >struct C : T { β¦ }; |
Appears only in uninstantiated templates |
|
int func ( void ) { β¦struct S { β¦ }; β¦ } |
||
class C { β¦struct S { β¦ }; β¦ }; |
||
|
||
|
||
|
||
int func ( void ) { β¦typedef int T ; β¦ } |
||
class C { β¦typedef int T ; β¦ }; |
||
|
||
|
||
template < typename T >class C { β¦ }; |
||
|
Since C++14 |
Statement classesΒΆ
This table lists subclasses of Stmt representing C/C++ statements.
Example syntax |
CodeQL class |
Remarks |
|---|---|---|
|
Specific to a given CPU instruction set |
|
|
||
|
||
|
GNU extension; use with LabelLiteral |
|
Type i |
||
|
||
Expr |
||
|
Structured exception handling (SEH) under Windows |
|
|
Structured exception handling (SEH) under Windows |
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
slabel |
||
C99 variable-length array |
Expression classesΒΆ
This table lists subclasses of Expr 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 in uninstantiated templates |
|
|
||
[ = ] ( float b ) -> float{ return captured * b ; } |
C++11 |
|
^ int ( int x , int y ) { |
Apple extension |
|
|
GNU extension; use with ComputedGotoStmt |
|
β%3d %s\nβ |
||
0xdbceffca |
||
0167 |
||
βcβ |
||
βabcdefghβ, Lβwideβ |
||
|
||
|
||
|
||
|
||
See also Initializer |
||
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 ){ return sizeof... ( t ); } |
||
GNU/Clang extension |
||
|
||
|
||
|
||
|
Microsoft extension |
Type classesΒΆ
This table lists subclasses of Type 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 lists Preprocessor classes representing C/C++ preprocessing directives.
Example syntax |
CodeQL class |
Remarks |
|---|---|---|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Apple/NeXT extension |
|
|
Apple/NeXT extension |
|
|
Further readingΒΆ
βQL language referenceβ
βCodeQL toolsβ