Skip to content

Commit a85d3f9

Browse files
committed
C++: Support __has_unique_object_representations builtin
1 parent 0c03935 commit a85d3f9

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,9 +999,27 @@ class BuiltInComplexOperation extends BuiltInOperation, @builtincomplex {
999999
* Returns `true` if the type has is an aggregate type.
10001000
* ```
10011001
* std::integral_constant<bool, __is_aggregate(_Tp)> ia;
1002-
* ``` */
1002+
* ```
1003+
*/
10031004
class BuiltInOperationIsAggregate extends BuiltInOperation, @isaggregate {
10041005
override string toString() { result = "__is_aggregate" }
10051006

10061007
override string getAPrimaryQlClass() { result = "BuiltInOperationIsAggregate" }
10071008
}
1009+
1010+
/**
1011+
* A C++ `__has_unique_object_representations` built-in operation (used by some
1012+
* implementations of the `<type_traits>` header).
1013+
*
1014+
* Returns `true` if the type is trivially copyable and if the object representation
1015+
* is unique for two objects with the same value.
1016+
* ```
1017+
* bool v = __has_unique_object_representations(MyType);
1018+
* ```
1019+
*/
1020+
class BuiltInOperationHasUniqueObjectRepresentations extends BuiltInOperation,
1021+
@hasuniqueobjectrepresentations {
1022+
override string toString() { result = "__has_unique_object_representations" }
1023+
1024+
override string getAPrimaryQlClass() { result = "BuiltInOperationHasUniqueObjectRepresentations" }
1025+
}

cpp/ql/lib/semmlecode.cpp.dbscheme

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,7 @@ case @expr.kind of
16521652
| 329 = @temp_init
16531653
| 330 = @isassignable
16541654
| 331 = @isaggregate
1655+
| 332 = @hasuniqueobjectrepresentations
16551656
;
16561657

16571658
@var_args_expr = @vastartexpr
@@ -1715,6 +1716,7 @@ case @expr.kind of
17151716
| @builtincomplex
17161717
| @isassignable
17171718
| @isaggregate
1719+
| @hasuniqueobjectrepresentations
17181720
;
17191721

17201722
new_allocated_type(

cpp/ql/test/library-tests/builtins/type_traits/expr.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,7 @@
309309
| ms.cpp:262:28:262:51 | a_struct | | <none> |
310310
| ms.cpp:263:28:263:46 | __is_aggregate | int | 0 |
311311
| ms.cpp:263:28:263:46 | int | | <none> |
312+
| ms.cpp:265:49:265:88 | __has_unique_object_representations | int | 1 |
313+
| ms.cpp:265:49:265:88 | int | | <none> |
314+
| ms.cpp:266:49:266:90 | __has_unique_object_representations | float | 0 |
315+
| ms.cpp:266:49:266:90 | float | | <none> |

cpp/ql/test/library-tests/builtins/type_traits/ms.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,7 @@ void f(void) {
261261

262262
bool b_is_aggregate1 = __is_aggregate(a_struct);
263263
bool b_is_aggregate2 = __is_aggregate(int);
264+
265+
bool b_has_unique_object_representations1 = __has_unique_object_representations(int);
266+
bool b_has_unique_object_representations2 = __has_unique_object_representations(float);
264267
}

0 commit comments

Comments
 (0)