C++: Support std::addressof

I didn't add this support in `AddressConstantExpression.qll` since I
think it would require extra work and testing to get the constexprness
right. My long-term plan for `AddressConstantExpression.qll` is to move
its functionality to the extractor.
This commit is contained in:
Jonas Jensen
2020-05-06 11:17:13 +02:00
parent 1b1095ee75
commit 32e04b4033
4 changed files with 63 additions and 22 deletions

View File

@@ -63,3 +63,18 @@ void nonexamples(int *ptr, int &ref) {
nonexamples(&*ptr, ref);
}
}
namespace std {
template<typename T>
constexpr T *addressof(T &obj) noexcept {
return __builtin_addressof(obj);
}
}
void use_std_addressof() {
int x = 0;
int *y = std::addressof(x) + *std::addressof(x);
}
// semmle-extractor-options: --clang

View File

@@ -25,6 +25,10 @@
| addressOf.cpp:62:11:62:13 | ptr | |
| addressOf.cpp:63:19:63:21 | ptr | |
| addressOf.cpp:63:24:63:26 | ref | non-const address |
| addressOf.cpp:71:32:71:34 | obj | |
| addressOf.cpp:71:32:71:34 | obj | |
| addressOf.cpp:77:27:77:27 | x | non-const address |
| addressOf.cpp:77:48:77:48 | x | |
| file://:0:0:0:0 | captured | |
| file://:0:0:0:0 | captured | |
| file://:0:0:0:0 | captured | non-const address |