Skip to content

Commit 65b2128

Browse files
committed
C++: Move builtin function identification to its own table
1 parent 7c2fd28 commit 65b2128

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,12 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
282282
* definition, if possible.)
283283
*/
284284
override Location getLocation() {
285-
if exists(this.getDefinition())
286-
then result = this.getDefinitionLocation()
287-
else result = this.getADeclarationLocation()
285+
if this instanceof BuiltInFunction
286+
then result instanceof UnknownLocation // a dummy location for the built-in function
287+
else
288+
if exists(this.getDefinition())
289+
then result = this.getDefinitionLocation()
290+
else result = this.getADeclarationLocation()
288291
}
289292

290293
/** Gets a child declaration of this function. */
@@ -896,17 +899,9 @@ class FunctionTemplateSpecialization extends Function {
896899
* A GCC built-in function. For example: `__builtin___memcpy_chk`.
897900
*/
898901
class BuiltInFunction extends Function {
899-
BuiltInFunction() { functions(underlyingElement(this), _, 6) }
900-
901-
/** Gets a dummy location for the built-in function. */
902-
override Location getLocation() {
903-
suppressUnusedThis(this) and
904-
result instanceof UnknownLocation
905-
}
902+
BuiltInFunction() { builtin_functions(underlyingElement(this)) }
906903
}
907904

908-
private predicate suppressUnusedThis(Function f) { any() }
909-
910905
/**
911906
* A C++ user-defined literal [N4140 13.5.8].
912907
*/

cpp/ql/lib/semmlecode.cpp.dbscheme

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,13 @@ macro_argument_expanded(
288288

289289
/*
290290
case @function.kind of
291-
1 = @normal_function
291+
0 = @unknown_function
292+
| 1 = @normal_function
292293
| 2 = @constructor
293294
| 3 = @destructor
294295
| 4 = @conversion_function
295296
| 5 = @operator
296-
| 6 = @builtin_function // GCC built-in functions, e.g. __builtin___memcpy_chk
297+
// ... 6 = @builtin_function deprecated // GCC built-in functions, e.g. __builtin___memcpy_chk
297298
| 7 = @user_defined_literal
298299
| 8 = @deduction_guide
299300
;
@@ -305,6 +306,10 @@ functions(
305306
int kind: int ref
306307
);
307308

309+
builtin_functions(
310+
int id: @function ref
311+
)
312+
308313
function_entry_point(
309314
int id: @function ref,
310315
unique int entry_point: @stmt ref

0 commit comments

Comments
 (0)