Skip to content

Commit ecbdc4f

Browse files
committed
C++: Add Arm scalable vector type QL classes
1 parent 9fb47cc commit ecbdc4f

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,17 @@ 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 `__SVCount_t`.
361+
*/
362+
class ScalableVectorCount extends BuiltInType {
363+
ScalableVectorCount() { builtintypes(underlyingElement(this), _, 63, _, _, _) }
364+
365+
override string getAPrimaryQlClass() { result = "ScalableVectorCount" }
356366
}
357367

358368
/**
@@ -1084,7 +1094,7 @@ class NullPointerType extends BuiltInType {
10841094
/**
10851095
* A C/C++ derived type.
10861096
*
1087-
* These are pointer and reference types, array and GNU vector types, and `const` and `volatile` types.
1097+
* These are pointer and reference types, array and vector types, and `const` and `volatile` types.
10881098
* In all cases, the type is formed from a single base type. For example:
10891099
* ```
10901100
* int *pi;
@@ -1643,6 +1653,26 @@ class GNUVectorType extends DerivedType {
16431653
override predicate isDeeplyConstBelow() { this.getBaseType().isDeeplyConst() }
16441654
}
16451655

1656+
/**
1657+
* An Arm Scalable vector type.
1658+
*/
1659+
class ScalableVectorType extends DerivedType {
1660+
ScalableVectorType() { derivedtypes(underlyingElement(this), _, 11, _) }
1661+
1662+
/**
1663+
* Get the number of tuple elements of this scalable vector type.
1664+
*/
1665+
int getNumTupleElements() { tupleelements(underlyingElement(this), result) }
1666+
1667+
override string getAPrimaryQlClass() { result = "ScalableVectorType" }
1668+
1669+
override int getAlignment() { arraysizes(underlyingElement(this), _, _, result) }
1670+
1671+
override string explain() { result = "scalable vector of {" + this.getBaseType().explain() + "}" }
1672+
1673+
override predicate isDeeplyConstBelow() { this.getBaseType().isDeeplyConst() }
1674+
}
1675+
16461676
/**
16471677
* A C/C++ pointer to a function. See 7.7.
16481678
* ```

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)