Skip to content

Commit 960a41b

Browse files
committed
Handle __builtin_addressof.
1 parent 175ba7b commit 960a41b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

cpp/ql/src/semmle/code/cpp/exprs/BuiltInOperations.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,29 @@ class BuiltInVarArgCopy extends BuiltInOperation, @vacopyexpr {
5151
*/
5252
class BuiltInNoOp extends BuiltInOperation, @noopexpr {
5353
override string toString() { result = "__noop" }
54+
55+
/** Canonical QL class corresponding to this element. */
56+
override string getCanonicalQLClass() { result = "BuiltInNoOp" }
5457
}
5558

5659
/**
5760
* A C++ `__offsetof` expression (used by some implementations of offsetof in the presence of user-defined `operator&`).
5861
*/
5962
class BuiltInOperationOffsetOf extends BuiltInOperation, @offsetofexpr {
6063
override string toString() { result = "__offsetof" }
64+
65+
/** Canonical QL class corresponding to this element. */
66+
override string getCanonicalQLClass() { result = "BuiltInOperationOffsetOf" }
6167
}
6268

6369
/**
6470
* A C/C++ `__INTADDR__` expression, used by EDG to implement `offsetof` in the presence of user-defined `operator&`.
6571
*/
6672
class BuiltInIntAddr extends BuiltInOperation, @intaddrexpr {
6773
override string toString() { result = "__INTADDR__" }
74+
75+
/** Canonical QL class corresponding to this element. */
76+
override string getCanonicalQLClass() { result = "BuiltInIntAddr" }
6877
}
6978

7079
/**
@@ -239,6 +248,9 @@ class BuiltInOperationBuiltInAddressOf extends UnaryOperation, BuiltInOperation,
239248
or result = this.getOperand().(ReferenceDereferenceExpr).getChild(0).(Access).getTarget()
240249
}
241250

251+
/** Canonical QL class corresponding to this element. */
252+
override string getCanonicalQLClass() { result = "BuiltInOperationBuiltInAddressOf" }
253+
242254
override string getOperator() { result = "__builtin_addressof" }
243255
}
244256

cpp/ql/test/library-tests/ir/ir/PrintAST.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ clang.cpp:
195195
# 5| params:
196196
# 5| body: [Block]: { ... }
197197
# 6| 0: [ReturnStmt]: return ...
198-
# 6| 0: [???]: __builtin_addressof ...
198+
# 6| 0: [BuiltInOperationBuiltInAddressOf]: __builtin_addressof ...
199199
# 6| Type = [IntPointerType]: int *
200200
# 6| ValueCategory = prvalue
201201
# 6| 0: [VariableAccess]: globalInt

0 commit comments

Comments
 (0)