mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Merge pull request #19159 from github/idrissrio/calling-conventions
C++: Add class representing calling conventions
This commit is contained in:
5
cpp/ql/lib/change-notes/2025-03-31-calling-convention.md
Normal file
5
cpp/ql/lib/change-notes/2025-03-31-calling-convention.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
category: feature
|
||||||
|
---
|
||||||
|
* Calling conventions explicitly specified on function declarations (`__cdecl`, `__stdcall`, `__fastcall`, etc.) are now represented as specifiers of those declarations.
|
||||||
|
* A new class `CallingConventionSpecifier` extending the `Specifier` class was introduced, which represents explicitly specified calling conventions.
|
||||||
@@ -97,6 +97,18 @@ class AccessSpecifier extends Specifier {
|
|||||||
override string getAPrimaryQlClass() { result = "AccessSpecifier" }
|
override string getAPrimaryQlClass() { result = "AccessSpecifier" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A C/C++ calling convention specifier: `cdecl`, `fastcall`, `stdcall`, `thiscall`,
|
||||||
|
* `vectorcall`, or `clrcall`.
|
||||||
|
*/
|
||||||
|
class CallingConventionSpecifier extends Specifier {
|
||||||
|
CallingConventionSpecifier() {
|
||||||
|
this.hasName(["cdecl", "fastcall", "stdcall", "thiscall", "vectorcall", "clrcall"])
|
||||||
|
}
|
||||||
|
|
||||||
|
override string getAPrimaryQlClass() { result = "CallingConventionSpecifier" }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An attribute introduced by GNU's `__attribute__((name))` syntax,
|
* An attribute introduced by GNU's `__attribute__((name))` syntax,
|
||||||
* Microsoft's `__declspec(name)` syntax, Microsoft's `[name]` syntax, the
|
* Microsoft's `__declspec(name)` syntax, Microsoft's `[name]` syntax, the
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
| test.cpp:4:21:4:35 | definition of thiscall_method | thiscall |
|
||||||
|
| test.cpp:7:14:7:23 | definition of func_cdecl | cdecl |
|
||||||
|
| test.cpp:9:16:9:27 | definition of func_stdcall | stdcall |
|
||||||
|
| test.cpp:11:17:11:29 | definition of func_fastcall | fastcall |
|
||||||
|
| test.cpp:13:20:13:34 | definition of func_vectorcall | vectorcall |
|
||||||
|
| test.cpp:15:13:15:25 | definition of func_overload | cdecl |
|
||||||
|
| test.cpp:16:15:16:27 | definition of func_overload | stdcall |
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import cpp
|
||||||
|
|
||||||
|
from FunctionDeclarationEntry func, CallingConventionSpecifier ccs
|
||||||
|
where ccs.hasName(func.getASpecifier())
|
||||||
|
select func, func.getASpecifier()
|
||||||
16
cpp/ql/test/library-tests/calling-convention/test.cpp
Normal file
16
cpp/ql/test/library-tests/calling-convention/test.cpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// semmle-extractor-options: --microsoft
|
||||||
|
|
||||||
|
struct call_conventions {
|
||||||
|
void __thiscall thiscall_method() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
void __cdecl func_cdecl() {}
|
||||||
|
|
||||||
|
void __stdcall func_stdcall() {}
|
||||||
|
|
||||||
|
void __fastcall func_fastcall() {}
|
||||||
|
|
||||||
|
void __vectorcall func_vectorcall() {}
|
||||||
|
|
||||||
|
int __cdecl func_overload() {}
|
||||||
|
int __stdcall func_overload(int x) {}
|
||||||
Reference in New Issue
Block a user