Skip to content

Commit 1ebce01

Browse files
authored
Merge pull request github#19159 from github/idrissrio/calling-conventions
C++: Add class representing calling conventions
2 parents 8bf2ceb + d61d973 commit 1ebce01

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: feature
3+
---
4+
* Calling conventions explicitly specified on function declarations (`__cdecl`, `__stdcall`, `__fastcall`, etc.) are now represented as specifiers of those declarations.
5+
* A new class `CallingConventionSpecifier` extending the `Specifier` class was introduced, which represents explicitly specified calling conventions.

cpp/ql/lib/semmle/code/cpp/Specifier.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ class AccessSpecifier extends Specifier {
9797
override string getAPrimaryQlClass() { result = "AccessSpecifier" }
9898
}
9999

100+
/**
101+
* A C/C++ calling convention specifier: `cdecl`, `fastcall`, `stdcall`, `thiscall`,
102+
* `vectorcall`, or `clrcall`.
103+
*/
104+
class CallingConventionSpecifier extends Specifier {
105+
CallingConventionSpecifier() {
106+
this.hasName(["cdecl", "fastcall", "stdcall", "thiscall", "vectorcall", "clrcall"])
107+
}
108+
109+
override string getAPrimaryQlClass() { result = "CallingConventionSpecifier" }
110+
}
111+
100112
/**
101113
* An attribute introduced by GNU's `__attribute__((name))` syntax,
102114
* Microsoft's `__declspec(name)` syntax, Microsoft's `[name]` syntax, the
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| test.cpp:4:21:4:35 | definition of thiscall_method | thiscall |
2+
| test.cpp:7:14:7:23 | definition of func_cdecl | cdecl |
3+
| test.cpp:9:16:9:27 | definition of func_stdcall | stdcall |
4+
| test.cpp:11:17:11:29 | definition of func_fastcall | fastcall |
5+
| test.cpp:13:20:13:34 | definition of func_vectorcall | vectorcall |
6+
| test.cpp:15:13:15:25 | definition of func_overload | cdecl |
7+
| test.cpp:16:15:16:27 | definition of func_overload | stdcall |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import cpp
2+
3+
from FunctionDeclarationEntry func, CallingConventionSpecifier ccs
4+
where ccs.hasName(func.getASpecifier())
5+
select func, func.getASpecifier()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// semmle-extractor-options: --microsoft
2+
3+
struct call_conventions {
4+
void __thiscall thiscall_method() {}
5+
};
6+
7+
void __cdecl func_cdecl() {}
8+
9+
void __stdcall func_stdcall() {}
10+
11+
void __fastcall func_fastcall() {}
12+
13+
void __vectorcall func_vectorcall() {}
14+
15+
int __cdecl func_overload() {}
16+
int __stdcall func_overload(int x) {}

0 commit comments

Comments
 (0)