From f83f14bab2b81fa262e1896f62c84d85a5a4fb12 Mon Sep 17 00:00:00 2001 From: idrissrio Date: Fri, 28 Mar 2025 16:31:01 +0100 Subject: [PATCH] C++: add calling convention specifier class --- cpp/ql/lib/semmle/code/cpp/Specifier.qll | 12 ++++++++++++ .../calling-convention/calling-convention.ql | 5 +++++ 2 files changed, 17 insertions(+) create mode 100644 cpp/ql/test/library-tests/calling-convention/calling-convention.ql diff --git a/cpp/ql/lib/semmle/code/cpp/Specifier.qll b/cpp/ql/lib/semmle/code/cpp/Specifier.qll index 2f1976d220c..28ba2195656 100644 --- a/cpp/ql/lib/semmle/code/cpp/Specifier.qll +++ b/cpp/ql/lib/semmle/code/cpp/Specifier.qll @@ -97,6 +97,18 @@ class AccessSpecifier extends Specifier { 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, * Microsoft's `__declspec(name)` syntax, Microsoft's `[name]` syntax, the diff --git a/cpp/ql/test/library-tests/calling-convention/calling-convention.ql b/cpp/ql/test/library-tests/calling-convention/calling-convention.ql new file mode 100644 index 00000000000..02e3b3af5ce --- /dev/null +++ b/cpp/ql/test/library-tests/calling-convention/calling-convention.ql @@ -0,0 +1,5 @@ +import cpp + +from FunctionDeclarationEntry func, CallingConventionSpecifier ccs +where ccs.hasName(func.getASpecifier()) +select func, func.getASpecifier()