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 |
|
|