Skip to content

Commit 7bbfffe

Browse files
Merge pull request #1552 from jbj/ir-builtin_addressof
C++ IR: Support __builtin_addressof
2 parents 52e0f3f + 4b4e7ca commit 7bbfffe

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
@@ -190,6 +190,17 @@ bad_asts.cpp:
190190
# 27| Type = const Point &
191191
# 27| ValueCategory = prvalue(load)
192192
# 28| 1: return ...
193+
clang.cpp:
194+
# 5| int* globalIntAddress()
195+
# 5| params:
196+
# 5| body: { ... }
197+
# 6| 0: return ...
198+
# 6| 0: __builtin_addressof ...
199+
# 6| Type = int *
200+
# 6| ValueCategory = prvalue
201+
# 6| 0: globalInt
202+
# 6| Type = int
203+
# 6| ValueCategory = lvalue
193204
ir.cpp:
194205
# 1| void Constants()
195206
# 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)