Skip to content

Commit 676289e

Browse files
authored
Merge pull request #19845 from jketema/ir-sve
C++: Handle Arm SVE in the IR
2 parents 2218a98 + ca96138 commit 676289e

File tree

8 files changed

+338
-188
lines changed

8 files changed

+338
-188
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/SideEffects.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ private predicate isDeeplyConstBelow(Type t) {
5454
or
5555
isDeeplyConst(t.(GNUVectorType).getBaseType())
5656
or
57+
isDeeplyConst(t.(ScalableVectorType).getBaseType())
58+
or
5759
isDeeplyConst(t.(FunctionPointerIshType).getBaseType())
5860
or
5961
isDeeplyConst(t.(PointerWrapper).getTemplateArgument(0))

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ private int getTypeSizeWorkaround(Type type) {
2929
not arrayType.hasArraySize() and
3030
result = getPointerSize()
3131
)
32+
or
33+
// Scalable vectors are opaque and not of fixed size. Use 0 as a substitute.
34+
type instanceof ScalableVectorType and
35+
result = 0
3236
)
3337
)
3438
}
@@ -136,6 +140,8 @@ private predicate isOpaqueType(Type type) {
136140
type instanceof PointerToMemberType // PTMs are missing size info
137141
or
138142
type instanceof ScalableVectorCount
143+
or
144+
type instanceof ScalableVectorType
139145
}
140146

141147
/**

cpp/ql/test/library-tests/ir/ir/PrintAST.expected

Lines changed: 98 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
#-----| Type = [LongType] unsigned long
5959
#-----| getParameter(1): [Parameter] (unnamed parameter 1)
6060
#-----| Type = [ScopedEnum] align_val_t
61-
arm.cpp:
61+
arm_neon.cpp:
6262
# 6| [TopLevelFunction] uint8x8_t vadd_u8(uint8x8_t, uint8x8_t)
6363
# 6| <params>:
6464
# 6| getParameter(0): [Parameter] a
@@ -76,59 +76,105 @@ arm.cpp:
7676
# 7| getRightOperand(): [VariableAccess] b
7777
# 7| Type = [CTypedefType] uint8x8_t
7878
# 7| ValueCategory = prvalue(load)
79-
# 12| [TopLevelFunction] uint16x8_t __builtin_aarch64_uaddlv8qi_uuu(uint8x8_t, uint8x8_t)
79+
# 10| [TopLevelFunction] uint16x8_t vaddl_u8(uint8x8_t, uint8x8_t)
80+
# 10| <params>:
81+
# 10| getParameter(0): [Parameter] a
82+
# 10| Type = [CTypedefType] uint8x8_t
83+
# 10| getParameter(1): [Parameter] b
84+
# 10| Type = [CTypedefType] uint8x8_t
85+
# 12| [TopLevelFunction] uint16x8_t arm_add(uint8x8_t, uint8x8_t*)
8086
# 12| <params>:
81-
# 12| getParameter(0): [Parameter] (unnamed parameter 0)
82-
# 12| Type = [CTypedefType] uint8x8_t
83-
# 12| getParameter(1): [Parameter] (unnamed parameter 1)
87+
# 12| getParameter(0): [Parameter] a
8488
# 12| Type = [CTypedefType] uint8x8_t
85-
# 14| [TopLevelFunction] uint16x8_t vaddl_u8(uint8x8_t, uint8x8_t)
86-
# 14| <params>:
87-
# 14| getParameter(0): [Parameter] a
88-
# 14| Type = [CTypedefType] uint8x8_t
89-
# 14| getParameter(1): [Parameter] b
90-
# 14| Type = [CTypedefType] uint8x8_t
91-
# 14| getEntryPoint(): [BlockStmt] { ... }
92-
# 15| getStmt(0): [ReturnStmt] return ...
93-
# 15| getExpr(): [FunctionCall] call to __builtin_aarch64_uaddlv8qi_uuu
94-
# 15| Type = [CTypedefType] uint16x8_t
95-
# 15| ValueCategory = prvalue
96-
# 15| getArgument(0): [VariableAccess] a
97-
# 15| Type = [CTypedefType] uint8x8_t
98-
# 15| ValueCategory = prvalue(load)
99-
# 15| getArgument(1): [VariableAccess] b
100-
# 15| Type = [CTypedefType] uint8x8_t
101-
# 15| ValueCategory = prvalue(load)
102-
# 18| [TopLevelFunction] uint16x8_t arm_add(uint8x8_t, uint8x8_t)
103-
# 18| <params>:
104-
# 18| getParameter(0): [Parameter] a
105-
# 18| Type = [CTypedefType] uint8x8_t
106-
# 18| getParameter(1): [Parameter] b
107-
# 18| Type = [CTypedefType] uint8x8_t
108-
# 18| getEntryPoint(): [BlockStmt] { ... }
109-
# 19| getStmt(0): [DeclStmt] declaration
110-
# 19| getDeclarationEntry(0): [VariableDeclarationEntry] definition of c
111-
# 19| Type = [CTypedefType] uint8x8_t
112-
# 19| getVariable().getInitializer(): [Initializer] initializer for c
113-
# 19| getExpr(): [FunctionCall] call to vadd_u8
114-
# 19| Type = [CTypedefType] uint8x8_t
115-
# 19| ValueCategory = prvalue
116-
# 19| getArgument(0): [VariableAccess] a
117-
# 19| Type = [CTypedefType] uint8x8_t
118-
# 19| ValueCategory = prvalue(load)
119-
# 19| getArgument(1): [VariableAccess] b
120-
# 19| Type = [CTypedefType] uint8x8_t
121-
# 19| ValueCategory = prvalue(load)
122-
# 20| getStmt(1): [ReturnStmt] return ...
123-
# 20| getExpr(): [FunctionCall] call to vaddl_u8
124-
# 20| Type = [CTypedefType] uint16x8_t
125-
# 20| ValueCategory = prvalue
126-
# 20| getArgument(0): [VariableAccess] a
127-
# 20| Type = [CTypedefType] uint8x8_t
128-
# 20| ValueCategory = prvalue(load)
129-
# 20| getArgument(1): [VariableAccess] c
130-
# 20| Type = [CTypedefType] uint8x8_t
131-
# 20| ValueCategory = prvalue(load)
89+
# 12| getParameter(1): [Parameter] b
90+
# 12| Type = [PointerType] uint8x8_t *
91+
# 12| getEntryPoint(): [BlockStmt] { ... }
92+
# 13| getStmt(0): [DeclStmt] declaration
93+
# 13| getDeclarationEntry(0): [VariableDeclarationEntry] definition of c
94+
# 13| Type = [CTypedefType] uint8x8_t
95+
# 13| getVariable().getInitializer(): [Initializer] initializer for c
96+
# 13| getExpr(): [FunctionCall] call to vadd_u8
97+
# 13| Type = [CTypedefType] uint8x8_t
98+
# 13| ValueCategory = prvalue
99+
# 13| getArgument(0): [VariableAccess] a
100+
# 13| Type = [CTypedefType] uint8x8_t
101+
# 13| ValueCategory = prvalue(load)
102+
# 13| getArgument(1): [PointerDereferenceExpr] * ...
103+
# 13| Type = [CTypedefType] uint8x8_t
104+
# 13| ValueCategory = prvalue(load)
105+
# 13| getOperand(): [VariableAccess] b
106+
# 13| Type = [PointerType] uint8x8_t *
107+
# 13| ValueCategory = prvalue(load)
108+
# 14| getStmt(1): [ReturnStmt] return ...
109+
# 14| getExpr(): [FunctionCall] call to vaddl_u8
110+
# 14| Type = [CTypedefType] uint16x8_t
111+
# 14| ValueCategory = prvalue
112+
# 14| getArgument(0): [VariableAccess] a
113+
# 14| Type = [CTypedefType] uint8x8_t
114+
# 14| ValueCategory = prvalue(load)
115+
# 14| getArgument(1): [VariableAccess] c
116+
# 14| Type = [CTypedefType] uint8x8_t
117+
# 14| ValueCategory = prvalue(load)
118+
# 20| [TopLevelFunction] mfloat8x8_t vreinterpret_mf8_s8(int8x8_t)
119+
# 20| <params>:
120+
# 20| getParameter(0): [Parameter] (unnamed parameter 0)
121+
# 20| Type = [CTypedefType] int8x8_t
122+
# 22| [TopLevelFunction] mfloat8x8_t arm_reinterpret(int8x8_t*)
123+
# 22| <params>:
124+
# 22| getParameter(0): [Parameter] a
125+
# 22| Type = [PointerType] int8x8_t *
126+
# 22| getEntryPoint(): [BlockStmt] { ... }
127+
# 23| getStmt(0): [ReturnStmt] return ...
128+
# 23| getExpr(): [FunctionCall] call to vreinterpret_mf8_s8
129+
# 23| Type = [CTypedefType] mfloat8x8_t
130+
# 23| ValueCategory = prvalue
131+
# 23| getArgument(0): [PointerDereferenceExpr] * ...
132+
# 23| Type = [CTypedefType] int8x8_t
133+
# 23| ValueCategory = prvalue(load)
134+
# 23| getOperand(): [VariableAccess] a
135+
# 23| Type = [PointerType] int8x8_t *
136+
# 23| ValueCategory = prvalue(load)
137+
arm_sve.cpp:
138+
# 6| [TopLevelFunction] svuint8x2_t svsel_u8_x2(svcount_t, svuint8x2_t, svuint8x2_t)
139+
# 6| <params>:
140+
# 6| getParameter(0): [Parameter] (unnamed parameter 0)
141+
# 6| Type = [CTypedefType] svcount_t
142+
# 6| getParameter(1): [Parameter] (unnamed parameter 1)
143+
# 6| Type = [CTypedefType] svuint8x2_t
144+
# 6| getParameter(2): [Parameter] (unnamed parameter 2)
145+
# 6| Type = [CTypedefType] svuint8x2_t
146+
# 8| [TopLevelFunction] svuint8x2_t arm_sel(svcount_t, svuint8x2_t, svuint8x2_t*)
147+
# 8| <params>:
148+
# 8| getParameter(0): [Parameter] a
149+
# 8| Type = [CTypedefType] svcount_t
150+
# 8| getParameter(1): [Parameter] b
151+
# 8| Type = [CTypedefType] svuint8x2_t
152+
# 8| getParameter(2): [Parameter] c
153+
# 8| Type = [PointerType] svuint8x2_t *
154+
# 8| getEntryPoint(): [BlockStmt] { ... }
155+
# 9| getStmt(0): [DeclStmt] declaration
156+
# 9| getDeclarationEntry(0): [VariableDeclarationEntry] definition of d
157+
# 9| Type = [CTypedefType] svuint8x2_t
158+
# 9| getVariable().getInitializer(): [Initializer] initializer for d
159+
# 9| getExpr(): [FunctionCall] call to svsel_u8_x2
160+
# 9| Type = [CTypedefType] svuint8x2_t
161+
# 9| ValueCategory = prvalue
162+
# 9| getArgument(0): [VariableAccess] a
163+
# 9| Type = [CTypedefType] svcount_t
164+
# 9| ValueCategory = prvalue(load)
165+
# 9| getArgument(1): [VariableAccess] b
166+
# 9| Type = [CTypedefType] svuint8x2_t
167+
# 9| ValueCategory = prvalue(load)
168+
# 9| getArgument(2): [PointerDereferenceExpr] * ...
169+
# 9| Type = [CTypedefType] svuint8x2_t
170+
# 9| ValueCategory = prvalue(load)
171+
# 9| getOperand(): [VariableAccess] c
172+
# 9| Type = [PointerType] svuint8x2_t *
173+
# 9| ValueCategory = prvalue(load)
174+
# 10| getStmt(1): [ReturnStmt] return ...
175+
# 10| getExpr(): [VariableAccess] d
176+
# 10| Type = [CTypedefType] svuint8x2_t
177+
# 10| ValueCategory = prvalue(load)
132178
bad_asts.cpp:
133179
# 5| [CopyAssignmentOperator] Bad::S& Bad::S::operator=(Bad::S const&)
134180
# 5| <params>:

0 commit comments

Comments
 (0)