Skip to content

Commit 81e687e

Browse files
committed
C++: Support __builtin_bit_cast builtin
1 parent a85d3f9 commit 81e687e

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,3 +1023,18 @@ class BuiltInOperationHasUniqueObjectRepresentations extends BuiltInOperation,
10231023

10241024
override string getAPrimaryQlClass() { result = "BuiltInOperationHasUniqueObjectRepresentations" }
10251025
}
1026+
1027+
/**
1028+
* A C/C++ `__builtin_bit_cast` built-in operation (used by some implementations
1029+
* of `std::bit_cast`).
1030+
*
1031+
* Performs a bit cast from a value to a type.
1032+
* ```
1033+
* __builtin_bit_cast(Type, value);
1034+
* ```
1035+
*/
1036+
class BuiltInBitCast extends BuiltInOperation, @builtinbitcast {
1037+
override string toString() { result = "__builtin_bit_cast" }
1038+
1039+
override string getAPrimaryQlClass() { result = "BuiltInBitCast" }
1040+
}

cpp/ql/lib/semmlecode.cpp.dbscheme

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,7 @@ case @expr.kind of
16531653
| 330 = @isassignable
16541654
| 331 = @isaggregate
16551655
| 332 = @hasuniqueobjectrepresentations
1656+
| 333 = @builtinbitcast
16561657
;
16571658

16581659
@var_args_expr = @vastartexpr
@@ -1717,6 +1718,7 @@ case @expr.kind of
17171718
| @isassignable
17181719
| @isaggregate
17191720
| @hasuniqueobjectrepresentations
1721+
| @builtinbitcast
17201722
;
17211723

17221724
new_allocated_type(

cpp/ql/test/library-tests/builtins/edg/edg.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
// semmle-extractor-options: --clang
22
struct mystruct {
33
int f1;
44
int f2;
@@ -13,3 +13,6 @@ void f(void) {
1313
int i2 = edg_offsetof(struct mystruct,f2);
1414
}
1515

16+
void g(void) {
17+
double f = __builtin_bit_cast(double,42l);
18+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
| edg.c:13:14:13:45 | (size_t)... | 0 | 0 |
1414
| edg.c:13:14:13:45 | __INTADDR__ | 1 | 1 |
1515
| edg.c:13:43:13:44 | f2 | 0 | 0 |
16+
| edg.c:17:16:17:45 | __builtin_bit_cast | 1 | 1 |
17+
| edg.c:17:16:17:45 | double | 0 | 0 |
18+
| edg.c:17:42:17:44 | 42 | 1 | 1 |

0 commit comments

Comments
 (0)