Skip to content

Commit 4b4e7ca

Browse files
committed
C++ IR: Support __builtin_addressof
1 parent 50e8034 commit 4b4e7ca

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,8 @@ class TranslatedTransparentUnaryOperation extends TranslatedTransparentExpr {
727727
expr instanceof PointerDereferenceExpr or
728728
// &x is the same as x. &x isn't loadable, but is included
729729
// here to avoid having two nearly identical classes.
730-
expr instanceof AddressOfExpr
730+
expr instanceof AddressOfExpr or
731+
expr instanceof BuiltInOperationBuiltInAddressOf
731732
)
732733
}
733734

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ bad_asts.cpp:
174174
# 27| Type = const Point &
175175
# 27| ValueCategory = prvalue(load)
176176
# 28| 1: return ...
177+
clang.cpp:
178+
# 5| int* globalIntAddress()
179+
# 5| params:
180+
# 5| body: { ... }
181+
# 6| 0: return ...
182+
# 6| 0: __builtin_addressof ...
183+
# 6| Type = int *
184+
# 6| ValueCategory = prvalue
185+
# 6| 0: globalInt
186+
# 6| Type = int
187+
# 6| ValueCategory = lvalue
177188
ir.cpp:
178189
# 1| void Constants()
179190
# 1| params:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// semmle-extractor-options: --clang
2+
3+
int globalInt;
4+
5+
int *globalIntAddress() {
6+
return __builtin_addressof(globalInt);
7+
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ bad_asts.cpp:
4848
# 26| v0_13(void) = UnmodeledUse : mu*
4949
# 26| v0_14(void) = ExitFunction :
5050

51+
clang.cpp:
52+
# 5| int* globalIntAddress()
53+
# 5| Block 0
54+
# 5| v0_0(void) = EnterFunction :
55+
# 5| mu0_1(unknown) = AliasedDefinition :
56+
# 5| mu0_2(unknown) = UnmodeledDefinition :
57+
# 6| r0_3(glval<int *>) = VariableAddress[#return] :
58+
# 6| r0_4(glval<int>) = VariableAddress[globalInt] :
59+
# 6| mu0_5(int *) = Store : &:r0_3, r0_4
60+
# 5| r0_6(glval<int *>) = VariableAddress[#return] :
61+
# 5| v0_7(void) = ReturnValue : &:r0_6, ~mu0_2
62+
# 5| v0_8(void) = UnmodeledUse : mu*
63+
# 5| v0_9(void) = ExitFunction :
64+
5165
ir.cpp:
5266
# 1| void Constants()
5367
# 1| Block 0

0 commit comments

Comments
 (0)