Skip to content

Commit 7ac26e8

Browse files
committed
C++: Add Arm scalable vector type QL classes
1 parent b2f7b89 commit 7ac26e8

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

cpp/ql/lib/semmle/code/cpp/Type.qll

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,23 @@ class UnknownType extends BuiltInType {
352352
private predicate isArithmeticType(@builtintype type, int kind) {
353353
builtintypes(type, _, kind, _, _, _) and
354354
kind >= 4 and
355-
kind != 34 // Exclude decltype(nullptr)
355+
kind != 34 and // Exclude decltype(nullptr)
356+
kind != 63 // Exclude __SVCount_t
357+
}
358+
359+
/**
360+
* The Arm scalable vector count type.
361+
*
362+
* In the following example, `a` is declared using the scalable vector
363+
* count type:
364+
* ```
365+
* svcount_t a;
366+
* ```
367+
*/
368+
class ScalableVectorCount extends BuiltInType {
369+
ScalableVectorCount() { builtintypes(underlyingElement(this), _, 63, _, _, _) }
370+
371+
override string getAPrimaryQlClass() { result = "ScalableVectorCount" }
356372
}
357373

358374
/**
@@ -1084,7 +1100,7 @@ class NullPointerType extends BuiltInType {
10841100
/**
10851101
* A C/C++ derived type.
10861102
*
1087-
* These are pointer and reference types, array and GNU vector types, and `const` and `volatile` types.
1103+
* These are pointer and reference types, array and vector types, and `const` and `volatile` types.
10881104
* In all cases, the type is formed from a single base type. For example:
10891105
* ```
10901106
* int *pi;
@@ -1643,6 +1659,30 @@ class GNUVectorType extends DerivedType {
16431659
override predicate isDeeplyConstBelow() { this.getBaseType().isDeeplyConst() }
16441660
}
16451661

1662+
/**
1663+
* An Arm Scalable vector type.
1664+
*
1665+
* In the following example, `a` has a scalable vector type consisting
1666+
* of 8-bit signed integer elements:
1667+
* ```
1668+
* svint8_t a;
1669+
* ```
1670+
*/
1671+
class ScalableVectorType extends DerivedType {
1672+
ScalableVectorType() { derivedtypes(underlyingElement(this), _, 11, _) }
1673+
1674+
/**
1675+
* Get the number of tuple elements of this scalable vector type.
1676+
*/
1677+
int getNumTupleElements() { tupleelements(underlyingElement(this), result) }
1678+
1679+
override string getAPrimaryQlClass() { result = "ScalableVectorType" }
1680+
1681+
override string explain() { result = "scalable vector of {" + this.getBaseType().explain() + "}" }
1682+
1683+
override predicate isDeeplyConstBelow() { this.getBaseType().isDeeplyConst() }
1684+
}
1685+
16461686
/**
16471687
* A C/C++ pointer to a function. See 7.7.
16481688
* ```

cpp/ql/lib/semmle/code/cpp/ir/internal/CppType.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ private predicate isOpaqueType(Type type) {
134134
)
135135
or
136136
type instanceof PointerToMemberType // PTMs are missing size info
137+
or
138+
type instanceof ScalableVectorCount
137139
}
138140

139141
/**

cpp/ql/lib/semmlecode.cpp.dbscheme

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ case @builtintype.kind of
692692
| 60 = @complex_float64x // _Complex _Float64x
693693
| 61 = @complex_std_float128 // _Complex _Float128
694694
| 62 = @mfp8 // __mfp8
695+
| 63 = @scalable_vector_count // __SVCount_t
695696
;
696697

697698
builtintypes(
@@ -718,6 +719,7 @@ case @derivedtype.kind of
718719
| 8 = @rvalue_reference // C++11
719720
// ... 9 type_conforming_to_protocols deprecated
720721
| 10 = @block
722+
| 11 = @scalable_vector // Arm SVE
721723
;
722724

723725
derivedtypes(
@@ -738,6 +740,11 @@ arraysizes(
738740
int alignment: int ref
739741
);
740742

743+
tupleelements(
744+
unique int id: @derivedtype ref,
745+
int num_elements: int ref
746+
);
747+
741748
typedefbase(
742749
unique int id: @usertype ref,
743750
int type_id: @type ref

0 commit comments

Comments
 (0)