mirror of
https://github.com/github/codeql.git
synced 2025-12-23 20:26:32 +01:00
C++: Support __builtin_shuffle builtin
While here write gcc instead of GNU, which is more accurate.
This commit is contained in:
@@ -121,7 +121,7 @@ class BuiltInNoOp extends BuiltInOperation, @noopexpr {
|
|||||||
/**
|
/**
|
||||||
* A C/C++ `__builtin_offsetof` built-in operation (used by some implementations
|
* A C/C++ `__builtin_offsetof` built-in operation (used by some implementations
|
||||||
* of `offsetof`). The operation retains its semantics even in the presence
|
* of `offsetof`). The operation retains its semantics even in the presence
|
||||||
* of an overloaded `operator &`). This is a GNU/Clang extension.
|
* of an overloaded `operator &`). This is a gcc/clang extension.
|
||||||
* ```
|
* ```
|
||||||
* struct S {
|
* struct S {
|
||||||
* int a, b;
|
* int a, b;
|
||||||
@@ -494,6 +494,23 @@ class BuiltInOperationBuiltInShuffleVector extends BuiltInOperation, @builtinshu
|
|||||||
override string getAPrimaryQlClass() { result = "BuiltInOperationBuiltInShuffleVector" }
|
override string getAPrimaryQlClass() { result = "BuiltInOperationBuiltInShuffleVector" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A gcc `__builtin_shuffle` expression.
|
||||||
|
*
|
||||||
|
* It outputs a permutation of elements from one or two input vectors.
|
||||||
|
* Please see https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html
|
||||||
|
* for more information.
|
||||||
|
* ```
|
||||||
|
* // Concatenate every other element of 4-element vectors V1 and V2.
|
||||||
|
* V3 = __builtin_shufflevector(V1, V2, {0, 2, 4, 6});
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
class BuiltInOperationBuiltInShuffle extends BuiltInOperation, @builtinshuffle {
|
||||||
|
override string toString() { result = "__builtin_shuffle" }
|
||||||
|
|
||||||
|
override string getAPrimaryQlClass() { result = "BuiltInOperationBuiltInShuffle" }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A clang `__builtin_convertvector` expression.
|
* A clang `__builtin_convertvector` expression.
|
||||||
*
|
*
|
||||||
@@ -946,7 +963,7 @@ class BuiltInOperationIsFinal extends BuiltInOperation, @isfinalexpr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `__builtin_choose_expr` expression. This is a GNU/Clang extension.
|
* The `__builtin_choose_expr` expression. This is a gcc/clang extension.
|
||||||
*
|
*
|
||||||
* The expression functions similarly to the ternary `?:` operator, except
|
* The expression functions similarly to the ternary `?:` operator, except
|
||||||
* that it is evaluated at compile-time.
|
* that it is evaluated at compile-time.
|
||||||
|
|||||||
@@ -1654,6 +1654,7 @@ case @expr.kind of
|
|||||||
| 331 = @isaggregate
|
| 331 = @isaggregate
|
||||||
| 332 = @hasuniqueobjectrepresentations
|
| 332 = @hasuniqueobjectrepresentations
|
||||||
| 333 = @builtinbitcast
|
| 333 = @builtinbitcast
|
||||||
|
| 334 = @builtinshuffle
|
||||||
;
|
;
|
||||||
|
|
||||||
@var_args_expr = @vastartexpr
|
@var_args_expr = @vastartexpr
|
||||||
@@ -1719,6 +1720,7 @@ case @expr.kind of
|
|||||||
| @isaggregate
|
| @isaggregate
|
||||||
| @hasuniqueobjectrepresentations
|
| @hasuniqueobjectrepresentations
|
||||||
| @builtinbitcast
|
| @builtinbitcast
|
||||||
|
| @builtinshuffle
|
||||||
;
|
;
|
||||||
|
|
||||||
new_allocated_type(
|
new_allocated_type(
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
|
| vector_types2.cpp:10:15:10:42 | __builtin_shuffle |
|
||||||
|
| vector_types2.cpp:11:15:11:45 | __builtin_shuffle |
|
||||||
| vector_types.cpp:31:13:31:49 | __builtin_shufflevector |
|
| vector_types.cpp:31:13:31:49 | __builtin_shufflevector |
|
||||||
| vector_types.cpp:58:10:58:52 | __builtin_convertvector |
|
| vector_types.cpp:58:10:58:52 | __builtin_convertvector |
|
||||||
|
|||||||
@@ -13,6 +13,12 @@
|
|||||||
| file://:0:0:0:0 | gp_offset | gp_offset | file://:0:0:0:0 | unsigned int | 4 |
|
| file://:0:0:0:0 | gp_offset | gp_offset | file://:0:0:0:0 | unsigned int | 4 |
|
||||||
| file://:0:0:0:0 | overflow_arg_area | overflow_arg_area | file://:0:0:0:0 | void * | 8 |
|
| file://:0:0:0:0 | overflow_arg_area | overflow_arg_area | file://:0:0:0:0 | void * | 8 |
|
||||||
| file://:0:0:0:0 | reg_save_area | reg_save_area | file://:0:0:0:0 | void * | 8 |
|
| file://:0:0:0:0 | reg_save_area | reg_save_area | file://:0:0:0:0 | void * | 8 |
|
||||||
|
| vector_types2.cpp:5:7:5:7 | a | a | vector_types2.cpp:2:13:2:15 | v4i | 16 |
|
||||||
|
| vector_types2.cpp:6:7:6:7 | b | b | vector_types2.cpp:2:13:2:15 | v4i | 16 |
|
||||||
|
| vector_types2.cpp:7:7:7:12 | mask_1 | mask_1 | vector_types2.cpp:2:13:2:15 | v4i | 16 |
|
||||||
|
| vector_types2.cpp:8:7:8:12 | mask_2 | mask_2 | vector_types2.cpp:2:13:2:15 | v4i | 16 |
|
||||||
|
| vector_types2.cpp:10:7:10:11 | res_1 | res_1 | vector_types2.cpp:2:13:2:15 | v4i | 16 |
|
||||||
|
| vector_types2.cpp:11:7:11:11 | res_2 | res_2 | vector_types2.cpp:2:13:2:15 | v4i | 16 |
|
||||||
| vector_types.cpp:9:21:9:21 | x | x | vector_types.cpp:6:15:6:17 | v4f | 16 |
|
| vector_types.cpp:9:21:9:21 | x | x | vector_types.cpp:6:15:6:17 | v4f | 16 |
|
||||||
| vector_types.cpp:14:18:14:20 | lhs | lhs | vector_types.cpp:6:15:6:17 | v4f | 16 |
|
| vector_types.cpp:14:18:14:20 | lhs | lhs | vector_types.cpp:6:15:6:17 | v4f | 16 |
|
||||||
| vector_types.cpp:14:27:14:29 | rhs | rhs | vector_types.cpp:6:15:6:17 | v4f | 16 |
|
| vector_types.cpp:14:27:14:29 | rhs | rhs | vector_types.cpp:6:15:6:17 | v4f | 16 |
|
||||||
|
|||||||
12
cpp/ql/test/library-tests/vector_types/vector_types2.cpp
Normal file
12
cpp/ql/test/library-tests/vector_types/vector_types2.cpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// semmle-extractor-options: --gnu --gnu_version 80000
|
||||||
|
typedef int v4i __attribute__((vector_size (16)));
|
||||||
|
|
||||||
|
void f() {
|
||||||
|
v4i a = {1,2,3,4};
|
||||||
|
v4i b = {5,6,7,8};
|
||||||
|
v4i mask_1 = {3,0,1,2};
|
||||||
|
v4i mask_2 = {3,5,4,2};
|
||||||
|
|
||||||
|
v4i res_1 = __builtin_shuffle(a, mask_1);
|
||||||
|
v4i res_2 = __builtin_shuffle(a, b, mask_2);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user