Skip to content

Commit 7d1b5ce

Browse files
committed
C++: Add basic Aarch64 Neon test
1 parent 8f0f200 commit 7d1b5ce

File tree

4 files changed

+254
-0
lines changed

4 files changed

+254
-0
lines changed

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,77 @@
5858
#-----| Type = [LongType] unsigned long
5959
#-----| getParameter(1): [Parameter] (unnamed parameter 1)
6060
#-----| Type = [ScopedEnum] align_val_t
61+
arm.cpp:
62+
# 6| [TopLevelFunction] uint8x8_t vadd_u8(uint8x8_t, uint8x8_t)
63+
# 6| <params>:
64+
# 6| getParameter(0): [Parameter] __a
65+
# 6| Type = [CTypedefType] uint8x8_t
66+
# 6| getParameter(1): [Parameter] __b
67+
# 6| Type = [CTypedefType] uint8x8_t
68+
# 7| getEntryPoint(): [BlockStmt] { ... }
69+
# 8| getStmt(0): [ReturnStmt] return ...
70+
# 8| getExpr(): [AddExpr] ... + ...
71+
# 8| Type = [GNUVectorType] __attribute((neon_vector_type(8))) unsigned char
72+
# 8| ValueCategory = prvalue
73+
# 8| getLeftOperand(): [VariableAccess] __a
74+
# 8| Type = [CTypedefType] uint8x8_t
75+
# 8| ValueCategory = prvalue(load)
76+
# 8| getRightOperand(): [VariableAccess] __b
77+
# 8| Type = [CTypedefType] uint8x8_t
78+
# 8| ValueCategory = prvalue(load)
79+
# 13| [TopLevelFunction] uint16x8_t __builtin_aarch64_uaddlv8qi_uuu(uint8x8_t, uint8x8_t)
80+
# 13| <params>:
81+
# 13| getParameter(0): [Parameter] (unnamed parameter 0)
82+
# 13| Type = [CTypedefType] uint8x8_t
83+
# 13| getParameter(1): [Parameter] (unnamed parameter 1)
84+
# 13| Type = [CTypedefType] uint8x8_t
85+
# 15| [TopLevelFunction] uint16x8_t vaddl_u8(uint8x8_t, uint8x8_t)
86+
# 15| <params>:
87+
# 15| getParameter(0): [Parameter] __a
88+
# 15| Type = [CTypedefType] uint8x8_t
89+
# 15| getParameter(1): [Parameter] __b
90+
# 15| Type = [CTypedefType] uint8x8_t
91+
# 16| getEntryPoint(): [BlockStmt] { ... }
92+
# 17| getStmt(0): [ReturnStmt] return ...
93+
# 17| getExpr(): [FunctionCall] call to __builtin_aarch64_uaddlv8qi_uuu
94+
# 17| Type = [CTypedefType] uint16x8_t
95+
# 17| ValueCategory = prvalue
96+
# 17| getArgument(0): [VariableAccess] __a
97+
# 17| Type = [CTypedefType] uint8x8_t
98+
# 17| ValueCategory = prvalue(load)
99+
# 17| getArgument(1): [VariableAccess] __b
100+
# 17| Type = [CTypedefType] uint8x8_t
101+
# 17| ValueCategory = prvalue(load)
102+
# 20| [TopLevelFunction] uint16x8_t arm_add(uint8x8_t, uint8x8_t)
103+
# 20| <params>:
104+
# 20| getParameter(0): [Parameter] a
105+
# 20| Type = [CTypedefType] uint8x8_t
106+
# 20| getParameter(1): [Parameter] b
107+
# 20| Type = [CTypedefType] uint8x8_t
108+
# 20| getEntryPoint(): [BlockStmt] { ... }
109+
# 21| getStmt(0): [DeclStmt] declaration
110+
# 21| getDeclarationEntry(0): [VariableDeclarationEntry] definition of c
111+
# 21| Type = [CTypedefType] uint8x8_t
112+
# 21| getVariable().getInitializer(): [Initializer] initializer for c
113+
# 21| getExpr(): [FunctionCall] call to vadd_u8
114+
# 21| Type = [CTypedefType] uint8x8_t
115+
# 21| ValueCategory = prvalue
116+
# 21| getArgument(0): [VariableAccess] a
117+
# 21| Type = [CTypedefType] uint8x8_t
118+
# 21| ValueCategory = prvalue(load)
119+
# 21| getArgument(1): [VariableAccess] b
120+
# 21| Type = [CTypedefType] uint8x8_t
121+
# 21| ValueCategory = prvalue(load)
122+
# 22| getStmt(1): [ReturnStmt] return ...
123+
# 22| getExpr(): [FunctionCall] call to vaddl_u8
124+
# 22| Type = [CTypedefType] uint16x8_t
125+
# 22| ValueCategory = prvalue
126+
# 22| getArgument(0): [VariableAccess] a
127+
# 22| Type = [CTypedefType] uint8x8_t
128+
# 22| ValueCategory = prvalue(load)
129+
# 22| getArgument(1): [VariableAccess] c
130+
# 22| Type = [CTypedefType] uint8x8_t
131+
# 22| ValueCategory = prvalue(load)
61132
bad_asts.cpp:
62133
# 5| [CopyAssignmentOperator] Bad::S& Bad::S::operator=(Bad::S const&)
63134
# 5| <params>:

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,86 @@
1+
arm.cpp:
2+
# 6| uint8x8_t vadd_u8(uint8x8_t, uint8x8_t)
3+
# 6| Block 0
4+
# 6| v6_1(void) = EnterFunction :
5+
# 6| m6_2(unknown) = AliasedDefinition :
6+
# 6| m6_3(unknown) = InitializeNonLocal :
7+
# 6| m6_4(unknown) = Chi : total:m6_2, partial:m6_3
8+
# 6| r6_5(glval<__attribute((neon_vector_type(8))) unsigned char>) = VariableAddress[__a] :
9+
# 6| m6_6(__attribute((neon_vector_type(8))) unsigned char) = InitializeParameter[__a] : &:r6_5
10+
# 6| r6_7(glval<__attribute((neon_vector_type(8))) unsigned char>) = VariableAddress[__b] :
11+
# 6| m6_8(__attribute((neon_vector_type(8))) unsigned char) = InitializeParameter[__b] : &:r6_7
12+
# 8| r8_1(glval<__attribute((neon_vector_type(8))) unsigned char>) = VariableAddress[#return] :
13+
# 8| r8_2(glval<__attribute((neon_vector_type(8))) unsigned char>) = VariableAddress[__a] :
14+
# 8| r8_3(__attribute((neon_vector_type(8))) unsigned char) = Load[__a] : &:r8_2, m6_6
15+
# 8| r8_4(glval<__attribute((neon_vector_type(8))) unsigned char>) = VariableAddress[__b] :
16+
# 8| r8_5(__attribute((neon_vector_type(8))) unsigned char) = Load[__b] : &:r8_4, m6_8
17+
# 8| r8_6(__attribute((neon_vector_type(8))) unsigned char) = Add : r8_3, r8_5
18+
# 8| m8_7(__attribute((neon_vector_type(8))) unsigned char) = Store[#return] : &:r8_1, r8_6
19+
# 6| r6_9(glval<__attribute((neon_vector_type(8))) unsigned char>) = VariableAddress[#return] :
20+
# 6| v6_10(void) = ReturnValue : &:r6_9, m8_7
21+
# 6| v6_11(void) = AliasedUse : m6_3
22+
# 6| v6_12(void) = ExitFunction :
23+
24+
# 15| uint16x8_t vaddl_u8(uint8x8_t, uint8x8_t)
25+
# 15| Block 0
26+
# 15| v15_1(void) = EnterFunction :
27+
# 15| m15_2(unknown) = AliasedDefinition :
28+
# 15| m15_3(unknown) = InitializeNonLocal :
29+
# 15| m15_4(unknown) = Chi : total:m15_2, partial:m15_3
30+
# 15| r15_5(glval<__attribute((neon_vector_type(8))) unsigned char>) = VariableAddress[__a] :
31+
# 15| m15_6(__attribute((neon_vector_type(8))) unsigned char) = InitializeParameter[__a] : &:r15_5
32+
# 15| r15_7(glval<__attribute((neon_vector_type(8))) unsigned char>) = VariableAddress[__b] :
33+
# 15| m15_8(__attribute((neon_vector_type(8))) unsigned char) = InitializeParameter[__b] : &:r15_7
34+
# 17| r17_1(glval<__attribute((neon_vector_type(8))) unsigned short>) = VariableAddress[#return] :
35+
# 17| r17_2(glval<unknown>) = FunctionAddress[__builtin_aarch64_uaddlv8qi_uuu] :
36+
# 17| r17_3(glval<__attribute((neon_vector_type(8))) unsigned char>) = VariableAddress[__a] :
37+
# 17| r17_4(__attribute((neon_vector_type(8))) unsigned char) = Load[__a] : &:r17_3, m15_6
38+
# 17| r17_5(glval<__attribute((neon_vector_type(8))) unsigned char>) = VariableAddress[__b] :
39+
# 17| r17_6(__attribute((neon_vector_type(8))) unsigned char) = Load[__b] : &:r17_5, m15_8
40+
# 17| r17_7(__attribute((neon_vector_type(8))) unsigned short) = Call[__builtin_aarch64_uaddlv8qi_uuu] : func:r17_2, 0:r17_4, 1:r17_6
41+
# 17| m17_8(unknown) = ^CallSideEffect : ~m15_4
42+
# 17| m17_9(unknown) = Chi : total:m15_4, partial:m17_8
43+
# 17| m17_10(__attribute((neon_vector_type(8))) unsigned short) = Store[#return] : &:r17_1, r17_7
44+
# 15| r15_9(glval<__attribute((neon_vector_type(8))) unsigned short>) = VariableAddress[#return] :
45+
# 15| v15_10(void) = ReturnValue : &:r15_9, m17_10
46+
# 15| v15_11(void) = AliasedUse : ~m17_9
47+
# 15| v15_12(void) = ExitFunction :
48+
49+
# 20| uint16x8_t arm_add(uint8x8_t, uint8x8_t)
50+
# 20| Block 0
51+
# 20| v20_1(void) = EnterFunction :
52+
# 20| m20_2(unknown) = AliasedDefinition :
53+
# 20| m20_3(unknown) = InitializeNonLocal :
54+
# 20| m20_4(unknown) = Chi : total:m20_2, partial:m20_3
55+
# 20| r20_5(glval<__attribute((neon_vector_type(8))) unsigned char>) = VariableAddress[a] :
56+
# 20| m20_6(__attribute((neon_vector_type(8))) unsigned char) = InitializeParameter[a] : &:r20_5
57+
# 20| r20_7(glval<__attribute((neon_vector_type(8))) unsigned char>) = VariableAddress[b] :
58+
# 20| m20_8(__attribute((neon_vector_type(8))) unsigned char) = InitializeParameter[b] : &:r20_7
59+
# 21| r21_1(glval<__attribute((neon_vector_type(8))) unsigned char>) = VariableAddress[c] :
60+
# 21| r21_2(glval<unknown>) = FunctionAddress[vadd_u8] :
61+
# 21| r21_3(glval<__attribute((neon_vector_type(8))) unsigned char>) = VariableAddress[a] :
62+
# 21| r21_4(__attribute((neon_vector_type(8))) unsigned char) = Load[a] : &:r21_3, m20_6
63+
# 21| r21_5(glval<__attribute((neon_vector_type(8))) unsigned char>) = VariableAddress[b] :
64+
# 21| r21_6(__attribute((neon_vector_type(8))) unsigned char) = Load[b] : &:r21_5, m20_8
65+
# 21| r21_7(__attribute((neon_vector_type(8))) unsigned char) = Call[vadd_u8] : func:r21_2, 0:r21_4, 1:r21_6
66+
# 21| m21_8(unknown) = ^CallSideEffect : ~m20_4
67+
# 21| m21_9(unknown) = Chi : total:m20_4, partial:m21_8
68+
# 21| m21_10(__attribute((neon_vector_type(8))) unsigned char) = Store[c] : &:r21_1, r21_7
69+
# 22| r22_1(glval<__attribute((neon_vector_type(8))) unsigned short>) = VariableAddress[#return] :
70+
# 22| r22_2(glval<unknown>) = FunctionAddress[vaddl_u8] :
71+
# 22| r22_3(glval<__attribute((neon_vector_type(8))) unsigned char>) = VariableAddress[a] :
72+
# 22| r22_4(__attribute((neon_vector_type(8))) unsigned char) = Load[a] : &:r22_3, m20_6
73+
# 22| r22_5(glval<__attribute((neon_vector_type(8))) unsigned char>) = VariableAddress[c] :
74+
# 22| r22_6(__attribute((neon_vector_type(8))) unsigned char) = Load[c] : &:r22_5, m21_10
75+
# 22| r22_7(__attribute((neon_vector_type(8))) unsigned short) = Call[vaddl_u8] : func:r22_2, 0:r22_4, 1:r22_6
76+
# 22| m22_8(unknown) = ^CallSideEffect : ~m21_9
77+
# 22| m22_9(unknown) = Chi : total:m21_9, partial:m22_8
78+
# 22| m22_10(__attribute((neon_vector_type(8))) unsigned short) = Store[#return] : &:r22_1, r22_7
79+
# 20| r20_9(glval<__attribute((neon_vector_type(8))) unsigned short>) = VariableAddress[#return] :
80+
# 20| v20_10(void) = ReturnValue : &:r20_9, m22_10
81+
# 20| v20_11(void) = AliasedUse : ~m22_9
82+
# 20| v20_12(void) = ExitFunction :
83+
184
bad_asts.cpp:
285
# 9| int Bad::S::MemberFunction<int 6>(int)
386
# 9| Block 0
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// semmle-extractor-options: --edg --target --edg linux_arm64
2+
3+
typedef __Uint8x8_t uint8x8_t;
4+
typedef __Uint16x8_t uint16x8_t;
5+
6+
uint8x8_t vadd_u8 (uint8x8_t __a, uint8x8_t __b)
7+
{
8+
return __a + __b;
9+
}
10+
11+
// Workaround: the frontend only exposes this when the arm_neon.h
12+
// header is encountered.
13+
uint16x8_t __builtin_aarch64_uaddlv8qi_uuu(uint8x8_t, uint8x8_t);
14+
15+
uint16x8_t vaddl_u8 (uint8x8_t __a, uint8x8_t __b)
16+
{
17+
return __builtin_aarch64_uaddlv8qi_uuu (__a, __b);
18+
}
19+
20+
uint16x8_t arm_add(uint8x8_t a, uint8x8_t b) {
21+
uint8x8_t c = vadd_u8(a, b);
22+
return vaddl_u8(a, c);
23+
}

0 commit comments

Comments
 (0)