Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 93103e1

Browse files
committed
C++: add class and test for a GNU vector fill operation
1 parent 8e3f639 commit 93103e1

6 files changed

Lines changed: 27 additions & 0 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,10 @@ class BuiltInOperationIsFinal extends BuiltInOperation, @isfinalexpr {
369369
class BuiltInChooseExpr extends BuiltInOperation, @builtinchooseexpr {
370370
override string toString() { result = "__builtin_choose_expr" }
371371
}
372+
373+
/**
374+
* Fill operation on a GNU vector.
375+
*/
376+
class VectorFillOperation extends UnaryOperation, @vec_fill {
377+
override string getOperator() { result = "(vector fill)" }
378+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| vector_types.cpp:51:18:51:18 | (vector fill) ... | file://:0:0:0:0 | __attribute((vector_size(16))) int | vector_types.cpp:51:18:51:18 | n | file://:0:0:0:0 | int |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import cpp
2+
3+
from VectorFillOperation vf, Expr operand
4+
where operand = vf.getOperand()
5+
select vf, vf.getType(), operand, operand.getType()

cpp/ql/test/library-tests/vector_types/variables.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@
1414
| vector_types.cpp:33:8:33:9 | v5 | v5 | file://:0:0:0:0 | __attribute((vector_size(16))) double | 16 |
1515
| vector_types.cpp:34:10:34:16 | doubles | doubles | file://:0:0:0:0 | double[2] | 16 |
1616
| vector_types.cpp:41:14:41:16 | arg | arg | vector_types.cpp:7:14:7:17 | v16c | 16 |
17+
| vector_types.cpp:47:23:47:25 | dst | dst | file://:0:0:0:0 | v16i * | 8 |
18+
| vector_types.cpp:47:34:47:36 | src | src | file://:0:0:0:0 | v16i * | 8 |
19+
| vector_types.cpp:47:43:47:43 | n | n | file://:0:0:0:0 | int | 4 |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
| vector_types.cpp:16:16:16:41 | ... == ... | == | file://:0:0:0:0 | __attribute((vector_size(16))) char |
22
| vector_types.cpp:21:10:21:18 | ... < ... | < | file://:0:0:0:0 | __attribute((vector_size(16))) int |
3+
| vector_types.cpp:51:10:51:18 | ... << ... | << | file://:0:0:0:0 | __attribute((vector_size(16))) int |
4+
| vector_types.cpp:51:18:51:18 | (vector fill) ... | (vector fill) | file://:0:0:0:0 | __attribute((vector_size(16))) int |

cpp/ql/test/library-tests/vector_types/vector_types.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,12 @@ int main() {
4141
v4f lax(v16c arg) {
4242
return arg;
4343
}
44+
45+
typedef int v16i __attribute__((vector_size(16)));
46+
47+
void shift_left(v16i *dst, v16i *src, int n) {
48+
// We represent this shift as an operation on vector types, and the
49+
// right-hand side is a vector fill expression (i.e. a vector filled with n in
50+
// each element).
51+
*dst = *src << n;
52+
}

0 commit comments

Comments
 (0)