diff --git a/testsuite/c_test/driver_test/AST0001-HelloWorld/HelloWorld.c b/testsuite/c_test/driver_test/AST0001-HelloWorld/HelloWorld.c new file mode 100644 index 0000000000000000000000000000000000000000..1755ef20bb8edd20b0510aa99644f25041835c78 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0001-HelloWorld/HelloWorld.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +int main() { + printf("Hello world!"); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0001-HelloWorld/expected.txt b/testsuite/c_test/driver_test/AST0001-HelloWorld/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..6769dd60bdf536a83c9353272157893043e9f7d0 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0001-HelloWorld/expected.txt @@ -0,0 +1 @@ +Hello world! \ No newline at end of file diff --git a/testsuite/c_test/driver_test/AST0001-HelloWorld/test.cfg b/testsuite/c_test/driver_test/AST0001-HelloWorld/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..70d1fd11a120a7827774383a30e206f3bc7b8087 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0001-HelloWorld/test.cfg @@ -0,0 +1,2 @@ +compile(APP=HelloWorld.c,OPTION="--no-maple-phase -o HelloWorld") +run(HelloWorld) diff --git a/testsuite/c_test/driver_test/AST0002-IntPrint/IntPrint.c b/testsuite/c_test/driver_test/AST0002-IntPrint/IntPrint.c new file mode 100644 index 0000000000000000000000000000000000000000..ff457cd6fcebbe4d8dfff1f52f271ec998b7dc72 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0002-IntPrint/IntPrint.c @@ -0,0 +1,22 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +int main() { + int a = 2; + int b = 3; + printf("%d%d", a, b); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0002-IntPrint/expected.txt b/testsuite/c_test/driver_test/AST0002-IntPrint/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..b39356075901abfb43d27aef2ae5b76b6aee19c4 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0002-IntPrint/expected.txt @@ -0,0 +1 @@ +23 \ No newline at end of file diff --git a/testsuite/c_test/driver_test/AST0002-IntPrint/test.cfg b/testsuite/c_test/driver_test/AST0002-IntPrint/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..d509193f69a8b632c6d8b1101bfc1904853da1b8 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0002-IntPrint/test.cfg @@ -0,0 +1,2 @@ +compile(APP=IntPrint.c,OPTION="--no-maple-phase -o IntPrint") +run(IntPrint) diff --git a/testsuite/c_test/driver_test/AST0003-CallExpr/CallExpr.c b/testsuite/c_test/driver_test/AST0003-CallExpr/CallExpr.c new file mode 100644 index 0000000000000000000000000000000000000000..c4c51ca0e3bcf741a7bc539968ca4c5e57b17c73 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0003-CallExpr/CallExpr.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +int GetValue(int a) { + return a; +} +int AddTwo(int a, int b){ // multi param + return GetValue(a) + GetValue(b); +} +void AssignArr(int a[], int len){ // array param + for (int i = 0; i < len; i++){ + a[i] = i * 2; + } +} +void PrintArr(int a[], int len){ + int i = 0; + while (i < len){ + printf("%d", a[i]); + i++; + } + printf("\n"); +} +int CulSum(int a){ // recursive call + if (a == 1){ + return 1; + } + else{ + return a + CulSum(a - 1); + } +} + +int main() { + int b = 23; + int c = GetValue(b); + printf("%d", c); + + // add more complex cases + printf("b + c = %d\n", AddTwo(b, c)); + int arr[5]; + int len = sizeof(arr)/sizeof(int); + AssignArr(arr, len); + // PrintArr(arr, len); // @fail case, output wrong + printf("%d", CulSum(10)); + + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0003-CallExpr/expected.txt b/testsuite/c_test/driver_test/AST0003-CallExpr/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0a4b798364543ea925ac8533dc2a503c62437613 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0003-CallExpr/expected.txt @@ -0,0 +1,2 @@ +23b + c = 46 +55 \ No newline at end of file diff --git a/testsuite/c_test/driver_test/AST0003-CallExpr/test.cfg b/testsuite/c_test/driver_test/AST0003-CallExpr/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..d9db4425074e762cc954bc53b5dffaf8e926b57c --- /dev/null +++ b/testsuite/c_test/driver_test/AST0003-CallExpr/test.cfg @@ -0,0 +1,2 @@ +compile(APP=CallExpr.c,OPTION="--no-maple-phase -o CallExpr") +run(CallExpr) diff --git a/testsuite/c_test/driver_test/AST0004-SameVarName/SameVarName.c b/testsuite/c_test/driver_test/AST0004-SameVarName/SameVarName.c new file mode 100644 index 0000000000000000000000000000000000000000..cf988433154777c7e87224a6f2e9a926a39e7cf0 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0004-SameVarName/SameVarName.c @@ -0,0 +1,24 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +int a = 1; +int b = 2; + +int main() { + int a = 3; + printf("%d%d", b, a); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0004-SameVarName/expected.txt b/testsuite/c_test/driver_test/AST0004-SameVarName/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..b39356075901abfb43d27aef2ae5b76b6aee19c4 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0004-SameVarName/expected.txt @@ -0,0 +1 @@ +23 \ No newline at end of file diff --git a/testsuite/c_test/driver_test/AST0004-SameVarName/test.cfg b/testsuite/c_test/driver_test/AST0004-SameVarName/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..925a8cec62c4899d50a4b9b4403168ec17d4a9ad --- /dev/null +++ b/testsuite/c_test/driver_test/AST0004-SameVarName/test.cfg @@ -0,0 +1,2 @@ +compile(APP=SameVarName.c,OPTION="--no-maple-phase -o SameVarName") +run(SameVarName) diff --git a/testsuite/c_test/driver_test/AST0005-UnaryOperatorExpr/UnaryOperatorExpr.c b/testsuite/c_test/driver_test/AST0005-UnaryOperatorExpr/UnaryOperatorExpr.c new file mode 100644 index 0000000000000000000000000000000000000000..f7a3f0fb43634aa68872d45fb991621f0f0417dd --- /dev/null +++ b/testsuite/c_test/driver_test/AST0005-UnaryOperatorExpr/UnaryOperatorExpr.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +int a = 1; + +int main() { + int b = 10; + printf("%d", a++); + printf("%d", ++a); + printf("%d", a--); + printf("%d", --a); + printf("%d", b++); + printf("%d", ++b); + printf("%d", b--); + printf("%d", --b); + printf("\n"); + double c = 1.0; + printf("%f", c++); + printf("%f", ++c); + printf("%f", c--); + printf("%f", --c); + printf("\n"); + short d = 2; + printf("%d", d++); + printf("%d", ++d); + printf("%d", d--); + printf("%d", --d); + printf("\n"); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0005-UnaryOperatorExpr/expected.txt b/testsuite/c_test/driver_test/AST0005-UnaryOperatorExpr/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..df573c936fac09fda19cc11353233119f1bf096b --- /dev/null +++ b/testsuite/c_test/driver_test/AST0005-UnaryOperatorExpr/expected.txt @@ -0,0 +1,3 @@ +133110121210 +1.0000003.0000003.0000001.000000 +2442 diff --git a/testsuite/c_test/driver_test/AST0005-UnaryOperatorExpr/test.cfg b/testsuite/c_test/driver_test/AST0005-UnaryOperatorExpr/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..d2d3120ef11bb54e60a76333523a2286a8f01223 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0005-UnaryOperatorExpr/test.cfg @@ -0,0 +1,2 @@ +compile(APP=UnaryOperatorExpr.c,OPTION="--no-maple-phase -o UnaryOperatorExpr") +run(UnaryOperatorExpr) diff --git a/testsuite/c_test/driver_test/AST0006-ArraySubscriptExpr/ArraySubscriptExpr.c b/testsuite/c_test/driver_test/AST0006-ArraySubscriptExpr/ArraySubscriptExpr.c new file mode 100644 index 0000000000000000000000000000000000000000..824ef3825cae69731ffec2c6f193b8af8bae8482 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0006-ArraySubscriptExpr/ArraySubscriptExpr.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +int main() { + int a[3] = {1, 2, 3}; + double f[3] = {1.0, 2.1, 3.14}; + int b[10]; + b[2] = 10; + b[3] = 100; + + char c[5]; + c[3] = 'a'; + c[4] = 'b'; + + printf("%d", b[2]); + printf("%d", b[3]); + printf("%c", c[3]); + printf("%c\n", c[4]); + printf("%d%d%d", a[0], a[1], a[2]); + int a_ = a[0] + a[1] + a[2]; + printf("%d", a_); + printf("%lf%lf%lf", f[0], f[1], f[2]); + // fail cases + // double f[3] = {1, 2.1, 3.14}; + // printf("%d%d%d", a[0], a[1], a[1+1]); + // printf("%d%d%d", a[0] + a[1] + a[2]); + // double f_ = f[0] + f[1] + f[2]; + // printf("\n%d%d%d",*(a), *(a+1), *(a+2)); + // printf("%d%d%d",*&a[0], *&a[1+1], *&a[2]); + // printf("\n%f%f%f",*&f[0], *&f[1+1], *&f[2]); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0006-ArraySubscriptExpr/expected.txt b/testsuite/c_test/driver_test/AST0006-ArraySubscriptExpr/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..eaaf8c10a2bcf6c72dad4828233fefc1f9ca8dfb --- /dev/null +++ b/testsuite/c_test/driver_test/AST0006-ArraySubscriptExpr/expected.txt @@ -0,0 +1,2 @@ +10100ab +12361.0000002.1000003.140000 \ No newline at end of file diff --git a/testsuite/c_test/driver_test/AST0006-ArraySubscriptExpr/test.cfg b/testsuite/c_test/driver_test/AST0006-ArraySubscriptExpr/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..d107c03f793aed80dd27d97d37094ce0091193e8 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0006-ArraySubscriptExpr/test.cfg @@ -0,0 +1,2 @@ +compile(APP=ArraySubscriptExpr.c,OPTION="--no-maple-phase -o ArraySubscriptExpr") +run(ArraySubscriptExpr) diff --git a/testsuite/c_test/driver_test/AST0007-ConditionalOperator/ConditionalOperator.c b/testsuite/c_test/driver_test/AST0007-ConditionalOperator/ConditionalOperator.c new file mode 100644 index 0000000000000000000000000000000000000000..03b1c009e6667585743187e3dd3d32f63904529f --- /dev/null +++ b/testsuite/c_test/driver_test/AST0007-ConditionalOperator/ConditionalOperator.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +int main() { + int a = 9; + int b = (a < 10) ? 1 : 2; + printf("%d %d\n", a, b); // 9 1 + // nested false expr + b = (a < 9) ? 1 : a++; + printf("%d %d\n", a, b); // 10 9 + // multilevel conditional expr + (a < 10) ? (a = 1) : (b < 9) ? 1 : (a = 2, a++); + printf("%d %d\n", a, b); // 3 9 + // noncomparative conditional expr + double c = 0.0; + b = c++ ? 1 : a++; + printf("%d %d %f\n", a, b, c); // 4 3 1.000000 + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0007-ConditionalOperator/expected.txt b/testsuite/c_test/driver_test/AST0007-ConditionalOperator/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..55a04753cf0dffc92584e3fd72119647ec7dc967 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0007-ConditionalOperator/expected.txt @@ -0,0 +1,4 @@ +9 1 +10 9 +3 9 +4 3 1.000000 diff --git a/testsuite/c_test/driver_test/AST0007-ConditionalOperator/test.cfg b/testsuite/c_test/driver_test/AST0007-ConditionalOperator/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..73ab0445b4f047e2160430bf875768b9a567aca3 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0007-ConditionalOperator/test.cfg @@ -0,0 +1,2 @@ +compile(APP=ConditionalOperator.c,OPTION="--no-maple-phase -o ConditionalOperator") +run(ConditionalOperator) diff --git a/testsuite/c_test/driver_test/AST0008-InitListExpr-Array/InitListExpr-Array.c b/testsuite/c_test/driver_test/AST0008-InitListExpr-Array/InitListExpr-Array.c new file mode 100644 index 0000000000000000000000000000000000000000..71b373a3a32bfde465ecb1d3ce8fd691dd2341a7 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0008-InitListExpr-Array/InitListExpr-Array.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +int main() { + int arr1[10] = {1 ,2, 3}; + double arr2[10] = {1.5, 2.5 ,8.5}; + char arr3[10] = {'a', 'b'}; + char arr4[2][3] = {'a', 'b','c','d','e'}; + char arr5[2][2][2] = {{'a', 'b','c','d'},{{'b','c'},{'d','e'}}}; + printf("%d\n", arr1[2]); + printf("%f\n", arr2[2]); + printf("%c\n", arr3[0]); + printf("%c\n", arr4[1][1]); + arr4[1][1] = 'z'; + char c = arr4[1][1]; + printf("%c\n", arr4[1][1]); + printf("%c\n",c); + printf("%c\n", arr5[0][1][1]); + arr5[0][1][1] = 'w'; + char c1 = arr5[0][1][1]; + printf("%c\n",c1); + printf("%c\n", arr5[0][1][1]); + return 0; +} + diff --git a/testsuite/c_test/driver_test/AST0008-InitListExpr-Array/expected.txt b/testsuite/c_test/driver_test/AST0008-InitListExpr-Array/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..62ffe507a2eb1d354ecea6235f9efe29b486a165 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0008-InitListExpr-Array/expected.txt @@ -0,0 +1,9 @@ +3 +8.500000 +a +e +z +z +d +w +w diff --git a/testsuite/c_test/driver_test/AST0008-InitListExpr-Array/test.cfg b/testsuite/c_test/driver_test/AST0008-InitListExpr-Array/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..f81fa198757de5bf387c4b827890821d2c68adac --- /dev/null +++ b/testsuite/c_test/driver_test/AST0008-InitListExpr-Array/test.cfg @@ -0,0 +1,2 @@ +compile(APP=InitListExpr-Array.c,OPTION="--no-maple-phase -o InitListExpr-Array") +run(InitListExpr-Array) diff --git a/testsuite/c_test/driver_test/AST0009-BinaryOperatorExpr/BinaryOperatorExpr.c b/testsuite/c_test/driver_test/AST0009-BinaryOperatorExpr/BinaryOperatorExpr.c new file mode 100755 index 0000000000000000000000000000000000000000..02bf197ef0ddade61dc6a31f541111766e184a4f --- /dev/null +++ b/testsuite/c_test/driver_test/AST0009-BinaryOperatorExpr/BinaryOperatorExpr.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +int a = 1; +struct Person{ + int age; + char c_name; +}; + +int main() { + int b = 10; + int a = 2; + printf("%d + %d=%d\n", a, b, a + b); + printf("%d - %d=%d\n", a, b, a - b); + printf("%d * %d=%d\n", a, b, a * b); + printf("%d / %d=%d\n", a, b, a / b); + printf("%d %% %d=%d\n", a, b, a % b); + printf("%d << %d=%d\n", a, b, a << b); + printf("%d >> %d=%d\n", a, b, a >> b); + printf("%d > %d=%d\n", a, b, a > b); + printf("%d < %d=%d\n", a, b, a < b); + printf("%d <= %d=%d\n", a, b, a <= b); + printf("%d >= %d=%d\n", a, b, a >= b); + printf("%d == %d=%d\n", a, b, a == b); + printf("%d != %d=%d\n", a, b, a != b); + printf("%d & %d=%d\n", a, b, a & b); + printf("%d ^ %d=%d\n", a, b, a ^ b); + printf("%d | %d=%d\n", a, b, a | b); + printf("%d && %d=%d\n", a, b, a && b); + printf("%d || %d=%d\n", a, b, a || b); + printf("%d , %d=%d\n", a, b, (a, b)); + + // add more complex cases + long int l_int = -2147483647; + char c = 'a'; + unsigned int u_int = 65535; + unsigned char u_char = 128; + float flt = 123.456789f; // @fail if no 'f' at end + double db = 1.23456789; + // long double ldb = 12.3456789123456; //@fail case + double ldb = 12.3456789123456; + short int s_int = 0xa5; + int res = c + a; + printf("+:%ld%ud%.2f%f\n",(l_int + c), (u_int + u_char), (flt + db), (ldb + s_int)); + printf("-:%ld%ud%.2f%f\n",(l_int - c), (u_int - u_char), (flt - db), (ldb - s_int)); + printf("*:%ld%ud%.2f%f\n",(l_int * c), (u_int * u_char), (flt * db), (ldb * s_int)); + printf("/:%ld%ud%.2f%f\n",(l_int / c), (u_int / u_char), (flt / db), (ldb / s_int)); + // printf("%%:%ld%ud%d%d\n",(l_int % c), (u_int % u_char), ((int)flt % (int)db), ((int)ldb / (int)s_int)); //@fail case + // printf("&:%ld%ud%d%d\n",(l_int & c), (u_int & u_char), ((int)flt & (int)db), (int)ldb & (int)s_int); //@fail case + // printf("&:%ld%ud%d%d\n",(l_int | c), (u_int | u_char), ((int)flt | (int)db), (int)ldb | (int)s_int); //@fail case + // printf("&:%ld%ud%d%d\n",(l_int ^ c), (u_int ^ u_char), ((int)flt ^ (int)db), (int)ldb ^ (int)s_int); //@fail case + + struct Person p; + struct Person *ptr = &p; + p.age = 10; + p.c_name = 'p'; + printf("%d%d", ptr->age + 10, ptr->c_name + 10); + printf("%d%d", p.age + 10, p.c_name + 10); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0009-BinaryOperatorExpr/expected.txt b/testsuite/c_test/driver_test/AST0009-BinaryOperatorExpr/expected.txt new file mode 100755 index 0000000000000000000000000000000000000000..437d8426a923f273c4777e1b890849c980cd0cd4 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0009-BinaryOperatorExpr/expected.txt @@ -0,0 +1,24 @@ +2 + 10=12 +2 - 10=-8 +2 * 10=20 +2 / 10=0 +2 % 10=2 +2 << 10=2048 +2 >> 10=0 +2 > 10=0 +2 < 10=1 +2 <= 10=1 +2 >= 10=0 +2 == 10=0 +2 != 10=1 +2 & 10=2 +2 ^ 10=8 +2 | 10=10 +2 && 10=1 +2 || 10=1 +2 , 10=10 ++:-214748355065663d124.69177.345679 +-:-214748374465407d122.22-152.654321 +*:-2083059137598388480d152.422037.037021 +/:-22139006511d100.000.074822 +2012220122 \ No newline at end of file diff --git a/testsuite/c_test/driver_test/AST0009-BinaryOperatorExpr/test.cfg b/testsuite/c_test/driver_test/AST0009-BinaryOperatorExpr/test.cfg new file mode 100755 index 0000000000000000000000000000000000000000..01b93635f6cfeb512793ae886e244a5ddb3b6858 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0009-BinaryOperatorExpr/test.cfg @@ -0,0 +1,2 @@ +compile(APP=BinaryOperatorExpr.c,OPTION="--no-maple-phase -o BinaryOperatorExpr") +run(BinaryOperatorExpr) diff --git a/testsuite/c_test/driver_test/AST0010-BinaryOperatorStmt/BinaryOperatorStmt.c b/testsuite/c_test/driver_test/AST0010-BinaryOperatorStmt/BinaryOperatorStmt.c new file mode 100755 index 0000000000000000000000000000000000000000..4d961c9b2881e46bef3c55d24c53febbb92c24a9 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0010-BinaryOperatorStmt/BinaryOperatorStmt.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +int a = 1; + +int main() { + int b = 10; + int a = 2; + a + b; + a - b; + a * b; + a / b; + a % b; + a << b; + a >> b; + a > b; + a < b; + a <= b; + a >= b; + a == b; + a != b; + a & b; + a ^ b; + a | b; + a && b; + a || b; + printf("ok\n"); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0010-BinaryOperatorStmt/expected.txt b/testsuite/c_test/driver_test/AST0010-BinaryOperatorStmt/expected.txt new file mode 100755 index 0000000000000000000000000000000000000000..9766475a4185a151dc9d56d614ffb9aaea3bfd42 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0010-BinaryOperatorStmt/expected.txt @@ -0,0 +1 @@ +ok diff --git a/testsuite/c_test/driver_test/AST0010-BinaryOperatorStmt/test.cfg b/testsuite/c_test/driver_test/AST0010-BinaryOperatorStmt/test.cfg new file mode 100755 index 0000000000000000000000000000000000000000..86f50d8929b8813949bc76274f2bceb473bf1389 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0010-BinaryOperatorStmt/test.cfg @@ -0,0 +1,2 @@ +compile(APP=BinaryOperatorStmt.c,OPTION="--no-maple-phase -o BinaryOperatorStmt") +run(BinaryOperatorStmt) diff --git a/testsuite/c_test/driver_test/AST0011-MemberExpr/MemberExpr.c b/testsuite/c_test/driver_test/AST0011-MemberExpr/MemberExpr.c new file mode 100755 index 0000000000000000000000000000000000000000..e8c17969573e167b5683195de00b0005fd84dbd1 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0011-MemberExpr/MemberExpr.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +struct A { + int a; + int b; +}; +struct B { + struct A a; + struct A *pa; + int d; + char c; + double f[1]; +}; + +int main() { + struct A a; + struct A *pa = &a; + a.a = 1; + a.b = 2; + printf("%d,", a.a); + printf("%d,", a.b); + printf("%d,", pa->a); + printf("%d\n", pa->b); + + // add more cases + struct B b; + struct B *pb = &b; + b.pa = &a; + b.a.a = 11; + b.a.b = 22; + b.d = -32766; + b.c = 'b'; + printf("%c", pb->c); + printf("%d", b.d); + b.f[0] = 1.1; + printf("%d\n", pb->a.a + pb->a.b + pb->d); + b.pa = &b.a; + printf("%d%d", b.pa->a, b.pa->b); + printf("%d", b.a.a + b.a.b + b.d); + + struct C { + struct B b; + struct B *pb; + } c; + c.pb = &c.b; + struct C *pc = &c; + c.b = b; + pc->b = b; + c.b.pa = &a; + c.b.a.a = 11; + c.b.a.b = 22; + c.b.d = -32766; + c.b.c = 'b'; + // c.b.f[0] = 1.11; // fail case + c.b.pa = &c.b.a; + printf("%c%c%c%c", c.b.c, pc->b.c, c.pb->c, pc->pb->c); + printf("%d%d%d%d", c.b.pa->a, c.b.a.a, c.pb->a.a, c.pb->pa->a); + printf("%d%d%d%d", pc->b.pa->a, pc->b.a.a, pc->pb->a.a, pc->pb->pa->a); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0011-MemberExpr/expected.txt b/testsuite/c_test/driver_test/AST0011-MemberExpr/expected.txt new file mode 100755 index 0000000000000000000000000000000000000000..16b8d24d1e0f6163e982555c084d09d73c2f34b9 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0011-MemberExpr/expected.txt @@ -0,0 +1,3 @@ +1,2,1,2 +b-32766-32733 +1122-32733bbbb1111111111111111 \ No newline at end of file diff --git a/testsuite/c_test/driver_test/AST0011-MemberExpr/test.cfg b/testsuite/c_test/driver_test/AST0011-MemberExpr/test.cfg new file mode 100755 index 0000000000000000000000000000000000000000..25c8b7a8beac8419d2f634c1f4a99d020ebb96a4 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0011-MemberExpr/test.cfg @@ -0,0 +1,2 @@ +compile(APP=MemberExpr.c,OPTION="--no-maple-phase -o MemberExpr") +run(MemberExpr) diff --git a/testsuite/c_test/driver_test/AST0012-AssignExpr/AssignExpr.c b/testsuite/c_test/driver_test/AST0012-AssignExpr/AssignExpr.c new file mode 100755 index 0000000000000000000000000000000000000000..db9c32123f5c4ecfb955a49d9d9dbc16386e1d76 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0012-AssignExpr/AssignExpr.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +struct A { + int a; + int b; +}; + +int main() { + int a = 0; + int b = 1; + int c = 2; + int *pb = &b; + int *pc = &c; + struct A sa; + struct A sb; + struct A *psb = &sb; + sa.a = 0; + sa.b = 0; + sb.a = 0; + sb.b = 0; + printf("%d,", a); + a = 1; + printf("%d,", a); + printf("%d,", *pb); + pb = pc; + printf("%d,", *pc); + *pc = 4; + printf("%d,", *pc); + printf("%d,", sa.a); + printf("%d,", sa.b); + sa.a = 1; + sa.b = 2; + printf("%d,", sa.a); + printf("%d,", sa.b); + printf("%d,", psb->a); + printf("%d,", psb->b); + psb->a = 3; + psb->b = 4; + printf("%d,", psb->a); + printf("%d,", psb->b); + + int arr[] = {1,2,3,4,5}; + int *parr = arr; + printf("%d,", *(arr + 1)); + printf("%d,", *(1 + arr)); + printf("%d\n", *(1 + arr - 2 + 1)); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0012-AssignExpr/expected.txt b/testsuite/c_test/driver_test/AST0012-AssignExpr/expected.txt new file mode 100755 index 0000000000000000000000000000000000000000..5bd06043f44ca78d742f3c0c28475a921203c3a1 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0012-AssignExpr/expected.txt @@ -0,0 +1 @@ +0,1,1,2,4,0,0,1,2,0,0,3,4,2,2,1 diff --git a/testsuite/c_test/driver_test/AST0012-AssignExpr/test.cfg b/testsuite/c_test/driver_test/AST0012-AssignExpr/test.cfg new file mode 100755 index 0000000000000000000000000000000000000000..4c20af46f07ede2b3286547d578e0803b8054031 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0012-AssignExpr/test.cfg @@ -0,0 +1,2 @@ +compile(APP=AssignExpr.c,OPTION="--no-maple-phase -o AssignExpr") +run(AssignExpr) diff --git a/testsuite/c_test/driver_test/AST0013-IfStmt/IfStmt.c b/testsuite/c_test/driver_test/AST0013-IfStmt/IfStmt.c new file mode 100755 index 0000000000000000000000000000000000000000..d842b98281b9d1bca8bbdad0f0076765e12b788f --- /dev/null +++ b/testsuite/c_test/driver_test/AST0013-IfStmt/IfStmt.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +int main() { + int a = 1; + int b = 0; + if (a) { + printf("1,"); + } + if (b) { + printf("failed"); + } + if (a) { + printf("1,"); + } else { + printf("failed"); + } + if (b) { + printf("failed"); + } else { + printf("1\n"); + } + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0013-IfStmt/expected.txt b/testsuite/c_test/driver_test/AST0013-IfStmt/expected.txt new file mode 100755 index 0000000000000000000000000000000000000000..5b8274e039ab99fdbbc827ab684a1380855e16d4 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0013-IfStmt/expected.txt @@ -0,0 +1 @@ +1,1,1 diff --git a/testsuite/c_test/driver_test/AST0013-IfStmt/test.cfg b/testsuite/c_test/driver_test/AST0013-IfStmt/test.cfg new file mode 100755 index 0000000000000000000000000000000000000000..9778f942f2a2fbef76230ce590d8a4bbf568419b --- /dev/null +++ b/testsuite/c_test/driver_test/AST0013-IfStmt/test.cfg @@ -0,0 +1,2 @@ +compile(APP=IfStmt.c,OPTION="--no-maple-phase -o IfStmt") +run(IfStmt) diff --git a/testsuite/c_test/driver_test/AST0014-ForStmt/ForStmt.c b/testsuite/c_test/driver_test/AST0014-ForStmt/ForStmt.c new file mode 100755 index 0000000000000000000000000000000000000000..59a44f500034edf139fc6915649492f599d65152 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0014-ForStmt/ForStmt.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +int main() { + for (int i = 0; i < 5; i++) { + printf("%d,", i); + } + int a = 0; + for (; a < 5; a++) { + printf("%d,", a); + } + int b = 0; + for (;; b++) { + printf("%d,", b); + if (b >= 5) { + break; + } + } + int c = 10; + for (;;) { + printf("%d,", c); + c = c - 1; + if (c <= 5) { + break; + } + } + for (int i = 0; i < 5; i++) { + if (i == 2) { + continue; + } + printf("%d,", i); + } + printf("0\n"); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0014-ForStmt/expected.txt b/testsuite/c_test/driver_test/AST0014-ForStmt/expected.txt new file mode 100755 index 0000000000000000000000000000000000000000..242b3354ac73ded78b394edc41668ca7e7bc84cb --- /dev/null +++ b/testsuite/c_test/driver_test/AST0014-ForStmt/expected.txt @@ -0,0 +1 @@ +0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,5,10,9,8,7,6,0,1,3,4,0 diff --git a/testsuite/c_test/driver_test/AST0014-ForStmt/test.cfg b/testsuite/c_test/driver_test/AST0014-ForStmt/test.cfg new file mode 100755 index 0000000000000000000000000000000000000000..823af40a9bb918e303f6a95bedd6609d255ec873 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0014-ForStmt/test.cfg @@ -0,0 +1,2 @@ +compile(APP=ForStmt.c,OPTION="--no-maple-phase -o ForStmt") +run(ForStmt) diff --git a/testsuite/c_test/driver_test/AST0015-DoStmt/DoStmt.c b/testsuite/c_test/driver_test/AST0015-DoStmt/DoStmt.c new file mode 100755 index 0000000000000000000000000000000000000000..890e821898ebf084dfb0f4ccf4b99b97a34cc151 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0015-DoStmt/DoStmt.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +int main() { + int i = 0; + do { + printf("%d,", i); + if (i == 3) { + continue; + } + } while (++i < 5); + i = 0; + do { + printf("%d,", i); + if (i == 3) { + break; + } + } while (++i < 5); + i = 0; + do { + i = i + 1; + printf("%d,", i); + if (i == 3) { + break; + } + } while (i < 5); + i = 0; + do { + i = i + 1; + printf("%d,", i); + if (i == 3) { + continue; + } + } while (i < 5); + printf("0\n"); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0015-DoStmt/expected.txt b/testsuite/c_test/driver_test/AST0015-DoStmt/expected.txt new file mode 100755 index 0000000000000000000000000000000000000000..f56a9ced10771aa246ddb23236deb20e09b3f88f --- /dev/null +++ b/testsuite/c_test/driver_test/AST0015-DoStmt/expected.txt @@ -0,0 +1 @@ +0,1,2,3,4,0,1,2,3,1,2,3,1,2,3,4,5,0 diff --git a/testsuite/c_test/driver_test/AST0015-DoStmt/test.cfg b/testsuite/c_test/driver_test/AST0015-DoStmt/test.cfg new file mode 100755 index 0000000000000000000000000000000000000000..4f700435e5f6a655393214e6edd14329752b3177 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0015-DoStmt/test.cfg @@ -0,0 +1,2 @@ +compile(APP=DoStmt.c,OPTION="--no-maple-phase -o DoStmt") +run(DoStmt) diff --git a/testsuite/c_test/driver_test/AST0016-WhileStmt/WhileStmt.c b/testsuite/c_test/driver_test/AST0016-WhileStmt/WhileStmt.c new file mode 100755 index 0000000000000000000000000000000000000000..e9f6094f97efb3973942d3aed19ad41d9ab29574 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0016-WhileStmt/WhileStmt.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +int main() { + int i = 0; + while (++i < 5) { + if (i == 3) { + continue; + } + printf("%d,", i); + } + i = 0; + while (++i < 5) { + if (i == 3) { + break; + } + printf("%d,", i); + } + i = 1; + while (i) { + i = i + 1; + printf("%d,", i); + if (i > 3) { + i = 0; + } + } + int a = 0; + while (1) { + if (a >= 5) { + break; + } + printf("%d,", a); + a = a + 1; + } + printf("0\n"); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0016-WhileStmt/expected.txt b/testsuite/c_test/driver_test/AST0016-WhileStmt/expected.txt new file mode 100755 index 0000000000000000000000000000000000000000..bc2ea163a0dd73f7d605c2d636a9201c9805d785 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0016-WhileStmt/expected.txt @@ -0,0 +1 @@ +1,2,4,1,2,2,3,4,0,1,2,3,4,0 diff --git a/testsuite/c_test/driver_test/AST0016-WhileStmt/test.cfg b/testsuite/c_test/driver_test/AST0016-WhileStmt/test.cfg new file mode 100755 index 0000000000000000000000000000000000000000..f6dc0054ee47485e32d2b4c771c189f5e963fcd1 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0016-WhileStmt/test.cfg @@ -0,0 +1,2 @@ +compile(APP=WhileStmt.c,OPTION="--no-maple-phase -o WhileStmt") +run(WhileStmt) diff --git a/testsuite/c_test/driver_test/AST0017-InitListExpr-Struct/InitListExpr-Struct.c b/testsuite/c_test/driver_test/AST0017-InitListExpr-Struct/InitListExpr-Struct.c new file mode 100644 index 0000000000000000000000000000000000000000..4d536dada862a33e391a4ec96bd066016f631749 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0017-InitListExpr-Struct/InitListExpr-Struct.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +#include + +struct Str2 { + short c; + int e; +}; + +struct Str1 { + int a; + double b; + char ch[2]; + struct Str2 d; +}; + +int main() { + // printf("%c", myStr1.ch[0]) not support temporarily + struct Str1 myStr1 = {1, 1.5, {'a', 'b'}, {2, 3}}; + printf("%d:%f:%hd:%d\n", myStr1.a, myStr1.b, myStr1.d.c, myStr1.d.e); + + struct Str2 myStr2 = {4, 5}; + struct Str1 myStr3 = {1, 1.5, {'a', 'b'}, .d = myStr2}; + printf("%d:%f:%hd:%d\n", myStr3.a, myStr3.b, myStr3.d.c, myStr3.d.e); + + struct Str1 myStr4 = {1, 1.5, {'a', 'b'}, .d = myStr2, .d.c = 6, .d.e = 7}; + printf("%d:%f:%hd:%d\n", myStr4.a, myStr4.b, myStr4.d.c, myStr4.d.e); + + struct Str1 myStr5 = {1, 1.5, {'a', 'b'}, .d = myStr2, .d.c = 8}; + printf("%d:%f:%hd:%d\n", myStr5.a, myStr5.b, myStr5.d.c, myStr5.d.e); + + struct Str2 myStr6 = (struct Str2){9, 10}; + printf("%hd:%d\n", myStr6.c, myStr6.e); + + size_t lenA = offsetof(struct Str1, a); + printf("%ld\n", lenA); + + size_t lenB = offsetof(struct Str1, b); + printf("%ld\n", lenB); + + size_t lenCh = offsetof(struct Str1, ch); + printf("%ld\n", lenCh); + + size_t lenD = offsetof(struct Str1, d); + printf("%ld\n", lenD); + + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0017-InitListExpr-Struct/expected.txt b/testsuite/c_test/driver_test/AST0017-InitListExpr-Struct/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..04c3a5eda968d43d59f9f4cdbcc1d350af36b313 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0017-InitListExpr-Struct/expected.txt @@ -0,0 +1,9 @@ +1:1.500000:2:3 +1:1.500000:4:5 +1:1.500000:6:7 +1:1.500000:8:0 +9:10 +0 +8 +16 +20 diff --git a/testsuite/c_test/driver_test/AST0017-InitListExpr-Struct/test.cfg b/testsuite/c_test/driver_test/AST0017-InitListExpr-Struct/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..55d472802b066124f6c04454e80488ca7b0ab659 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0017-InitListExpr-Struct/test.cfg @@ -0,0 +1,2 @@ +compile(APP=InitListExpr-Struct.c,OPTION="--no-maple-phase -o InitListExpr-Struct") +run(InitListExpr-Struct) diff --git a/testsuite/c_test/driver_test/AST0018-ConstantExprInEnum/ConstantExprInEnum.c b/testsuite/c_test/driver_test/AST0018-ConstantExprInEnum/ConstantExprInEnum.c new file mode 100644 index 0000000000000000000000000000000000000000..44d53f872715d650314da7a95276f42c8c694bc7 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0018-ConstantExprInEnum/ConstantExprInEnum.c @@ -0,0 +1,31 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +enum G { + g0 = 1, + g1 = sizeof(int), + g2, +}; + +int main() { + enum L { + l0 = 2, + l1, + l2 = sizeof(float) + }; + + printf("g0 = %d, g1 = %d, g2 = %d\nl0 = %d, l1 = %d, l2 = %d\n", g0, g1, g2, l0, l1, l2); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0018-ConstantExprInEnum/expected.txt b/testsuite/c_test/driver_test/AST0018-ConstantExprInEnum/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..2890d91145f9376925dff2cea6e1bcf6e27a93e8 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0018-ConstantExprInEnum/expected.txt @@ -0,0 +1,2 @@ +g0 = 1, g1 = 4, g2 = 5 +l0 = 2, l1 = 3, l2 = 4 diff --git a/testsuite/c_test/driver_test/AST0018-ConstantExprInEnum/test.cfg b/testsuite/c_test/driver_test/AST0018-ConstantExprInEnum/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..48918b61d70022f680d74beb11c89458b42f2266 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0018-ConstantExprInEnum/test.cfg @@ -0,0 +1,2 @@ +compile(APP=ConstantExprInEnum.c,OPTION="--no-maple-phase -o ConstantExprInEnum") +run(ConstantExprInEnum) diff --git a/testsuite/c_test/driver_test/AST0020-CStyleCastExpr/CStyleCastExpr.c b/testsuite/c_test/driver_test/AST0020-CStyleCastExpr/CStyleCastExpr.c new file mode 100644 index 0000000000000000000000000000000000000000..6f3c74a632ad0bf23c831c2b47eabeeb83cdae73 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0020-CStyleCastExpr/CStyleCastExpr.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +struct book { + int a; + int b; +}; +int main() { + double a = 2.2; + int b = (int)a; + int c = 3; + double d = (double)c; + struct book m; + m.a = 1; + m.b = 2; + struct book n = (struct book)m; + void *vPtr = (void*)&b; + int *sPtr = (int*)vPtr; + int arr[2]; + arr[0] = 7; + arr[1] = 8; + int *pArr = (int*)arr; + printf("%d, %f, %d, %d, %d, %d\n", b, d, n.a, n.b, *sPtr, *pArr); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0020-CStyleCastExpr/expected.txt b/testsuite/c_test/driver_test/AST0020-CStyleCastExpr/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..cdac60069de455c628d801fd98a76d76c6176770 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0020-CStyleCastExpr/expected.txt @@ -0,0 +1 @@ +2, 3.000000, 1, 2, 2, 7 diff --git a/testsuite/c_test/driver_test/AST0020-CStyleCastExpr/test.cfg b/testsuite/c_test/driver_test/AST0020-CStyleCastExpr/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..4ed3c877cc1773c5e56cb6a2367c70777983d17f --- /dev/null +++ b/testsuite/c_test/driver_test/AST0020-CStyleCastExpr/test.cfg @@ -0,0 +1,2 @@ +compile(APP=CStyleCastExpr.c,OPTION="--no-maple-phase -o CStyleCastExpr") +run(CStyleCastExpr) diff --git a/testsuite/c_test/driver_test/AST0021-SwitchCaseDefault/SwitchCaseDefault.c b/testsuite/c_test/driver_test/AST0021-SwitchCaseDefault/SwitchCaseDefault.c new file mode 100644 index 0000000000000000000000000000000000000000..2046b8b799be90b4661df708fef8f8c5e0745e1f --- /dev/null +++ b/testsuite/c_test/driver_test/AST0021-SwitchCaseDefault/SwitchCaseDefault.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +int main() { + int a = 5; + switch (a) { + case 0:{ + a = 1; + break; + } + default: { + switch (a) { + case 2: + a = 3; + case 3: + a = 10; + case 5: + a = 20; + } + break; + } + } + printf("%d\n", a); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0021-SwitchCaseDefault/expected.txt b/testsuite/c_test/driver_test/AST0021-SwitchCaseDefault/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..209e3ef4b6247ce746048d5711befda46206d235 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0021-SwitchCaseDefault/expected.txt @@ -0,0 +1 @@ +20 diff --git a/testsuite/c_test/driver_test/AST0021-SwitchCaseDefault/test.cfg b/testsuite/c_test/driver_test/AST0021-SwitchCaseDefault/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..52976697fae14d43405dec737443f735ab6e0eeb --- /dev/null +++ b/testsuite/c_test/driver_test/AST0021-SwitchCaseDefault/test.cfg @@ -0,0 +1,2 @@ +compile(APP=SwitchCaseDefault.c,OPTION="--no-maple-phase -o SwitchCaseDefault") +run(SwitchCaseDefault) diff --git a/testsuite/c_test/driver_test/AST0022-StructDReadField/StructDReadField.c b/testsuite/c_test/driver_test/AST0022-StructDReadField/StructDReadField.c new file mode 100644 index 0000000000000000000000000000000000000000..82c0bebb10fe91d28d8668978657709f07817c6b --- /dev/null +++ b/testsuite/c_test/driver_test/AST0022-StructDReadField/StructDReadField.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +struct Person1 { + char name; + int age; +}; + +struct Person2 { + int age; + char name; +}; + +int main() { + struct Person1 p1; + struct Person2 p2; + p1.name = 'a'; + p1.age = 100; + p2.name = 'a'; + p2.age = 100; + printf("%d%d\n", p1.age, p1.name); + printf("%d%c\n", p1.age, p1.name); + printf("%d%d\n", p2.age, p2.name); + printf("%d%c\n", p2.age, p2.name); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0022-StructDReadField/expected.txt b/testsuite/c_test/driver_test/AST0022-StructDReadField/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..882b71ced20d92cf55b89b653c87ddbc0fbbfb56 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0022-StructDReadField/expected.txt @@ -0,0 +1,4 @@ +10097 +100a +10097 +100a diff --git a/testsuite/c_test/driver_test/AST0022-StructDReadField/test.cfg b/testsuite/c_test/driver_test/AST0022-StructDReadField/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..ac7084da9d580c90bafb6d36c3d3cd16bdb6d2a9 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0022-StructDReadField/test.cfg @@ -0,0 +1,2 @@ +compile(APP=StructDReadField.c,OPTION="--no-maple-phase -o StructDReadField") +run(StructDReadField) diff --git a/testsuite/c_test/driver_test/AST0023-StructIReadField/StructIReadField.c b/testsuite/c_test/driver_test/AST0023-StructIReadField/StructIReadField.c new file mode 100644 index 0000000000000000000000000000000000000000..716522bc6d57d44870a9631c5c9ad9681a765ff9 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0023-StructIReadField/StructIReadField.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +struct Person1 { + char name; + int age; +}; + +struct Person2 { + int age; + char name; +}; + +int main() { + struct Person1 p1; + struct Person2 p2; + p1.name = 'a'; + p1.age = 100; + p2.name = 'a'; + p2.age = 100; + struct Person1 *p1Ptr = &p1; + struct Person2 *p2Ptr = &p2; + printf("%d%d\n", p1Ptr->age, p1Ptr->name); + printf("%d%c\n", p1Ptr->age, p1Ptr->name); + printf("%d%d\n", p2Ptr->age, p2Ptr->name); + printf("%d%c\n", p2Ptr->age, p2Ptr->name); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0023-StructIReadField/expected.txt b/testsuite/c_test/driver_test/AST0023-StructIReadField/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..882b71ced20d92cf55b89b653c87ddbc0fbbfb56 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0023-StructIReadField/expected.txt @@ -0,0 +1,4 @@ +10097 +100a +10097 +100a diff --git a/testsuite/c_test/driver_test/AST0023-StructIReadField/test.cfg b/testsuite/c_test/driver_test/AST0023-StructIReadField/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..f5b7f2ba6a4c69e189d9eaa142866a9ab421fcc3 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0023-StructIReadField/test.cfg @@ -0,0 +1,2 @@ +compile(APP=StructIReadField.c,OPTION="--no-maple-phase -o StructIReadField") +run(StructIReadField) diff --git a/testsuite/c_test/driver_test/AST0024-CompoundAssignOperator/CompoundAssignOperator.c b/testsuite/c_test/driver_test/AST0024-CompoundAssignOperator/CompoundAssignOperator.c new file mode 100644 index 0000000000000000000000000000000000000000..15797023d35b3d4de2b37a42be53ee901e01cc9e --- /dev/null +++ b/testsuite/c_test/driver_test/AST0024-CompoundAssignOperator/CompoundAssignOperator.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +int g_a = 10; +int g_b = 20; + +int main() +{ + int a = 15; + int b = 35; + + b += a; // += + g_b += g_a; + a += g_a; + printf("%d%d%d\n", b, g_b, a); + b -= a; // -= + g_b -= g_a; + a -= g_a; + printf("%d%d%d\n", b, g_b, a); + b *= a; // *= + g_b *= g_a; + a *= g_a; + printf("%d%d%d\n", b, g_b, a); + b /= a; // /= + g_b /= g_a; + a /= g_a; + printf("%d%d%d\n", b, g_b, a); + b %= a; // %= + g_b %= g_a; + a %= g_a; + printf("%d%d%d\n", b, g_b, a); + + // TODO: need more nested example + b += g_a; + g_b %= a; + printf("%d%d\n", b, g_b); + + return 0; +} \ No newline at end of file diff --git a/testsuite/c_test/driver_test/AST0024-CompoundAssignOperator/expected.txt b/testsuite/c_test/driver_test/AST0024-CompoundAssignOperator/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..9f934385024e4540c5e11dbf90f224ae104eea72 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0024-CompoundAssignOperator/expected.txt @@ -0,0 +1,6 @@ +503025 +252015 +375200150 +22015 +205 +120 diff --git a/testsuite/c_test/driver_test/AST0024-CompoundAssignOperator/test.cfg b/testsuite/c_test/driver_test/AST0024-CompoundAssignOperator/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..64a2fef8b1f3ac3a9f0b9dcd816825e0fba95a2f --- /dev/null +++ b/testsuite/c_test/driver_test/AST0024-CompoundAssignOperator/test.cfg @@ -0,0 +1,2 @@ +compile(APP=CompoundAssignOperator.c,OPTION="--no-maple-phase -o CompoundAssignOperator") +run(CompoundAssignOperator) diff --git a/testsuite/c_test/driver_test/AST0024-ConstantExprInBitField/ConstantExprInBitField.c b/testsuite/c_test/driver_test/AST0024-ConstantExprInBitField/ConstantExprInBitField.c new file mode 100644 index 0000000000000000000000000000000000000000..41ebbdc093087e82933a2104540d25222a3e5da5 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0024-ConstantExprInBitField/ConstantExprInBitField.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +struct A { + int i:2; + unsigned int j:2; +}; + +int main() { + struct A a; + a.i = 0x1; + printf("%d\n", a.i); + + a.i = 0x2; + printf("%d\n", a.i); + + a.i = 0x3; + printf("%d\n", a.i); + + a.i = 0x5; + printf("%d\n", a.i); + + a.i = 0x7; + printf("%d\n", a.i); + + a.j = 0x1; + printf("%u\n", a.j); + + a.j = 0x2; + printf("%u\n", a.j); + + a.j = 0x3; + printf("%u\n", a.j); + + a.j = 0x5; + printf("%u\n", a.j); + + a.j = 0x7; + printf("%u\n", a.j); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0024-ConstantExprInBitField/expected.txt b/testsuite/c_test/driver_test/AST0024-ConstantExprInBitField/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..7e9528a92f7e6962acb2dc6a62f9fea88c9b8e9e --- /dev/null +++ b/testsuite/c_test/driver_test/AST0024-ConstantExprInBitField/expected.txt @@ -0,0 +1,10 @@ +1 +-2 +-1 +1 +-1 +1 +2 +3 +1 +3 diff --git a/testsuite/c_test/driver_test/AST0024-ConstantExprInBitField/test.cfg b/testsuite/c_test/driver_test/AST0024-ConstantExprInBitField/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..43b997f8bb3c21656e60e56655a720f44dd4baa4 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0024-ConstantExprInBitField/test.cfg @@ -0,0 +1,2 @@ +compile(APP=ConstantExprInBitField.c,OPTION="--no-maple-phase -o ConstantExprInBitField") +run(ConstantExprInBitField) diff --git a/testsuite/c_test/driver_test/AST0025-BinaryConditionalOperator/BinaryConditionalOperator.c b/testsuite/c_test/driver_test/AST0025-BinaryConditionalOperator/BinaryConditionalOperator.c new file mode 100644 index 0000000000000000000000000000000000000000..b45b53397f889e5e5af38fa77815162dc0f68fdb --- /dev/null +++ b/testsuite/c_test/driver_test/AST0025-BinaryConditionalOperator/BinaryConditionalOperator.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +int main() { + int a = 0; + // comparative conditioan: a < 10, get true val = (a < 10) = 1 + int b = (a < 10) ?: 1; + printf("%d %d\n", a, b); // 0 1 + // noncomparative condition: a = 0, get false val + b = a ?: 2; + printf("%d %d\n", a, b); // 0 2 + + b = a++ ?: 2; + printf("%d %d\n", a, b); // 1 2 + // noncomparative conditioan: a = 10, get true val = 10 + a = 10; + b = a++ ?: 2; + printf("%d %d\n", a, b); // 11 10 + // comparative conditioan: a < 9, get false val + b = (a < 9) ?: a++; + printf("%d %d\n", a, b); // 12 11 + // multilevel conditional expr + b = (a < 10) ?: (b < 9) ?: (a = 2, a++); + printf("%d %d\n", a, b); // 3 2 + + + // double type noncomparative condition, get false val + double c = 0.0; + double d = c++ ?: 2.0; + printf("%f %f\n", c, d); // 1.000000 2.000000 + // double type noncomparative condition, get true val + c = 5.0; + d = c ?: 2.0; + printf("%f %f\n", c, d); // 5.000000 5.000000 + // double type comparative condition, get true val + d = (c < 10.0) ?: 2.0; + printf("%f %f\n", c, d); // 5.000000 1.000000 + // double type comparative condition, get false val + d = (c < 1.0) ?: 2.0; + printf("%f %f\n", c, d); // 5.000000 2.000000 + return 0; +} + diff --git a/testsuite/c_test/driver_test/AST0025-BinaryConditionalOperator/expected.txt b/testsuite/c_test/driver_test/AST0025-BinaryConditionalOperator/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d24b8de30f60dee5b74a81e0fdd80bbb20a31bc5 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0025-BinaryConditionalOperator/expected.txt @@ -0,0 +1,10 @@ +0 1 +0 2 +1 2 +11 10 +12 11 +3 2 +1.000000 2.000000 +5.000000 5.000000 +5.000000 1.000000 +5.000000 2.000000 diff --git a/testsuite/c_test/driver_test/AST0025-BinaryConditionalOperator/test.cfg b/testsuite/c_test/driver_test/AST0025-BinaryConditionalOperator/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..7272d34d88cdbdadfcc373c79dee6ff979d0b263 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0025-BinaryConditionalOperator/test.cfg @@ -0,0 +1,2 @@ +compile(APP=BinaryConditionalOperator.c,OPTION="--no-maple-phase -o BinaryConditionalOperator") +run(BinaryConditionalOperator) diff --git a/testsuite/c_test/driver_test/AST0025-FloatingLiteral/FloatingLiteral.c b/testsuite/c_test/driver_test/AST0025-FloatingLiteral/FloatingLiteral.c new file mode 100644 index 0000000000000000000000000000000000000000..b5d3058b3f9fa72467a8922422936107d0853229 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0025-FloatingLiteral/FloatingLiteral.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +int main() { + + // floating literal + printf("%.1f\n", 12345.678901); + printf("%2.3f\n", 12345.678901); + printf("%6.7f\n", 12345.678901); + + printf("%.1f\n", 105.861233e2); + printf("%5.3f\n", 105.861233e2); + printf("%5.8f\n", 105.861233e2); + + return 0; +} + diff --git a/testsuite/c_test/driver_test/AST0025-FloatingLiteral/expected.txt b/testsuite/c_test/driver_test/AST0025-FloatingLiteral/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..9d22ef0591320bf1130ef0ae201a9ee38215dc9f --- /dev/null +++ b/testsuite/c_test/driver_test/AST0025-FloatingLiteral/expected.txt @@ -0,0 +1,6 @@ +12345.7 +12345.679 +12345.6789010 +10586.1 +10586.123 +10586.12330000 diff --git a/testsuite/c_test/driver_test/AST0025-FloatingLiteral/test.cfg b/testsuite/c_test/driver_test/AST0025-FloatingLiteral/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..3db67249c97c7dd02de084ae6809d5dcfed7bb12 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0025-FloatingLiteral/test.cfg @@ -0,0 +1,2 @@ +compile(APP=FloatingLiteral.c,OPTION="--no-maple-phase -o FloatingLiteral") +run(FloatingLiteral) diff --git a/testsuite/c_test/driver_test/AST0026-CharacterLiteral/CharacterLiteral.c b/testsuite/c_test/driver_test/AST0026-CharacterLiteral/CharacterLiteral.c new file mode 100644 index 0000000000000000000000000000000000000000..20337621044095a015905083add57ef43a0b3c0f --- /dev/null +++ b/testsuite/c_test/driver_test/AST0026-CharacterLiteral/CharacterLiteral.c @@ -0,0 +1,24 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +char g_a = 'a'; +int main() { + + for (int c = 33; c <127; c++){ // ASCII 33->"!",...126->"~" + printf("%c\n",c); + } + + return 0; +} \ No newline at end of file diff --git a/testsuite/c_test/driver_test/AST0026-CharacterLiteral/expected.txt b/testsuite/c_test/driver_test/AST0026-CharacterLiteral/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e17df2ad76a1679ec4c6473e27ac0ad07e65b8d3 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0026-CharacterLiteral/expected.txt @@ -0,0 +1,94 @@ +! +" +# +$ +% +& +' +( +) +* ++ +, +- +. +/ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +: +; +< += +> +? +@ +A +B +C +D +E +F +G +H +I +J +K +L +M +N +O +P +Q +R +S +T +U +V +W +X +Y +Z +[ +\ +] +^ +_ +` +a +b +c +d +e +f +g +h +i +j +k +l +m +n +o +p +q +r +s +t +u +v +w +x +y +z +{ +| +} +~ diff --git a/testsuite/c_test/driver_test/AST0026-CharacterLiteral/test.cfg b/testsuite/c_test/driver_test/AST0026-CharacterLiteral/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..dbdc06bafff933286c2c8c72e34b324c381d5d6a --- /dev/null +++ b/testsuite/c_test/driver_test/AST0026-CharacterLiteral/test.cfg @@ -0,0 +1,2 @@ +compile(APP=CharacterLiteral.c,OPTION="--no-maple-phase -o CharacterLiteral") +run(CharacterLiteral) diff --git a/testsuite/c_test/driver_test/AST0026-Sizeof/Sizeof.c b/testsuite/c_test/driver_test/AST0026-Sizeof/Sizeof.c new file mode 100644 index 0000000000000000000000000000000000000000..6b628a7984ce392f8690e3905835766c00dde9e5 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0026-Sizeof/Sizeof.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +int main() { + printf("%d,",sizeof(int)); + printf("%d,",sizeof(long)); + int a; + printf("%d,",sizeof(a)); + struct A { + int a; + double b; + }; + struct A aa; + printf("%d,",sizeof(struct A)); + printf("%d\n",sizeof(aa)); + + // complex cases + long int l_int = -2147483647; + char c = 'a'; + unsigned int u_int = 65535; + unsigned char u_char = 128; + float flt = 123.456789f; + double db = 1.23456789; + // long double ldb = 12.3456789123456; //@fail case + double ldb = 12.3456789123456; + short int s_int = 0xa5; + int res = c + a; + char *p; + printf("%lu%lu%lu%lu", sizeof(l_int), sizeof(c), sizeof(u_int), sizeof(u_char)); + printf("%lu%lu%lu%lu\n", sizeof(flt), sizeof(db), sizeof(s_int), sizeof(res)); + struct B { + struct A a; + } B; + union u{ + char c; + double d; + } u; + int arr[5]; + double arr2[10]; + printf("%lu%lu%lu%lu", sizeof(struct B), sizeof(p), sizeof(arr), sizeof(arr2)); + printf("%lu%lu%lu%lu%lu%lu", sizeof(8), sizeof(8.8), sizeof("arr"), sizeof(u), sizeof(u.c), sizeof(u.d)); + printf("\n%lu%lu%lu", sizeof(aa), sizeof(aa.a), sizeof(aa.b)); + return 0; +} + diff --git a/testsuite/c_test/driver_test/AST0026-Sizeof/expected.txt b/testsuite/c_test/driver_test/AST0026-Sizeof/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..8109eefd46894b7c2084cd28bec2bd723c9c0c15 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0026-Sizeof/expected.txt @@ -0,0 +1,4 @@ +4,8,4,16,16 +81414824 +1682080484818 +1648 \ No newline at end of file diff --git a/testsuite/c_test/driver_test/AST0026-Sizeof/test.cfg b/testsuite/c_test/driver_test/AST0026-Sizeof/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..78590d3cd247a649f1fe663172ce5b5d5216fb0b --- /dev/null +++ b/testsuite/c_test/driver_test/AST0026-Sizeof/test.cfg @@ -0,0 +1,2 @@ +compile(APP=Sizeof.c,OPTION="--no-maple-phase -o Sizeof") +run(Sizeof) diff --git a/testsuite/c_test/driver_test/AST0027-GotoLabel/GotoLabel.c b/testsuite/c_test/driver_test/AST0027-GotoLabel/GotoLabel.c new file mode 100644 index 0000000000000000000000000000000000000000..c9d74be0acee88da68c77cb45626a94adf5c3fca --- /dev/null +++ b/testsuite/c_test/driver_test/AST0027-GotoLabel/GotoLabel.c @@ -0,0 +1,29 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +int main() { + printf("1"); + goto i_am_here_1; + printf("failed;"); + i_am_here_1: + printf("1"); + goto i_am_here_2; + printf("failed;"); + i_am_here_2: + printf("1"); + return 0; +} + diff --git a/testsuite/c_test/driver_test/AST0027-GotoLabel/expected.txt b/testsuite/c_test/driver_test/AST0027-GotoLabel/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..9d07aa0df55c353e18eea6f1b401946b5dad7bce --- /dev/null +++ b/testsuite/c_test/driver_test/AST0027-GotoLabel/expected.txt @@ -0,0 +1 @@ +111 \ No newline at end of file diff --git a/testsuite/c_test/driver_test/AST0027-GotoLabel/test.cfg b/testsuite/c_test/driver_test/AST0027-GotoLabel/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..b84b789a276ad447c69a273194fbebc7b4af4240 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0027-GotoLabel/test.cfg @@ -0,0 +1,2 @@ +compile(APP=GotoLabel.c,OPTION="--no-maple-phase -o GotoLabel") +run(GotoLabel) diff --git a/testsuite/c_test/driver_test/AST0027-ICallassigned/ICallassigned.c b/testsuite/c_test/driver_test/AST0027-ICallassigned/ICallassigned.c new file mode 100644 index 0000000000000000000000000000000000000000..31650e1f81cbcac1d710f6252bda48ac8bd83842 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0027-ICallassigned/ICallassigned.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +char *fpchar(void) { + return "yes_its_possible1"; +} + +char *(*fpfpchar(void))(void) { + return (fpchar); +} + +char *(*(*fpfpfpchar(void))(void))(void) { + return (fpfpchar); +} + +void fpvoid(void) { + printf("yes_its_possible2"); +} + +void (*fpfpvoid(void))(void) { + return (fpvoid); +} + +void (*(*fpfpfpvoid(void))(void))(void) { + return (fpfpvoid); +} + +void testv() { + printf("yes_its_possible3"); +} + +int testi() { + return 4; +} + +int main() { + char *tmp = (((fpfpfpchar())())()); + printf("%s", tmp); + (((fpfpfpvoid())())()); + testv(); + int a = testi(); + printf("yes_its_possible%d", a); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0027-ICallassigned/expected.txt b/testsuite/c_test/driver_test/AST0027-ICallassigned/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..84fc5513754671a674c743a9d8099737af8f42fa --- /dev/null +++ b/testsuite/c_test/driver_test/AST0027-ICallassigned/expected.txt @@ -0,0 +1 @@ +yes_its_possible1yes_its_possible2yes_its_possible3yes_its_possible4 \ No newline at end of file diff --git a/testsuite/c_test/driver_test/AST0027-ICallassigned/test.cfg b/testsuite/c_test/driver_test/AST0027-ICallassigned/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..5e66b6348791d48a01b14f7bca80ac174189e6d2 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0027-ICallassigned/test.cfg @@ -0,0 +1,2 @@ +compile(APP=ICallassigned.c,OPTION="--no-maple-phase -o ICallassigned") +run(ICallassigned) diff --git a/testsuite/c_test/driver_test/AST0028-ImplicitCvt/ImplicitCvt.c b/testsuite/c_test/driver_test/AST0028-ImplicitCvt/ImplicitCvt.c new file mode 100644 index 0000000000000000000000000000000000000000..bbe91ca14ee4f1e67c69330b38f622d29f1b2846 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0028-ImplicitCvt/ImplicitCvt.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +#include + +long a = 65538; +int b = 23; + +int main() { + if (ULONG_MAX >= 2147483647) { + printf("true"); + } + long c = 655351111; + int d = 23; + if (c > d) { + printf("true"); + } + if (a > b) { + printf("true"); + } + float e = 2.2f; + double f = 2.3; + if (f > e) { + printf("true"); + } + int i = e; + int j = f; + int h = 0; + h = e; + printf("%f", e); + printf("%f", f); + printf("%ld", a); + printf("%d", i); + printf("%d", j); + printf("%d", h); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0028-ImplicitCvt/expected.txt b/testsuite/c_test/driver_test/AST0028-ImplicitCvt/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..1f8f545a7d678531fa51e3f658a827bb264594ea --- /dev/null +++ b/testsuite/c_test/driver_test/AST0028-ImplicitCvt/expected.txt @@ -0,0 +1 @@ +truetruetruetrue2.2000002.30000065538222 \ No newline at end of file diff --git a/testsuite/c_test/driver_test/AST0028-ImplicitCvt/test.cfg b/testsuite/c_test/driver_test/AST0028-ImplicitCvt/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..3ec8c8a8dadd1d2b32fe806c524cd65da323c674 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0028-ImplicitCvt/test.cfg @@ -0,0 +1,2 @@ +compile(APP=ImplicitCvt.c,OPTION="--no-maple-phase -o ImplicitCvt") +run(ImplicitCvt) diff --git a/testsuite/c_test/driver_test/AST0028-PtrBinary/PtrBinary.c b/testsuite/c_test/driver_test/AST0028-PtrBinary/PtrBinary.c new file mode 100644 index 0000000000000000000000000000000000000000..9c315d2c4130f67343b962253115e37f88132d8f --- /dev/null +++ b/testsuite/c_test/driver_test/AST0028-PtrBinary/PtrBinary.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +int main() { + int a = 1; + int b = 2; + int c = 3; + int *pa = &a; + int *pb = &b; + int *pc = &c; + printf("%d,", *pa); + printf("%d,", *(pa+1)); + printf("%d,", *(pa+2)); + printf("%ld\n", (pc - pa)); + return 0; +} + diff --git a/testsuite/c_test/driver_test/AST0028-PtrBinary/expected.txt b/testsuite/c_test/driver_test/AST0028-PtrBinary/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..65f986cd2192bb117a24cbb74707db042918fdd3 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0028-PtrBinary/expected.txt @@ -0,0 +1 @@ +1,2,3,2 diff --git a/testsuite/c_test/driver_test/AST0028-PtrBinary/test.cfg b/testsuite/c_test/driver_test/AST0028-PtrBinary/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..c6f4f7724b0364c48d958368ffa3c4e5ec5aae18 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0028-PtrBinary/test.cfg @@ -0,0 +1,2 @@ +compile(APP=PtrBinary.c,OPTION="--no-maple-phase -o PtrBinary") +run(PtrBinary) diff --git a/testsuite/c_test/driver_test/AST0031-SameNameTypeDeclInDifferentScope/SameNameTypeDeclInDifferentScope.c b/testsuite/c_test/driver_test/AST0031-SameNameTypeDeclInDifferentScope/SameNameTypeDeclInDifferentScope.c new file mode 100644 index 0000000000000000000000000000000000000000..cdd0ae332fb17d274c1af5e37659a2747a456a9e --- /dev/null +++ b/testsuite/c_test/driver_test/AST0031-SameNameTypeDeclInDifferentScope/SameNameTypeDeclInDifferentScope.c @@ -0,0 +1,33 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +int main() { + struct A { int a; } aa; + aa.a = 111; + { + struct A { double d; } dd; + dd.d = 3.14; + printf("dd.d = %f\n", dd.d); + { + struct A { char c; } cc; + cc.c = 'a'; + printf("cc.c = %c\n", cc.c); + } + } + + printf("aa.a = %d\n", aa.a); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0031-SameNameTypeDeclInDifferentScope/expected.txt b/testsuite/c_test/driver_test/AST0031-SameNameTypeDeclInDifferentScope/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..7a47b67b07539bd882cb98f38a5c8973e7fa2dbb --- /dev/null +++ b/testsuite/c_test/driver_test/AST0031-SameNameTypeDeclInDifferentScope/expected.txt @@ -0,0 +1,3 @@ +dd.d = 3.140000 +cc.c = a +aa.a = 111 diff --git a/testsuite/c_test/driver_test/AST0031-SameNameTypeDeclInDifferentScope/test.cfg b/testsuite/c_test/driver_test/AST0031-SameNameTypeDeclInDifferentScope/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..2edc687a183567d624fa3393e7135d5baaa35814 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0031-SameNameTypeDeclInDifferentScope/test.cfg @@ -0,0 +1,2 @@ +compile(APP=SameNameTypeDeclInDifferentScope.c,OPTION="--no-maple-phase -o SameNameTypeDeclInDifferentScope") +run(SameNameTypeDeclInDifferentScope) diff --git a/testsuite/c_test/driver_test/AST0032-SameNameVarIndifferentScope/SameNameVarIndifferentScope.c b/testsuite/c_test/driver_test/AST0032-SameNameVarIndifferentScope/SameNameVarIndifferentScope.c new file mode 100644 index 0000000000000000000000000000000000000000..c82534f588dada181195142f7c7a019ebabd5372 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0032-SameNameVarIndifferentScope/SameNameVarIndifferentScope.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +enum { + e = 0 +}; +extern int aa; +int aa; +int main() { + aa = 123; + int x = 1; + printf("e = %d\n", e); + enum E { + e = 11 + }; + { + printf("e = %d\n", e); + enum EE { + e = 22 + }; + printf("x = %d\n", x); + int x = 2; + { + printf("e = %d\n", e); + printf("x = %d\n", x); + int x = 3; + enum EEE { + e = 33 + }; + printf("e = %d\n", e); + printf("x = %d\n", x); + } + printf("x = %d\n", x); + } + printf("e = %d\n", e); + printf("x = %d\n", x); + printf("aa = %d\n", aa); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0032-SameNameVarIndifferentScope/expected.txt b/testsuite/c_test/driver_test/AST0032-SameNameVarIndifferentScope/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..f18d783234d67f3924c17095a4b466bc68ed8139 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0032-SameNameVarIndifferentScope/expected.txt @@ -0,0 +1,11 @@ +e = 0 +e = 11 +x = 1 +e = 22 +x = 2 +e = 33 +x = 3 +x = 2 +e = 11 +x = 1 +aa = 123 diff --git a/testsuite/c_test/driver_test/AST0032-SameNameVarIndifferentScope/test.cfg b/testsuite/c_test/driver_test/AST0032-SameNameVarIndifferentScope/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..a6b8920b1fc2de66ea3a75ac3054fba916bff216 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0032-SameNameVarIndifferentScope/test.cfg @@ -0,0 +1,2 @@ +compile(APP=SameNameVarIndifferentScope.c,OPTION="--no-maple-phase -o SameNameVarIndifferentScope") +run(SameNameVarIndifferentScope) diff --git a/testsuite/c_test/driver_test/AST0033-StmtExpr/StmtExpr.c b/testsuite/c_test/driver_test/AST0033-StmtExpr/StmtExpr.c new file mode 100644 index 0000000000000000000000000000000000000000..56a804ceea9abfecc07a25a00a3608df0ee8ab2e --- /dev/null +++ b/testsuite/c_test/driver_test/AST0033-StmtExpr/StmtExpr.c @@ -0,0 +1,22 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +int main() { + ({int a = 1; a = 2; a;}); + int x = ({int a = 11; a = 22; a;}); + printf("x = %d\n", x); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0033-StmtExpr/expected.txt b/testsuite/c_test/driver_test/AST0033-StmtExpr/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..bb516a779476dca94bf71f7b25366412e16e5e76 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0033-StmtExpr/expected.txt @@ -0,0 +1 @@ +x = 22 diff --git a/testsuite/c_test/driver_test/AST0033-StmtExpr/test.cfg b/testsuite/c_test/driver_test/AST0033-StmtExpr/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..5b0c3defaca209d49260aca765fcea623a78ec9a --- /dev/null +++ b/testsuite/c_test/driver_test/AST0033-StmtExpr/test.cfg @@ -0,0 +1,2 @@ +compile(APP=StmtExpr.c,OPTION="--no-maple-phase -o StmtExpr") +run(StmtExpr) diff --git a/testsuite/c_test/driver_test/AST0034-ArrayInStruct/ArrayInStruct.c b/testsuite/c_test/driver_test/AST0034-ArrayInStruct/ArrayInStruct.c new file mode 100644 index 0000000000000000000000000000000000000000..60952333c358c367641fd3252cd4c7b6fe4a4faa --- /dev/null +++ b/testsuite/c_test/driver_test/AST0034-ArrayInStruct/ArrayInStruct.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +struct C { + char f; +}; +struct B { + char c; + char d; + struct C inc; +}; +struct A { + int a; + int b; + char inArr[2][2]; + double inArr1[2][2]; + struct B inb; +}; + +int main() { + struct A sa = {1, 2, {'a', 'b','c'},{2.5, 6.8,8.5,45.2},{'d','f',{'g'}}}; + char c1 = sa.inArr[0][1]; + char c2 = sa.inArr[1][0]; + double c11 = sa.inArr1[0][1]; + double c21 = sa.inArr1[1][0]; + double c22 = sa.inArr1[1][1]; + sa.inArr1[1][1] = 22.2; + double c23 = sa.inArr1[1][1]; + printf("%c\n",c1); + printf("%c\n",c2); + printf("%f\n",c11); + printf("%f\n",c21); + printf("%f\n",c22); + printf("%f\n",sa.inArr1[1][1]); + printf("%f\n",c23); + printf("%c\n",sa.inb.inc.f); + return 0; +} + diff --git a/testsuite/c_test/driver_test/AST0034-ArrayInStruct/expected.txt b/testsuite/c_test/driver_test/AST0034-ArrayInStruct/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d36a6db149a01e2ba5d259499f721216f8b11f53 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0034-ArrayInStruct/expected.txt @@ -0,0 +1,8 @@ +b +c +6.800000 +8.500000 +45.200000 +22.200000 +22.200000 +g diff --git a/testsuite/c_test/driver_test/AST0034-ArrayInStruct/test.cfg b/testsuite/c_test/driver_test/AST0034-ArrayInStruct/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..df165fdd4844ca7eda9f39a95f0441df3f1649aa --- /dev/null +++ b/testsuite/c_test/driver_test/AST0034-ArrayInStruct/test.cfg @@ -0,0 +1,2 @@ +compile(APP=ArrayInStruct.c,OPTION="--no-maple-phase -o ArrayInStruct") +run(ArrayInStruct) diff --git a/testsuite/c_test/driver_test/AST0035-ImplicitValueInitExpr/ImplicitValueInitExpr.c b/testsuite/c_test/driver_test/AST0035-ImplicitValueInitExpr/ImplicitValueInitExpr.c new file mode 100644 index 0000000000000000000000000000000000000000..e801e1b7eafbff51df4ca6d398463e3d0ac7e75c --- /dev/null +++ b/testsuite/c_test/driver_test/AST0035-ImplicitValueInitExpr/ImplicitValueInitExpr.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +#include + +struct Str2 { + short c; + int e; +}; + +struct Str1 { + int a; + double b; + int arr[2]; + struct Str2 d; +}; + +int main() { + struct Str1 myStr1 = {1}; + printf("%d:%f:%d:%d:%hd:%d\n", myStr1.a, myStr1.b, myStr1.arr[0], myStr1.arr[1], myStr1.d.c, myStr1.d.e); + + struct Str2 myStr2 = {4}; + struct Str1 myStr3 = {1, .d = myStr2}; + printf("%d:%f:%d:%d:%hd:%d\n", myStr3.a, myStr3.b, myStr3.arr[0], myStr3.arr[1], myStr3.d.c, myStr3.d.e); + + myStr2.e = 3; + struct Str1 myStr4 = {1, 1.5, .d = myStr2, .d.c = 5 }; + printf("%d:%f:%d:%d:%hd:%d\n", myStr4.a, myStr4.b, myStr4.arr[0], myStr4.arr[1], myStr4.d.c, myStr4.d.e); + + struct Str1 myStr5 = {1, .arr = {6, 7}, .d.c = 8}; + printf("%d:%f:%d:%d:%hd:%d\n", myStr5.a, myStr5.b, myStr5.arr[0], myStr5.arr[1], myStr5.d.c, myStr5.d.e); + + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0035-ImplicitValueInitExpr/expected.txt b/testsuite/c_test/driver_test/AST0035-ImplicitValueInitExpr/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..fbc6574557acacf90b02f11ec3928699539cbeb9 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0035-ImplicitValueInitExpr/expected.txt @@ -0,0 +1,4 @@ +1:0.000000:0:0:0:0 +1:0.000000:0:0:4:0 +1:1.500000:0:0:5:0 +1:0.000000:6:7:8:0 diff --git a/testsuite/c_test/driver_test/AST0035-ImplicitValueInitExpr/test.cfg b/testsuite/c_test/driver_test/AST0035-ImplicitValueInitExpr/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..8b79c0f7a6a8e67412133e1d00175610f8ff257f --- /dev/null +++ b/testsuite/c_test/driver_test/AST0035-ImplicitValueInitExpr/test.cfg @@ -0,0 +1,2 @@ +compile(APP=ImplicitValueInitExpr.c,OPTION="--no-maple-phase -o ImplicitValueInitExpr") +run(ImplicitValueInitExpr) diff --git a/testsuite/c_test/driver_test/AST0036-Complex/Complex.c b/testsuite/c_test/driver_test/AST0036-Complex/Complex.c new file mode 100644 index 0000000000000000000000000000000000000000..23635b7ec4446d3b22b2010d9c68bf5beb954fa6 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0036-Complex/Complex.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +#include + +int main() { + float complex a = 1 + I; + printf("%f + i%f\n", __real a , __imag a); + float complex b = 1 + I; + printf("%f + i%f\n", __real b , __imag b); + float complex c = a + b; + printf("%f + i%f\n", __real c , __imag c); + complex double d = a - b; + printf("%f + i%f\n", __real d , __imag d); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0036-Complex/expected.txt b/testsuite/c_test/driver_test/AST0036-Complex/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0244aca82c5cdddcfa2e097b3da467b8b074a0e7 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0036-Complex/expected.txt @@ -0,0 +1,4 @@ +1.000000 + i1.000000 +1.000000 + i1.000000 +2.000000 + i2.000000 +0.000000 + i0.000000 diff --git a/testsuite/c_test/driver_test/AST0036-Complex/test.cfg b/testsuite/c_test/driver_test/AST0036-Complex/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..bf01960a575b253739c0ca619d678e9eb3c819b9 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0036-Complex/test.cfg @@ -0,0 +1,2 @@ +compile(APP=Complex.c,OPTION="--no-maple-phase -o Complex") +run(Complex) diff --git a/testsuite/c_test/driver_test/AST0036-TypeDef/TypeDef.c b/testsuite/c_test/driver_test/AST0036-TypeDef/TypeDef.c new file mode 100644 index 0000000000000000000000000000000000000000..48455e62d803caf93b83e56deefb8a96eb224c28 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0036-TypeDef/TypeDef.c @@ -0,0 +1,33 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +typedef int MyInt; +typedef struct A { int i; } StructA; +int main() { + typedef float MyFloat; + StructA a; + a.i = 22; + typedef struct A { double d; } StructA; + StructA a0; + a0.d = 1.414; + MyInt i = 11; + MyFloat f = 3.14; + printf("i = %d\n", i); + printf("f = %f\n", f); + printf("a.i = %d\n", a.i); + printf("a0.d = %f\n", a0.d); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0036-TypeDef/expected.txt b/testsuite/c_test/driver_test/AST0036-TypeDef/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..43a1c844d5a42e5576f71b1cb2f2560499d4b717 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0036-TypeDef/expected.txt @@ -0,0 +1,4 @@ +i = 11 +f = 3.140000 +a.i = 22 +a0.d = 1.414000 diff --git a/testsuite/c_test/driver_test/AST0036-TypeDef/test.cfg b/testsuite/c_test/driver_test/AST0036-TypeDef/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..4d7c121a037fb6254e4f34a563f53b18e23259ab --- /dev/null +++ b/testsuite/c_test/driver_test/AST0036-TypeDef/test.cfg @@ -0,0 +1,2 @@ +compile(APP=TypeDef.c,OPTION="--no-maple-phase -o TypeDef") +run(TypeDef) diff --git a/testsuite/c_test/driver_test/AST0037-VAArgExpr/VAArgExpr.c b/testsuite/c_test/driver_test/AST0037-VAArgExpr/VAArgExpr.c new file mode 100644 index 0000000000000000000000000000000000000000..233e51797d6eca0bf020ab32d78e23c692dbf78e --- /dev/null +++ b/testsuite/c_test/driver_test/AST0037-VAArgExpr/VAArgExpr.c @@ -0,0 +1,126 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +typedef struct demo1 { + int a; + short b; +} demo1; + +typedef struct demo2 { + float a; + float b; + float c; +} demo2; // HFA + +typedef struct demo3 { + double a; + double b; + double c; +} demo3; // copyed mem + +typedef struct demo4 { + float a; + float arr[3]; +} demo4; // HFA nested array + +void func(int a, ...) { // reg + va_list vl; + printf("a: %d\n",a); + va_start(vl, a); + double b = va_arg(vl, double); + printf("b: %lf\n", b); + long c = va_arg(vl, long); + printf("c: %ld\n", c); + char *d = va_arg(vl, char *); + printf("d: %s\n", d); + demo1 e = va_arg(vl, demo1); + printf("e.a: %d\n", e.a); + printf("e.b: %d\n", e.b); + demo2 f = va_arg(vl, demo2); + printf("f.a: %lf\n", f.a); + printf("f.b: %lf\n", f.b); + printf("f.c: %lf\n", f.c); + demo3 g = va_arg(vl, demo3); + printf("g.a: %lf\n", g.a); + printf("g.b: %lf\n", g.b); + printf("g.c: %lf\n", g.c); + demo4 h = va_arg(vl, demo4); + printf("g.a: %lf\n", h.a); + printf("g.a: %lf\n", h.arr[2]); + va_end(vl); +} + +void func1(int a, ...) { // stack + va_list vl1; + printf("a: %d\n",a); + va_start(vl1, a); + + for (int i = 1; i <= 8; i++) { + int ii = va_arg(vl1, int); + printf("ii%d: %d\n", i, ii); + } + + for (int i = 1; i <= 8; i++) { + double dd = va_arg(vl1, double); + printf("dd%d: %lf\n", i, dd); + } + + double b = va_arg(vl1, double); + printf("b: %lf\n", b); + long c = va_arg(vl1, long); + printf("c: %ld\n", c); + char *d = va_arg(vl1, char *); + printf("d: %s\n", d); + demo1 e = va_arg(vl1, demo1); + printf("e.a: %d\n", e.a); + printf("e.b: %d\n", e.b); + demo2 f = va_arg(vl1, demo2); + printf("f.a: %lf\n", f.a); + printf("f.b: %lf\n", f.b); + printf("f.c: %lf\n", f.c); + demo3 g = va_arg(vl1, demo3); + printf("g.a: %lf\n", g.a); + printf("g.b: %lf\n", g.b); + printf("g.c: %lf\n", g.c); + demo4 h = va_arg(vl1, demo4); + printf("g.a: %lf\n", h.a); + printf("g.a: %lf\n", h.arr[2]); + va_end(vl1); +} + +int main() { + int a = 20; // int + double b = 30.0; // double + long c = 123L; + char *d = "abc"; // ptr + demo1 e; // struct + e.a = 100; + e.b = 101; + demo2 f; + f.a = 1.1f; + f.b = 1.2f; + f.c = 1.3f; + demo3 g; + g.a = 3.14; + g.b = 1.234; + g.c = 1.0; + demo4 h; + h.a = 2.22; + h.arr[2] = 3.33; + func(a, b, c, d, e, f, g, h); + func1(a, 1, 2, 3, 4, 5, 6, 7 ,8, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6 ,7.7, 8.8, b, c, d, e, f, g, h); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0037-VAArgExpr/expected.txt b/testsuite/c_test/driver_test/AST0037-VAArgExpr/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..41bf5fe6b913c266871d6f9b376ff23fa60337e1 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0037-VAArgExpr/expected.txt @@ -0,0 +1,44 @@ +a: 20 +b: 30.000000 +c: 123 +d: abc +e.a: 100 +e.b: 101 +f.a: 1.100000 +f.b: 1.200000 +f.c: 1.300000 +g.a: 3.140000 +g.b: 1.234000 +g.c: 1.000000 +g.a: 2.220000 +g.a: 3.330000 +a: 20 +ii1: 1 +ii2: 2 +ii3: 3 +ii4: 4 +ii5: 5 +ii6: 6 +ii7: 7 +ii8: 8 +dd1: 1.100000 +dd2: 2.200000 +dd3: 3.300000 +dd4: 4.400000 +dd5: 5.500000 +dd6: 6.600000 +dd7: 7.700000 +dd8: 8.800000 +b: 30.000000 +c: 123 +d: abc +e.a: 100 +e.b: 101 +f.a: 1.100000 +f.b: 1.200000 +f.c: 1.300000 +g.a: 3.140000 +g.b: 1.234000 +g.c: 1.000000 +g.a: 2.220000 +g.a: 3.330000 diff --git a/testsuite/c_test/driver_test/AST0037-VAArgExpr/test.cfg b/testsuite/c_test/driver_test/AST0037-VAArgExpr/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..04a99802128e3b99880ee79082f8713efe3b052c --- /dev/null +++ b/testsuite/c_test/driver_test/AST0037-VAArgExpr/test.cfg @@ -0,0 +1,2 @@ +compile(APP=VAArgExpr.c,OPTION="--no-maple-phase -o VAArgExpr") +run(VAArgExpr) diff --git a/testsuite/c_test/driver_test/AST0038-GlobalAggInit/GlobalAggInit.c b/testsuite/c_test/driver_test/AST0038-GlobalAggInit/GlobalAggInit.c new file mode 100644 index 0000000000000000000000000000000000000000..c5100c57abb876d228b6989bc8a7198bce0abe19 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0038-GlobalAggInit/GlobalAggInit.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +struct A { + int i[2]; + float f; +}; +const int cInt = 111; +enum { + e0, + e1 +}; +union U { + char c; + int i; + short s; +}; + +union U u = { 10 }; + +struct A Aarray[2] = { { { e0, e1 }, 11.1f }, + { { sizeof(int), 4 }, 22.2f } + }; +struct A a = { { 5, e1 }, 33.3f }; +int i[3] = { 3 + 1, 2, 1}; + +// +struct D { + int y; + double z; + int i; + int j; + struct E { + int i; + int j; + struct F { + int y; + } f; + } e; +} d; +struct F *pf = &d.e.f; + +int main() { + printf("a.i[0] = %d\na.i[1] = %d\n", a.i[0], a.i[1]); + printf("i[0] = %d\ni[1] = %d\ni[2] = %d\n", i[0], i[1], i[2]); + printf("u.i = %d\n", u.i); + pf->y = 2; + printf("d.e.f.y=%d, pf=%d\n", d.e.f.y, pf->y); + + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0038-GlobalAggInit/expected.txt b/testsuite/c_test/driver_test/AST0038-GlobalAggInit/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..4aed69f12dfbae36e8e389a08630d94526a5a488 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0038-GlobalAggInit/expected.txt @@ -0,0 +1,7 @@ +a.i[0] = 5 +a.i[1] = 1 +i[0] = 4 +i[1] = 2 +i[2] = 1 +u.i = 10 +d.e.f.y=2, pf=2 diff --git a/testsuite/c_test/driver_test/AST0038-GlobalAggInit/test.cfg b/testsuite/c_test/driver_test/AST0038-GlobalAggInit/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..eb74625265a2e09c85b81fbde2ee37243ba86dee --- /dev/null +++ b/testsuite/c_test/driver_test/AST0038-GlobalAggInit/test.cfg @@ -0,0 +1,2 @@ +compile(APP=GlobalAggInit.c,OPTION="--no-maple-phase -o GlobalAggInit") +run(GlobalAggInit) diff --git a/testsuite/c_test/driver_test/AST0038-GlobalVar/GlobalVar.c b/testsuite/c_test/driver_test/AST0038-GlobalVar/GlobalVar.c new file mode 100644 index 0000000000000000000000000000000000000000..a80d98cce0beb375f5400ff4f35e095b4994681f --- /dev/null +++ b/testsuite/c_test/driver_test/AST0038-GlobalVar/GlobalVar.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +// double c = 3.14159; // fail case +// long double d = 1.11111; // fail case +// float arr3[] = {1.0, -1.0, 0 , 0}; // fail case +// float arr4[] = {1.0f, -1.0, 0 , 0}; // fail case +// float arr4[] = {1.0f, -1.0f}; // fail case, wrong value +// struct A A = {10, 10.1, 10.2, 'a'}; // fail case +int a = 1; +float b = 1.1; +struct A { + int Aa; + float Ab; + double Ac; + char Ad; +} A; // A = {10, 10.1, 10.2, 'a'} fail + +struct A *pA = &A; +int arr[] = {1, 2, 3}; +float arr2[3] = {0.0}; +float arr3[] = {1.0, -1.0}; +char arr4[] = {'a','c'}; +float f = (1.17549435e-38f <= 1.1) ? 1.1 : 9.9; +struct B{ + int Barr[2]; + float Barr2[2]; + double Barr3[2]; + char Barr4[2]; +} B; +struct B *pB = &B; +int lenA = sizeof(A) + 1; +enum DAY{ + MON=1, TUE, WED, THU, FRI, SAT, SUN +} day = WED; +union data{ + int n; + char ch; + double f; +} data; +// const struct C { // fail case +// int a; +// char c; +// double d; +// } C = {1, 'a', 2.222}; +int main() { + A.Aa = 10; + A.Ab = 10.1; + A.Ac = 10.2; + A.Ad = 'a'; + B.Barr[0] = 20; + B.Barr[1] = 22; + B.Barr2[0] = 20.1; + B.Barr2[1] = 22.1; + B.Barr3[0] = 20.131; + B.Barr3[1] = 22.131; + B.Barr4[0] = 'b'; + B.Barr4[1] = 'c'; + data.n = 4; + data.ch ='s'; + data.f = 1.234; + printf("%d\n", a); + printf("%f\n", b); + printf("%f\n", A.Ac); + printf("%d%d%d\n", arr[0], arr[1], arr[2]); + printf("%f%f%f\n", arr2[0], arr2[1], arr2[2]); + printf("%f%f\n", arr3[0], arr3[1]); + printf("%c%c\n", arr4[0], arr4[1]); + printf("%f\n", f); + printf("%d%d%d\n", *arr, *(arr + 1), *(arr + 2)); + printf("%f%f%f\n", *arr2, *(arr2 + 1), *(arr2 + 2)); + printf("%f%f\n", *arr3, *(arr2 + 1)); + printf("%c%c\n", *arr4, *(arr4 + 1)); + printf("%d%d%d", lenA, sizeof(pA), sizeof(pB)); + printf("%d%d\n", day, sizeof(day)); + printf("%d%c%f\n",data.n, data.ch, data.f); + // printf("%c%c%c", A.Ad, B.Barr4[0], B.Barr4[1]); // fail case + // printf("%d\n", A.Aa); // fail case, wrong value + // printf("%f\n", A.Ab); // fail case, wrong value + // printf("%d%f%f\n", pA->Aa, pA->Ab, pA->Ac); // fail case + // printf("%d%d\n", pB->Barr[0], pB->Barr[1]); // fail case + // printf("%f%f%f%f\n", pB->Barr2[0], pB->Barr2[1], pB->Barr3[0], pB->Barr3[1]); // fail case + // printf("%f%f\n", arr4[0], arr4[1]); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0038-GlobalVar/expected.txt b/testsuite/c_test/driver_test/AST0038-GlobalVar/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..9113a848ff89212bfeed36c14a3f21b064a27aaf --- /dev/null +++ b/testsuite/c_test/driver_test/AST0038-GlobalVar/expected.txt @@ -0,0 +1,14 @@ +1 +1.100000 +10.200000 +123 +0.0000000.0000000.000000 +1.000000-1.000000 +ac +1.100000 +123 +0.0000000.0000000.000000 +1.0000000.000000 +ac +258834 +-927712936X1.234000 diff --git a/testsuite/c_test/driver_test/AST0038-GlobalVar/test.cfg b/testsuite/c_test/driver_test/AST0038-GlobalVar/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..aff0250733659d7a9649b92abf26e141ea4e24d4 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0038-GlobalVar/test.cfg @@ -0,0 +1,2 @@ +compile(APP=GlobalVar.c,OPTION="--no-maple-phase -o GlobalVar") +run(GlobalVar) diff --git a/testsuite/c_test/driver_test/AST0039-StructInArray/StructInArray.c b/testsuite/c_test/driver_test/AST0039-StructInArray/StructInArray.c new file mode 100644 index 0000000000000000000000000000000000000000..dac5f6b37feebf293db19223a670da5a3ccbb82a --- /dev/null +++ b/testsuite/c_test/driver_test/AST0039-StructInArray/StructInArray.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +struct A { + int a; + int b; +}; + +struct B { + int c; + int d; + struct A singleA; + int inB[2]; +}; + +int main() { + struct B s1; + s1.inB[1] = 15; + printf("%d\n", s1.inB[1]); + + struct A saa[4] = {{1,2},{3,4},{5,6},{7,8}}; + printf("%d\n",saa[0].a); + printf("%d\n",saa[1].b); + saa[0].a = 10; + printf("%d\n",saa[0].a); + saa[1].b = 20; + saa[0].a = 30; + printf("%d\n",saa[0].a); + printf("%d\n",saa[1].b); + printf("%d\n",saa[2].a); + printf("%d\n",saa[2].b); + printf("%d\n",saa[3].a); + printf("%d\n",saa[3].b); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0039-StructInArray/expected.txt b/testsuite/c_test/driver_test/AST0039-StructInArray/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..1e05afb0cd678683e19b4d9ec69b6379d56af712 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0039-StructInArray/expected.txt @@ -0,0 +1,10 @@ +15 +1 +4 +10 +30 +20 +5 +6 +7 +8 diff --git a/testsuite/c_test/driver_test/AST0039-StructInArray/test.cfg b/testsuite/c_test/driver_test/AST0039-StructInArray/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..2227cf217c2b9df95b908d60b65896ddd4568a83 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0039-StructInArray/test.cfg @@ -0,0 +1,2 @@ +compile(APP=StructInArray.c,OPTION="--no-maple-phase -o StructInArray") +run(StructInArray) diff --git a/testsuite/c_test/driver_test/AST0040-LocalAggInitialization/LocalAggInitialization.c b/testsuite/c_test/driver_test/AST0040-LocalAggInitialization/LocalAggInitialization.c new file mode 100644 index 0000000000000000000000000000000000000000..051bf80593e7a488c1e10c9febe5be8d0675da05 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0040-LocalAggInitialization/LocalAggInitialization.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +struct S { + float f; + int i[3]; +}; +union U { + char ch; + int i; + char c[4]; +}; +union U g = {}; +struct SU { + int i; + union U u; +}; +int main() { + struct S s0 = {}; + struct S s = { 3.14f, { 3, 4, 5, } }; + printf("%f, %d, %d, %d\n", s.f, s.i[0], s.i[1], s.i[2]); + union U u = {{0}}; + union U u0 = {}; + union U u1 = { 2 }; + union U u2 = { 'a', 2 }; + printf("%d %d %d %d %c %d\n", u.i, u0.i, u1.c[2], u1.i, u2.ch, u2.c[1]); + + struct SU su = { 22, { 33 }}; + printf("%d\n", su.u.i); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0040-LocalAggInitialization/expected.txt b/testsuite/c_test/driver_test/AST0040-LocalAggInitialization/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e33c5c8bb2110e8a00fc3a4f83c0cd82914c1029 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0040-LocalAggInitialization/expected.txt @@ -0,0 +1,3 @@ +3.140000, 3, 4, 5 +0 0 0 2 a 0 +33 diff --git a/testsuite/c_test/driver_test/AST0040-LocalAggInitialization/test.cfg b/testsuite/c_test/driver_test/AST0040-LocalAggInitialization/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..295a0002612016ddf4770319eb0d08551ecf54b6 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0040-LocalAggInitialization/test.cfg @@ -0,0 +1,2 @@ +compile(APP=LocalAggInitialization.c,OPTION="--no-maple-phase -o LocalAggInitialization") +run(LocalAggInitialization) diff --git a/testsuite/c_test/driver_test/AST0041-AddrOfLabel/AddrOfLabel.c b/testsuite/c_test/driver_test/AST0041-AddrOfLabel/AddrOfLabel.c new file mode 100644 index 0000000000000000000000000000000000000000..eaac69b6e0a25dba7c9ecda8cead6312af0bfb07 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0041-AddrOfLabel/AddrOfLabel.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +int main() { + void *plb = 0; + int visited = 0; +lb: + printf("%d\n", 111); + plb = &&lb; + if (visited == 0) { + visited = 1; + goto *plb; + } + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0041-AddrOfLabel/expected.txt b/testsuite/c_test/driver_test/AST0041-AddrOfLabel/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..2bbe845f4ef76194eda16eaad3b846e7ba014516 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0041-AddrOfLabel/expected.txt @@ -0,0 +1,2 @@ +111 +111 diff --git a/testsuite/c_test/driver_test/AST0041-AddrOfLabel/test.cfg b/testsuite/c_test/driver_test/AST0041-AddrOfLabel/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..9cf8408d6c7a3d12bea48016d3f67a6da6d27c9e --- /dev/null +++ b/testsuite/c_test/driver_test/AST0041-AddrOfLabel/test.cfg @@ -0,0 +1,2 @@ +compile(APP=AddrOfLabel.c,OPTION="--no-maple-phase -o AddrOfLabel") +run(AddrOfLabel) diff --git a/testsuite/c_test/driver_test/AST0070-builtin_rotateXXX/builtin_rotateXXX.c b/testsuite/c_test/driver_test/AST0070-builtin_rotateXXX/builtin_rotateXXX.c new file mode 100644 index 0000000000000000000000000000000000000000..ff63585e3c5720602833e9f13c692db8b24d819c --- /dev/null +++ b/testsuite/c_test/driver_test/AST0070-builtin_rotateXXX/builtin_rotateXXX.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +#include +#include + +int ConvertBinaryToDecimal(long long n) { + int dec = 0, i = 0, rem; + while (n != 0) { + rem = n % 10; + n /= 10; + dec += rem * pow(2, i); + ++i; + } + return dec; +} + +int main() { + unsigned int x = ConvertBinaryToDecimal(10000110); + unsigned int z = __builtin_rotateleft8(x, 11); + printf("%u\n", z); // 52: 0011 0100 + x = ConvertBinaryToDecimal(1000001101000010); + z = __builtin_rotateleft16(x, 23); + printf("%u\n", z); // 41281: 1010 0001 0100 0001 + x = ConvertBinaryToDecimal(1000001101000010); + z = __builtin_rotateleft32(x, 23); + printf("%u\n", z); // 2701131841: 1010 0001 0000 0000 0000 0000 0100 0001 + uint64_t w = __builtin_rotateleft64(3, 63); + printf("%llu\n", w); // 9223372036854775809: 1000000000000000000000000000000000000000000000000000000000000001 + printf("\n"); + + x = ConvertBinaryToDecimal(10000110); + z = __builtin_rotateright8(x, 11); + printf("%u\n", z); // 208: 1101 0000 + x = ConvertBinaryToDecimal(1000001101000010); + z = __builtin_rotateright16(x, 23); + printf("%u\n", z); // 34054: 1000 0101 000 00110 + x = ConvertBinaryToDecimal(1000001101000010); + z = __builtin_rotateright32(x, 23); + printf("%u\n", z); // 17204224: 0000 0001 0000 0110 1000 0100 0000 0000 + w = __builtin_rotateright64(3, 1); + printf("%llu\n", w); // 9223372036854775809: 1000000000000000000000000000000000000000000000000000000000000001 + + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0070-builtin_rotateXXX/expected.txt b/testsuite/c_test/driver_test/AST0070-builtin_rotateXXX/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..aa8c2766becdd3617039c9cfdf7711d736f1776a --- /dev/null +++ b/testsuite/c_test/driver_test/AST0070-builtin_rotateXXX/expected.txt @@ -0,0 +1,9 @@ +52 +41281 +2701131841 +9223372036854775809 + +208 +34054 +17204224 +9223372036854775809 diff --git a/testsuite/c_test/driver_test/AST0070-builtin_rotateXXX/test.cfg b/testsuite/c_test/driver_test/AST0070-builtin_rotateXXX/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..b2948b3a55fc63119d3554f559a0578d60ef10d9 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0070-builtin_rotateXXX/test.cfg @@ -0,0 +1,2 @@ +compile(APP=builtin_rotateXXX.c,OPTION="--no-maple-phase -lm -o builtin_rotateXXX") +run(builtin_rotateXXX) diff --git a/testsuite/c_test/driver_test/AST0072-InvalidInitializer/InvalidInitializer.c b/testsuite/c_test/driver_test/AST0072-InvalidInitializer/InvalidInitializer.c new file mode 100644 index 0000000000000000000000000000000000000000..0284bae906b8e5f8413b1a46c2a55b73c6b2e176 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0072-InvalidInitializer/InvalidInitializer.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include + +typedef struct { + char *auth_pwfile; + int x; +} auth_config_rec; + +void *Ptr = &((auth_config_rec*)0)->x; + +int main() { + printf("InvalidInitializer"); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0072-InvalidInitializer/expected.txt b/testsuite/c_test/driver_test/AST0072-InvalidInitializer/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..bd9f94ccaf2af0d82288a60ac7e592d0cb4144bb --- /dev/null +++ b/testsuite/c_test/driver_test/AST0072-InvalidInitializer/expected.txt @@ -0,0 +1 @@ +InvalidInitializer \ No newline at end of file diff --git a/testsuite/c_test/driver_test/AST0072-InvalidInitializer/test.cfg b/testsuite/c_test/driver_test/AST0072-InvalidInitializer/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..9653e72ce2de9cf747f80e88757b0a3dbcdf59bd --- /dev/null +++ b/testsuite/c_test/driver_test/AST0072-InvalidInitializer/test.cfg @@ -0,0 +1,2 @@ +compile(APP=InvalidInitializer.c,OPTION="--no-maple-phase -o InvalidInitializer") +run(InvalidInitializer) diff --git a/testsuite/c_test/driver_test/AST0073-RorOptimize/RorOptimize.c b/testsuite/c_test/driver_test/AST0073-RorOptimize/RorOptimize.c new file mode 100644 index 0000000000000000000000000000000000000000..b57edd50dc726ddae9845f09d3d9feb2b55e0da1 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0073-RorOptimize/RorOptimize.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) [2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include +#include + +typedef unsigned long u64; +typedef unsigned int u32; +typedef unsigned short u16; + +// u64 +u64 __attribute__((noinline)) rot1(u64 a, u64 b) { + return (a >> (b&63)) | (a << (64 - (b&63))); +} + +u64 __attribute__((noinline)) rot2(u64 a, u64 b) { + return (a << (64 - (b&63))) | (a >> (b&63)); +} + +// u32 +u32 __attribute__((noinline)) rot3(u32 a, u32 b) { + return (a >> (b&31)) | (a << (32 - (b&31))); +} + +u32 __attribute__((noinline)) rot4(u32 a, u32 b) { + return (a << (32 - (b&31))) | (a >> (b&31)); +} + +// u16 +u16 __attribute__((noinline)) rot5(u16 a, u16 b) { + return (a >> (b&15)) | (a << (16 - (b&15))); +} + +u16 __attribute__((noinline)) rot6(u16 a, u16 b) { + return (a << (16 - (b&15))) | (a >> (b&15)); +} + +int main() { + u64 a = 9; // 1001 + u64 b = rot1(a, 1); + u64 c = rot2(a, 2); + u32 d = rot3(a, 3); + u32 e = rot4(a, 4); + u16 f = rot5(a, 5); + u16 g = rot6(a, 6); + printf("%lu, %lu, %u, %u, %u, %u\n", b, c, d, e, f, g); + return 0; +} diff --git a/testsuite/c_test/driver_test/AST0073-RorOptimize/expected.txt b/testsuite/c_test/driver_test/AST0073-RorOptimize/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..748c315c99c5763cb40fe446cad9ff1295b22414 --- /dev/null +++ b/testsuite/c_test/driver_test/AST0073-RorOptimize/expected.txt @@ -0,0 +1 @@ +9223372036854775812, 4611686018427387906, 536870913, 2415919104, 18432, 9216 diff --git a/testsuite/c_test/driver_test/AST0073-RorOptimize/test.cfg b/testsuite/c_test/driver_test/AST0073-RorOptimize/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..678b9ca7bbd747f46c8cd63942dfed4d1e76087f --- /dev/null +++ b/testsuite/c_test/driver_test/AST0073-RorOptimize/test.cfg @@ -0,0 +1,2 @@ +compile(APP=RorOptimize.c,OPTION="--no-maple-phase -o RorOptimize") +run(RorOptimize) diff --git a/testsuite/c_test/driver_test/DRIVER0001-helloworld/test.cfg b/testsuite/c_test/driver_test/DRIVER0001-helloworld/test.cfg index b968e7ab388fa948d70a79e42c632f1008ca0bbc..3f7e77d5cf7602381a732b61ebc3359b9e4d4eee 100644 --- a/testsuite/c_test/driver_test/DRIVER0001-helloworld/test.cfg +++ b/testsuite/c_test/driver_test/DRIVER0001-helloworld/test.cfg @@ -1,2 +1,2 @@ -compile(APP=main.c,OPTION="--no-maple-phase --static") -run(a) +compile(APP=main.c,OPTION="--no-maple-phase -o app") +run(app) diff --git a/testsuite/c_test/driver_test/DRIVER0002-double/test.cfg b/testsuite/c_test/driver_test/DRIVER0002-double/test.cfg index c35ecc961471e3e3c764c4be509e31a611962a3a..100b7cc77d0aea3154203bb0d15bf946d7dbb208 100644 --- a/testsuite/c_test/driver_test/DRIVER0002-double/test.cfg +++ b/testsuite/c_test/driver_test/DRIVER0002-double/test.cfg @@ -1,2 +1,2 @@ -compile(APP="main.c helper.c",OPTION="--no-maple-phase --static") -run(a) +compile(APP="main.c helper.c",OPTION="--no-maple-phase ") +run(a.out) diff --git a/testsuite/c_test/driver_test/DRIVER0003-macro/test.cfg b/testsuite/c_test/driver_test/DRIVER0003-macro/test.cfg index ad25f535d3d7ec99f4b8fdd1f687763921a63422..be280a14b20053d8e3e3ea8d918a52533156c6f4 100644 --- a/testsuite/c_test/driver_test/DRIVER0003-macro/test.cfg +++ b/testsuite/c_test/driver_test/DRIVER0003-macro/test.cfg @@ -1,2 +1,2 @@ -compile(APP="main.c helper.c",OPTION="--no-maple-phase --static -DTEST1 -DNUM=20 -DTEST2 -UTEST2 -D TEST3 -D EXTRANUM=10") -run(a) +compile(APP="main.c helper.c",OPTION="--no-maple-phase -DTEST1 -DNUM=20 -DTEST2 -UTEST2 -D TEST3 -D EXTRANUM=10") +run(a.out) diff --git a/testsuite/c_test/driver_test/DRIVER0004-syslibs/test.cfg b/testsuite/c_test/driver_test/DRIVER0004-syslibs/test.cfg index d576379fe053ad817191ee4f5461fd3429b09225..ea05e0e14c8c5df8342e3c6b9c7706ec1fa40021 100644 --- a/testsuite/c_test/driver_test/DRIVER0004-syslibs/test.cfg +++ b/testsuite/c_test/driver_test/DRIVER0004-syslibs/test.cfg @@ -1,2 +1,2 @@ -compile(APP=main.c,OPTION="--no-maple-phase --static -lm") -run(a) +compile(APP=main.c,OPTION="--no-maple-phase -lm") +run(a.out) diff --git a/testsuite/c_test/driver_test/SANITY0001-addr/addr.c b/testsuite/c_test/driver_test/SANITY0001-addr/addr.c new file mode 100644 index 0000000000000000000000000000000000000000..1e0281a16f456474f3638644f422a077bcf4ba10 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0001-addr/addr.c @@ -0,0 +1,54 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int deref(int *iptr) { + return *iptr; +} + +int deref1(int *iptr) { + int j = 8; + j = *iptr + j; + return j; +} + +int addrof(int *iptr) { + int j = 8; + int *jptr = &j; + *jptr = *iptr; + return *jptr; +} + +int main() +{ + int v = 5; + int *vptr = &v; + + if (*vptr != 5) { + abort(); + } + if (deref(&v) != 5) { + abort(); + } + if (deref1(&v) != 13) { + abort(); + } + if (addrof(&v) != 5) { + abort(); + } +} + diff --git a/testsuite/c_test/driver_test/SANITY0001-addr/expected.txt b/testsuite/c_test/driver_test/SANITY0001-addr/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0001-addr/test.cfg b/testsuite/c_test/driver_test/SANITY0001-addr/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..8ed463449496a9834b857dc15506cfdd4fe85cbb --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0001-addr/test.cfg @@ -0,0 +1,2 @@ +compile(APP=addr.c,OPTION="--no-maple-phase -o addr") +run(addr) diff --git a/testsuite/c_test/driver_test/SANITY0002-argc/argc.c b/testsuite/c_test/driver_test/SANITY0002-argc/argc.c new file mode 100644 index 0000000000000000000000000000000000000000..2358a1da299fc3197592af44374d8cbea5d88707 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0002-argc/argc.c @@ -0,0 +1,26 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int main(int argc, char *argv[]) +{ + int i = 1; + if (i > argc) { + abort(); + } + return 0; +} diff --git a/testsuite/c_test/driver_test/SANITY0002-argc/expected.txt b/testsuite/c_test/driver_test/SANITY0002-argc/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0002-argc/test.cfg b/testsuite/c_test/driver_test/SANITY0002-argc/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..67e48c9e81bbe98ebc1cdd88e3ed8f6879e48124 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0002-argc/test.cfg @@ -0,0 +1,2 @@ +compile(APP=argc.c,OPTION="--no-maple-phase -o argc") +run(argc) diff --git a/testsuite/c_test/driver_test/SANITY0003-array_single/.raw_file_list.txt b/testsuite/c_test/driver_test/SANITY0003-array_single/.raw_file_list.txt new file mode 100644 index 0000000000000000000000000000000000000000..5d23177adea1119fd56dcc24260bae39c60ba8f0 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0003-array_single/.raw_file_list.txt @@ -0,0 +1,4 @@ +expected.txt +array_single.c +test.cfg +----- diff --git a/testsuite/c_test/driver_test/SANITY0003-array_single/array_single.ast b/testsuite/c_test/driver_test/SANITY0003-array_single/array_single.ast new file mode 100644 index 0000000000000000000000000000000000000000..87b57771fc017b4d658c28c569b036746407c1b9 Binary files /dev/null and b/testsuite/c_test/driver_test/SANITY0003-array_single/array_single.ast differ diff --git a/testsuite/c_test/driver_test/SANITY0003-array_single/array_single.c b/testsuite/c_test/driver_test/SANITY0003-array_single/array_single.c new file mode 100644 index 0000000000000000000000000000000000000000..22c881cddefb5e4cfddcf11a505305631cf2659e --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0003-array_single/array_single.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int A[5]; +int foo(int i) { + A[3] = i + A[2]; + return A[(i >= 0 && i < 5) ? i : 0]; +} + +float B[15]; +float bar(int i) { + B[3] = i + B[2]; + return B[(i >= 0 && i < 5) ? i : 0]; +} + +// variable array type +void vararr(int sz) { + int my[sz]; + int i; + for (i = 0; i < sz; ++i) { + my[i] = i; + } + for (i = 0; i < sz; ++i) { + if (my[i] != i) { + abort(); + } + } +} + +int main() +{ + vararr(4); + + A[0] = 0; + A[2] = A[3] = 2; + if (A[3] != 2) { + abort(); + } + if (foo(2) != 2) { + abort(); + } + if (A[3] != 4) { + abort(); + } + if (foo(5) != 0) { + abort(); + } + if (A[3] != 7) { + abort(); + } + + B[0] = 0; + B[1] = B[2] = B[3] = 3; + if (B[3] != 3) { + abort(); + } + if (bar(1) != 3) { + abort(); + } + if (B[3] != 4) { + abort(); + } + if (bar(5) != 0) { + abort(); + } + if (B[3] != 8) { + abort(); + } + + return 0; +} diff --git a/testsuite/c_test/driver_test/SANITY0003-array_single/expected.txt b/testsuite/c_test/driver_test/SANITY0003-array_single/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0003-array_single/test.cfg b/testsuite/c_test/driver_test/SANITY0003-array_single/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..1f6e84400ba34a88eb9bb15d021e079020f55a4d --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0003-array_single/test.cfg @@ -0,0 +1,2 @@ +compile(APP=array_single.c,OPTION="--no-maple-phase -o array_single") +run(array_single) diff --git a/testsuite/c_test/driver_test/SANITY0004-binop/binop.c b/testsuite/c_test/driver_test/SANITY0004-binop/binop.c new file mode 100644 index 0000000000000000000000000000000000000000..733be02b68f2a7772f5decac6204c75f079fdbf8 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0004-binop/binop.c @@ -0,0 +1,73 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int a = 0x80000001; +unsigned int ua = 0x00000002; +unsigned int val = 0xffffff84; + +int main() +{ + int c = a; + + c += a | 0; + c += a & 1; + c += a ^ 0; + c += a >> 0; + c += a << 0; + + c += a | 1; + c += a & 5; + c += a ^ 1; + c += a >> 1; + c += a << 1; + + c += a | 0x7ff; + c += a & 0x7ff; + c += a ^ 0x7ff; + c += a >> 16; + c += a << 16; + + c += a | 0xfff; + c += a & 0xfff; + c += a ^ 0xfff; + c += a >> 24; + c += a << 24; + + c += a | 0xffff; + c += a & 0xffff; + c += a ^ 0xffff; + c += a >> 31; + c += a << 31; + + unsigned int u = ua; + u += ua >> 0; + u += ua >> 1; + u += ua >> 16; + u += a >> 24; + u += a >> 31; + + if (c != 0xc102af83) { + abort(); + } + if (u != 0xffffff84) { + abort(); + } + if (u != val) { + abort(); + } +} diff --git a/testsuite/c_test/driver_test/SANITY0004-binop/expected.txt b/testsuite/c_test/driver_test/SANITY0004-binop/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0004-binop/test.cfg b/testsuite/c_test/driver_test/SANITY0004-binop/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..9561de3a26b48d10f753edd2368528bacb19cfb7 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0004-binop/test.cfg @@ -0,0 +1,2 @@ +compile(APP=binop.c,OPTION="--no-maple-phase -o binop") +run(binop) diff --git a/testsuite/c_test/driver_test/SANITY0005-cand/cand.c b/testsuite/c_test/driver_test/SANITY0005-cand/cand.c new file mode 100644 index 0000000000000000000000000000000000000000..fa71bffcbb09d2873f2181fb4b43616789eccb50 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0005-cand/cand.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int i = 2; +int main() { + int v = (((i > 0) && (i < 3)) ? 1 : 2); + if ( v != 1 ) { + abort(); + } + + v = (((i > 0) && (i < 2)) ? 1 : 2); + if ( v != 2 ) { + abort(); + } + + v = (((i > 2) && (i < 3)) ? 1 : 2); + if ( v != 2 ) { + abort(); + } +} diff --git a/testsuite/c_test/driver_test/SANITY0005-cand/expected.txt b/testsuite/c_test/driver_test/SANITY0005-cand/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0005-cand/test.cfg b/testsuite/c_test/driver_test/SANITY0005-cand/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..75021196e627708888c605e2306a2e10c046355c --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0005-cand/test.cfg @@ -0,0 +1,2 @@ +compile(APP=cand.c,OPTION="--no-maple-phase -o cand") +run(cand) diff --git a/testsuite/c_test/driver_test/SANITY0006-goto/expected.txt b/testsuite/c_test/driver_test/SANITY0006-goto/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0006-goto/goto.c b/testsuite/c_test/driver_test/SANITY0006-goto/goto.c new file mode 100644 index 0000000000000000000000000000000000000000..a0bad57bf41a655f6006851822ecfd95008cbf1a --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0006-goto/goto.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int g = 5; + +int main() { + for (int i = 0; i < 10; i++) { + if (i == 1) { + goto label; + } + g = i; // 0 + } + abort(); + +label: + if (g != 0) { + abort(); + } + return 0; +} diff --git a/testsuite/c_test/driver_test/SANITY0006-goto/test.cfg b/testsuite/c_test/driver_test/SANITY0006-goto/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..532cd95a4135ae313f9dc358ceabf7b83e91e2ed --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0006-goto/test.cfg @@ -0,0 +1,2 @@ +compile(APP=goto.c,OPTION="--no-maple-phase -o goto") +run(goto) diff --git a/testsuite/c_test/driver_test/SANITY0007-hello/expected.txt b/testsuite/c_test/driver_test/SANITY0007-hello/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0007-hello/hello.c b/testsuite/c_test/driver_test/SANITY0007-hello/hello.c new file mode 100644 index 0000000000000000000000000000000000000000..8b6d7b83d5d7fe7586ce7c78400810e67555c8e9 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0007-hello/hello.c @@ -0,0 +1,27 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int main() { + char str[32]; + int v = sprintf(str,"hello world\n"); + + if (v != 12) { + abort(); + } + return 0; +} diff --git a/testsuite/c_test/driver_test/SANITY0007-hello/test.cfg b/testsuite/c_test/driver_test/SANITY0007-hello/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..25bf685d1bf658d5a6db2a12b2bffda499f7a3bb --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0007-hello/test.cfg @@ -0,0 +1,2 @@ +compile(APP=hello.c,OPTION="--no-maple-phase -o hello") +run(hello) diff --git a/testsuite/c_test/driver_test/SANITY0008-if_call_return/expected.txt b/testsuite/c_test/driver_test/SANITY0008-if_call_return/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0008-if_call_return/if_call_return.c b/testsuite/c_test/driver_test/SANITY0008-if_call_return/if_call_return.c new file mode 100644 index 0000000000000000000000000000000000000000..e55533bd1fbb89fdce2b16381c6ee2fc19d2f68a --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0008-if_call_return/if_call_return.c @@ -0,0 +1,44 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int i = 1; +float f = 2.2; +long long ll = 3; +double d = 4.4; + +int fi(){ return i; } +float ff(){ return f; } +long long fll(){ return ll; } +double fd(){ return d; } + +int main() { + if (fi() != 1) { + abort(); + } + if (ff() != (float)2.2) { + abort(); + } + if (fll() != 3) { + abort(); + } + if (fd() != 4.4) { + abort(); + } + return 0; +} + diff --git a/testsuite/c_test/driver_test/SANITY0008-if_call_return/test.cfg b/testsuite/c_test/driver_test/SANITY0008-if_call_return/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..f69eadad91398a0a2b56a2087c233a49a8ef48ad --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0008-if_call_return/test.cfg @@ -0,0 +1,2 @@ +compile(APP=if_call_return.c,OPTION="--no-maple-phase -o if_call_return") +run(if_call_return) diff --git a/testsuite/c_test/driver_test/SANITY0009-if_else/expected.txt b/testsuite/c_test/driver_test/SANITY0009-if_else/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0009-if_else/if_else.c b/testsuite/c_test/driver_test/SANITY0009-if_else/if_else.c new file mode 100644 index 0000000000000000000000000000000000000000..63d19c2a83f1279f55ed509df7466dd9a0b7bd6f --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0009-if_else/if_else.c @@ -0,0 +1,28 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int main() { + int i = 1; + + if (i > 1) { + abort(); + } else { + printf(""); + } + return 0; +} diff --git a/testsuite/c_test/driver_test/SANITY0009-if_else/test.cfg b/testsuite/c_test/driver_test/SANITY0009-if_else/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..a06c1e66f05af19d87d5b8d60ba5c3bb888174dc --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0009-if_else/test.cfg @@ -0,0 +1,2 @@ +compile(APP=if_else.c,OPTION="--no-maple-phase -o if_else") +run(if_else) diff --git a/testsuite/c_test/driver_test/SANITY0010-if_else_fp/expected.txt b/testsuite/c_test/driver_test/SANITY0010-if_else_fp/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0010-if_else_fp/if_else_fp.c b/testsuite/c_test/driver_test/SANITY0010-if_else_fp/if_else_fp.c new file mode 100644 index 0000000000000000000000000000000000000000..65d0609a1489f46caf46379efc995592b250c304 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0010-if_else_fp/if_else_fp.c @@ -0,0 +1,108 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int main() { + double d1 = 10; + double d2 = 20; + int i = 0; + + if (d1 <= d2) { + i++; + } else { + abort(); + } + + if (d2 >= d1) { + i++; + } else { + abort(); + } + + if (d2 > d1) { + i++; + } else { + abort(); + } + + if (d1 < d2 && d2 > d1) { + i++; + } else { + abort(); + } + + if (d1 != d2) { + i++; + } else { + abort(); + } + + d1 = 20; + if (d1 <= d2) { + if (d1 == d2) { + i++; + } else { + abort(); + } + } + + float f1 = 10; + float f2 = 20; + + if (f1 <= f2) { + i++; + } else { + abort(); + } + + if (f2 >= f1) { + i++; + } else { + abort(); + } + + if (f2 > f1) { + i++; + } else { + abort(); + } + + if (f1 < f2 && f2 > f1) { + i++; + } else { + abort(); + } + + if (f1 != f2) { + i++; + } else { + abort(); + } + + f1 = 20; + if (f1 <= f2) { + if (f1 == f2) { + i++; + } else { + abort(); + } + } + + if (i != 12) { + abort(); + } +} diff --git a/testsuite/c_test/driver_test/SANITY0010-if_else_fp/test.cfg b/testsuite/c_test/driver_test/SANITY0010-if_else_fp/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..79cfd99805bffd7bbb67a161aca2d351fb46c523 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0010-if_else_fp/test.cfg @@ -0,0 +1,2 @@ +compile(APP=if_else_fp.c,OPTION="--no-maple-phase -o if_else_fp") +run(if_else_fp) diff --git a/testsuite/c_test/driver_test/SANITY0011-ind_call/expected.txt b/testsuite/c_test/driver_test/SANITY0011-ind_call/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0011-ind_call/ind_call.c b/testsuite/c_test/driver_test/SANITY0011-ind_call/ind_call.c new file mode 100644 index 0000000000000000000000000000000000000000..6cfda4c04c7b1e4ec4e4dd1b32131e525baeda3e --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0011-ind_call/ind_call.c @@ -0,0 +1,31 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int x = 1; + +int foo(){return x;} + +int main() { + int (*fptr)() = foo; + int v = fptr(); + + if (v != 1) { + abort(); + } + return 0; +} diff --git a/testsuite/c_test/driver_test/SANITY0011-ind_call/test.cfg b/testsuite/c_test/driver_test/SANITY0011-ind_call/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..c05b42ed6b96a0c1c8012d9fb55e03d45c529dba --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0011-ind_call/test.cfg @@ -0,0 +1,2 @@ +compile(APP=ind_call.c,OPTION="--no-maple-phase -o ind_call") +run(ind_call) diff --git a/testsuite/c_test/driver_test/SANITY0012-large_stack/expected.txt b/testsuite/c_test/driver_test/SANITY0012-large_stack/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0012-large_stack/large_stack.c b/testsuite/c_test/driver_test/SANITY0012-large_stack/large_stack.c new file mode 100644 index 0000000000000000000000000000000000000000..41bc2c2449dc29ad6d971eeae6b762abac286bdc --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0012-large_stack/large_stack.c @@ -0,0 +1,43 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +#define asize 500 +int sum = 0; +void vararr(int sz) { + int my[sz]; + volatile int a[asize], b[asize], c[asize]; + + for (int i = 0; i< asize; i++) { + a[i] = i; b[i] = i + 1; c[i] = i + 2; + sum = a[i] + b[i] * c[i]; + if (i < sz) { + my[i] = sum; + } + } + + if ((my[0] != 2) || + (my[1] != 7) || + (my[2] != 14) || + (my[3] != 23)) { + abort(); + } +} + +int main() { + vararr(4); +} diff --git a/testsuite/c_test/driver_test/SANITY0012-large_stack/test.cfg b/testsuite/c_test/driver_test/SANITY0012-large_stack/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..34877620e8c092c856bd2d1c751a64708f871cb0 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0012-large_stack/test.cfg @@ -0,0 +1,2 @@ +compile(APP=large_stack.c,OPTION="--no-maple-phase -o large_stack") +run(large_stack) diff --git a/testsuite/c_test/driver_test/SANITY0013-memexpr/expected.txt b/testsuite/c_test/driver_test/SANITY0013-memexpr/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0013-memexpr/memexpr.c b/testsuite/c_test/driver_test/SANITY0013-memexpr/memexpr.c new file mode 100644 index 0000000000000000000000000000000000000000..5417248d6ae6a5757952d51a5cfd07e6decb21e8 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0013-memexpr/memexpr.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int main() { + struct PSas { + short a, b; + int *p; + }(*PSas0), (*PSas1); + + struct PSas pSas0, pSas1, pSasa[10]; + + int i = 5; + PSas0 = &pSas0; + PSas1 = &pSas1; + + pSasa[8].a = 2; + (*PSas0).a = 3; + (*PSas1).p = &i; + + if (pSasa[8].a != 2 || (*PSas0).a != 3 || *((*PSas1).p) != 5) { + abort(); + } + + return 0; +} diff --git a/testsuite/c_test/driver_test/SANITY0013-memexpr/test.cfg b/testsuite/c_test/driver_test/SANITY0013-memexpr/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..249f93d1e92a7f4e23e0326a5e2cda282e45077d --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0013-memexpr/test.cfg @@ -0,0 +1,2 @@ +compile(APP=memexpr.c,OPTION="--no-maple-phase -o memexpr") +run(memexpr) diff --git a/testsuite/c_test/driver_test/SANITY0014-select/expected.txt b/testsuite/c_test/driver_test/SANITY0014-select/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0014-select/select.c b/testsuite/c_test/driver_test/SANITY0014-select/select.c new file mode 100644 index 0000000000000000000000000000000000000000..dfe621fe53908cd13d10df3ee9138b9534cc03c0 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0014-select/select.c @@ -0,0 +1,28 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int main(int argc, char *argv[]) +{ + int i = (argc != 1) ? ((argc != 2) ? ((argc != 3) ? 6 : 7) : 5) : ((argc == 4) ? 8 : 9); + + if (i != 9) { + abort(); + } + + return 0; +} diff --git a/testsuite/c_test/driver_test/SANITY0014-select/test.cfg b/testsuite/c_test/driver_test/SANITY0014-select/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..4a400fc2ae58b49353a40caeb01c56ffb1999b96 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0014-select/test.cfg @@ -0,0 +1,2 @@ +compile(APP=select.c,OPTION="--no-maple-phase -o select") +run(select) diff --git a/testsuite/c_test/driver_test/SANITY0015-select_fp/expected.txt b/testsuite/c_test/driver_test/SANITY0015-select_fp/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0015-select_fp/select_fp.c b/testsuite/c_test/driver_test/SANITY0015-select_fp/select_fp.c new file mode 100644 index 0000000000000000000000000000000000000000..6c3019a9757473356ce65272bf2d8a258c0bb115 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0015-select_fp/select_fp.c @@ -0,0 +1,29 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int main(int argc, char *argv[]) +{ + float f = 2000; + int i = (argc == 1) ? ((f != 200) ? ((f == 2000) ? 6 : 7) : 5) : ((argc == 4) ? 8 : 9); + + if (i != 6) { + abort(); + } + + return 0; +} diff --git a/testsuite/c_test/driver_test/SANITY0015-select_fp/test.cfg b/testsuite/c_test/driver_test/SANITY0015-select_fp/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..dff21dfb160226d4c80128c8f9ae46cdc0bbc6d9 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0015-select_fp/test.cfg @@ -0,0 +1,2 @@ +compile(APP=select_fp.c,OPTION="--no-maple-phase -o select_fp") +run(select_fp) diff --git a/testsuite/c_test/driver_test/SANITY0016-set/expected.txt b/testsuite/c_test/driver_test/SANITY0016-set/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0016-set/set.c b/testsuite/c_test/driver_test/SANITY0016-set/set.c new file mode 100644 index 0000000000000000000000000000000000000000..3eaca49ef8540270ebd929be1991220138a2a3cd --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0016-set/set.c @@ -0,0 +1,112 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include + +void foo1(int x) { // x = (0, 1, -1, 1, 0, 0) + int a1 = x++ == 0; + int a2 = x-- != 0; + int a3 = --x < 0; + int a4 = x+2 > 0; + int a5 = ++x <= 0; + int a6 = x >= 0; + if (a1+a2+a3+a4+a5+a6 != 6) { + abort(); + } +} + +void foo2(int x) { // x = (1, 2, 0, 2, 1, 1) + int a1 = x == 1; + int a2 = ++x != 1; + int a3 = x-2 < 1; + int a4 = x > 1; + int a5 = --x <= 1; + int a6 = x >= 1; + if (a1+a2+a3+a4+a5+a6 != 6) { + abort(); + } +} + +void foo3(int x, int y) { // x&y = (1==1, 1!=2, 0<2, 0>-1, 0<=0, 0>=0) + int a1 = x == y; + int a2 = x != ++y; + int a3 = --x < y--; + int a4 = x > y-2; + int a5 = x <= --y; + int a6 = x >= --y; + if (a1+a2+a3+a4+a5+a6 != 6) { + abort(); + } +} + +void foo4(unsigned x) { // x = (0, 1, 0xf-f, 1, 0, 0) + unsigned a1 = x++ == 0; + unsigned a2 = x-- != 0; + unsigned a3 = (--x < 0) + 1; + unsigned a4 = x+2 > 0; + unsigned a5 = ++x <= 0; + unsigned a6 = x >= 0; + if (a1+a2+a3+a4+a5+a6 != 6) { + abort(); + } +} + +void foo5(unsigned x) { // x = (1, 2, 0, 0xf-f, 1, 1) + unsigned a1 = x == 1; + unsigned a2 = ++x != 1; + unsigned a3 = x-2 < 1; + unsigned a4 = x-3 > 1; + unsigned a5 = --x <= 1; + unsigned a6 = x >= 1; + if (a1+a2+a3+a4+a5+a6 != 6) { + abort(); + } +} + +void foo6(unsigned x, unsigned y) { // x&y = (1==1, 1!=2, 0<2, 0xf-f>1, 0<=0, 0>=0, + // 0xf-f>=0) + unsigned a1 = x == y; + unsigned a2 = x != ++y; + unsigned a3 = --x < y--; + unsigned a4 = --x > y; + unsigned a5 = ++x <= --y; + unsigned a6 = x >= y; + unsigned a7 = --x >= y; + if (a1+a2+a3+a4+a5+a6+a7 != 7) { + abort(); + } +} + +void foo7(unsigned x) { // x = (4096, 4097, 4094, 4097, 4096, 4096) + unsigned a1 = x == 4096; + unsigned a2 = ++x != 4096; + unsigned a3 = x-3 < 4095; + unsigned a4 = x > 4096; + unsigned a5 = --x <= 4096; + unsigned a6 = x >= 4096; + if (a1+a2+a3+a4+a5+a6 != 6) { + abort(); + } +} + +int main() { + foo1(0); + foo2(1); + foo3(1, 1); + foo4(0); + foo5(1); + foo6(1, 1); + foo7(4096); +} diff --git a/testsuite/c_test/driver_test/SANITY0016-set/test.cfg b/testsuite/c_test/driver_test/SANITY0016-set/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..667fda6a6b5dfe7d79bc4ebdfd7291cd99875840 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0016-set/test.cfg @@ -0,0 +1,2 @@ +compile(APP=set.c,OPTION="--no-maple-phase -o set") +run(set) diff --git a/testsuite/c_test/driver_test/SANITY0017-struct_bits/expected.txt b/testsuite/c_test/driver_test/SANITY0017-struct_bits/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0017-struct_bits/struct_bits.c b/testsuite/c_test/driver_test/SANITY0017-struct_bits/struct_bits.c new file mode 100644 index 0000000000000000000000000000000000000000..7deea9e24a201a0bd0c6dfedae98d77c622d64e8 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0017-struct_bits/struct_bits.c @@ -0,0 +1,85 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +typedef struct x { + long x; + unsigned int z1:3; + unsigned int z2:12; + int z3:2; + int z4:10; + int z5:5; + int y; + char z[32]; +} x; + +typedef struct y { + long x; + long long x1 : 5; + long long x2 : 16; + unsigned long long x3 : 33; + long long x4 : 10; + int y; +} y; + +void foo() { + x xxx; + xxx.x = 1; + xxx.y = 2; + xxx.z1 = 0x7; + xxx.z2 = 0x800; + xxx.z3 = 0x3; + xxx.z4 = 0x201; + xxx.z5 = 0x11; + xxx.z[0] = 4; + xxx.z[31] = 6; + xxx.z[1] = 5; + + if (xxx.z1 != 7) { + abort(); + } + if (xxx.z2 != 0x800) { + abort(); + } + if (xxx.z3 != -1) { + abort(); + } + if (xxx.z4 != -511) { + abort(); + } + if (xxx.z5 != -15) { + abort(); + } +} + +void bar() { + y yyy; + + yyy.x = 3; + yyy.y = 4; + yyy.x1 = 7; + yyy.x2 = 0xff; + yyy.x3 = 0x800f0008; + yyy.x4 = 0x15; +} + +int main() { + foo(); + bar(); + return 0; +} + diff --git a/testsuite/c_test/driver_test/SANITY0017-struct_bits/test.cfg b/testsuite/c_test/driver_test/SANITY0017-struct_bits/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..7d6718faaa377fdf1bcfbd66c8830aad4e7aac13 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0017-struct_bits/test.cfg @@ -0,0 +1,2 @@ +compile(APP=struct_bits.c,OPTION="--no-maple-phase -o struct_bits") +run(struct_bits) diff --git a/testsuite/c_test/driver_test/SANITY0018-sum_array/expected.txt b/testsuite/c_test/driver_test/SANITY0018-sum_array/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0018-sum_array/sum_array.c b/testsuite/c_test/driver_test/SANITY0018-sum_array/sum_array.c new file mode 100644 index 0000000000000000000000000000000000000000..714090b6916b9bc58c7aefc5e172e1ec79b28b41 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0018-sum_array/sum_array.c @@ -0,0 +1,43 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +//int main(int argc, char *argv[]) +int main() +{ + int a[10], b[10], c[10], i; + + for (i = 0; i < 10; i++) { + b[i] = i << 2; + c[i] = i << b[i]; + } + + for (i = 0; i < 10; i++) { + a[i] = b[i] + c[9-i]; + } + + int sum = 0; + for (i = 0; i < 10; i++) { + sum += a[i]; + } + + if (sum != 1985229660) { + abort(); + } + + return 0; +} diff --git a/testsuite/c_test/driver_test/SANITY0018-sum_array/test.cfg b/testsuite/c_test/driver_test/SANITY0018-sum_array/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..dfd4ff4f73b972f1d0ef41b407f572c1f214985c --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0018-sum_array/test.cfg @@ -0,0 +1,2 @@ +compile(APP=sum_array.c,OPTION="--no-maple-phase -o sum_array") +run(sum_array) diff --git a/testsuite/c_test/driver_test/SANITY0019-sum/expected.txt b/testsuite/c_test/driver_test/SANITY0019-sum/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0019-sum/sum.c b/testsuite/c_test/driver_test/SANITY0019-sum/sum.c new file mode 100644 index 0000000000000000000000000000000000000000..d49699cfd26d73c389f2019cd01402cf89ec2e9b --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0019-sum/sum.c @@ -0,0 +1,31 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int main(int argc, char *argv[]) { + int sum = 0; + + for (int i = 0; i < 10; i++) { + sum += i; + } + + if (sum != 45) { + abort(); + } + + return 0; +} diff --git a/testsuite/c_test/driver_test/SANITY0019-sum/test.cfg b/testsuite/c_test/driver_test/SANITY0019-sum/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..939fe40e921a92ba9265af0d2368fb10067547b7 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0019-sum/test.cfg @@ -0,0 +1,2 @@ +compile(APP=sum.c,OPTION="--no-maple-phase -o sum") +run(sum) diff --git a/testsuite/c_test/driver_test/SANITY0020-vararg2/expected.txt b/testsuite/c_test/driver_test/SANITY0020-vararg2/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0020-vararg2/test.cfg b/testsuite/c_test/driver_test/SANITY0020-vararg2/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..6bb3bd0f2af067e9bd3cd1f62305050147f91885 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0020-vararg2/test.cfg @@ -0,0 +1,2 @@ +compile(APP=vararg2.c,OPTION="--no-maple-phase -o vararg2") +run(vararg2) diff --git a/testsuite/c_test/driver_test/SANITY0020-vararg2/vararg2.c b/testsuite/c_test/driver_test/SANITY0020-vararg2/vararg2.c new file mode 100644 index 0000000000000000000000000000000000000000..eb0fcd53dd5c71d78156cdf6819bfd6e76dc106a --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0020-vararg2/vararg2.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include + +static double f (float a, ...); +static double (*fp) (float a, ...); + +main () { + fp = f; + if (fp ((float) 1, (double)2) != 3.0) { + abort (); + } + exit (0); +} + +static double +f (float a, ...) { + va_list ap; + + va_start(ap, a); + float i = va_arg(ap, double); + return (double)a + i; +} diff --git a/testsuite/c_test/driver_test/SANITY0021-cc_param2/cc_param2.c b/testsuite/c_test/driver_test/SANITY0021-cc_param2/cc_param2.c new file mode 100644 index 0000000000000000000000000000000000000000..083050da0a3080ee4d2f7a03559bb0e1a5f6a9ff --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0021-cc_param2/cc_param2.c @@ -0,0 +1,46 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +// +// Test calling convention of passing half-half struct param +// +#include +typedef struct { long long i; int j; } S0; +typedef struct { long long i; int j; } S1; +typedef struct { long long i; int j; } S2; + +// IntCC: 1 intreg short, half of s passed on stack, half in fpreg +void foo1( int i1, int i2, int i3, S0 r, int i4, int i5, int i6, int i7, S1 s, S1 t ) +{ + if (r.j != 2) abort(); + if (s.j != 4) abort(); + if (t.j != 6) abort(); +} + +void foo2( int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, S1 s, S1 t ) +{ + if (s.j != 4) abort(); + if (t.j != 6) abort(); +} + +int main() +{ + S0 x = { 1, 2 }; + S1 y = { 3, 4 }; + S1 z = { 5, 6 }; + + foo1(1,2,3,x,4,5,6,7, y, z); + foo2(0,0,0,0,0,0,0,0, y, z); +} diff --git a/testsuite/c_test/driver_test/SANITY0021-cc_param2/expected.txt b/testsuite/c_test/driver_test/SANITY0021-cc_param2/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0021-cc_param2/test.cfg b/testsuite/c_test/driver_test/SANITY0021-cc_param2/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..5f39bb1e95591de5599425ed50f38d41301beac0 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0021-cc_param2/test.cfg @@ -0,0 +1,2 @@ +compile(APP=cc_param2.c,OPTION="--no-maple-phase -o cc_param2") +run(cc_param2) diff --git a/testsuite/c_test/driver_test/SANITY0022-cc_param3/cc_param3.c b/testsuite/c_test/driver_test/SANITY0022-cc_param3/cc_param3.c new file mode 100644 index 0000000000000000000000000000000000000000..9caad4774db86fc94595fbe1a1eb7707f1b3c2aa --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0022-cc_param3/cc_param3.c @@ -0,0 +1,72 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include + +typedef struct { int i; long long j; } S1; +// IntCC: no intreg, entire s passed on stack +void foo0( int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, S1 s ) +{ if (s.j != 2) abort(); } + +// IntCC: 1 intreg short, half of s passed on stack, half $a7 reg +void foo1( int i1, int i2, int i3, int i4, int i5, int i6, int i7, S1 s ) +{ if (s.j != 2) abort(); } + +// FpCC: 1 intreg short, move to IntCC: 1 stack +typedef struct { float i; int j; } S2; +void foo2( int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, S2 s ) +{ if (s.j != 4) abort(); } + +// FpCC: 1 fpreg short, move to IntCC: 1 intreg + 1 stack +void foo3( float i1, float i2, float i3, float i4, float i5, float i6, float i7, float i8, S2 s ) +{ if (s.j != 4) abort(); } + +// FpCC: 2 fpregs short, move to IntCC: 2 stacks +typedef struct { double i; double j; float k; } S4; +void foo4( float i1, float i2, float i3, float i4, float i5, float i6, float i7, float i8, S4 s ) +{ if (s.j != 6) abort(); } + +// IntCC: 1 float on stack, 8 intregs +typedef struct { float i; int j; } S5; +void foo5( int i1, int i2, int i3, int i4, int i5, int i6, int i7, + float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, + S5 s ) +{ if (s.i != 7.0f || s.j != 8) abort(); } + +// IntCC: 1 int on stack, 8 fpregs +void foo6( int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, + float f1, float f2, float f3, float f4, float f5, float f6, float f7, + S5 s ) +{ if (s.i != 7.0f || s.j != 8) abort(); } + +int main() +{ + S1 s1 = { 1, 2 }; + foo0(1,2,3,4,5,6,7,8, s1); + foo1(1,2,3,4,5,6,7, s1); + + S2 s2 = { 3, 4 }; + foo2(1,2,3,4,5,6,7,8, s2); + foo3(0,0,0,0,0,0,0,0, s2); + + S4 s4 = { 5, 6 }; + foo4(0,0,0,0,0,0,0,0, s4); + + S5 s5 = { 7.0f, 8 }; + foo5( 1,2,3,4,5,6,7, 10,20,30,40,50,60,70,80, s5 ); + foo6( 1,2,3,4,5,6,7,8, 10,20,30,40,50,60,70, s5 ); + + return 0; +} diff --git a/testsuite/c_test/driver_test/SANITY0022-cc_param3/expected.txt b/testsuite/c_test/driver_test/SANITY0022-cc_param3/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0022-cc_param3/test.cfg b/testsuite/c_test/driver_test/SANITY0022-cc_param3/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..05a974719f660a9d96595e17562b39f50bc73c52 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0022-cc_param3/test.cfg @@ -0,0 +1,2 @@ +compile(APP=cc_param3.c,OPTION="--no-maple-phase -o cc_param3") +run(cc_param3) diff --git a/testsuite/c_test/driver_test/SANITY0023-cc_sret/cc_sret.c b/testsuite/c_test/driver_test/SANITY0023-cc_sret/cc_sret.c new file mode 100644 index 0000000000000000000000000000000000000000..3b32e2106e5042e0efe29cfe937b43d1a15111db --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0023-cc_sret/cc_sret.c @@ -0,0 +1,186 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +// +// Test calling convention of struct return type +#include +typedef struct { int x; int y; } s1; +typedef struct { long long x; long long y; } s2; +typedef struct { long long x; long long y; int z; } s3; +typedef struct { float x; float y; } f1; +typedef struct { double x; double y; } f2; +typedef struct { float x; char y; char z; short w; } m1; +typedef struct { int x[4]; } a1; +typedef struct { double x[4]; } a2; +typedef struct { float x[2]; } f3; +typedef struct { float x[3]; } f4; +typedef struct { int x; float y; } m2; +typedef struct { double x; long long y; } m3; + +s1 foo1(int i){ s1 x = {1,2}; return x; } // 1 intreg return +s2 foo2(int i){ s2 x = {3,4}; return x; } // 2 intregs return +s3 foo3(int i){ s3 x = {5,6,7}; return x; } // hidden 1st arg, >16by +f1 foo4(int i){ f1 x = {8,9}; return x; } // 2 fpregs return +f2 foo5(int i){ f2 x = {10,11}; return x; } // 2 fpregs return +m1 foo6(int i){ m1 x = {12,13,14,15}; return x; } // 1 intregs return +a1 foo7(int i){ a1 x = {16,17,18,19}; return x; } // 2 intregs return +a2 foo8(int i){ a2 x = {20,21,22,23}; return x; } // hidden 1st arg, >16by +f3 foo9(int i){ f3 x = {24,25}; return x; } // 2 fpregs return +f4 foo10(int i){ f4 x = {26,27,28}; return x; } // 2 intregs return +m2 foo11(int i){ m2 x = {29,30.0}; return x; } // 1 intreg 1 fpreg +m3 foo12(int i){ m3 x = {31.0,32}; return x; } // 1 fpreg 1 intreg + +typedef struct { int a[2]; } sz8; // 8 byte struct +typedef struct { int a[4]; } sz16; // 16 byte struct +typedef struct { int a[8]; } sz32; // 32 byte struct + +sz8 call8() +{ + s1 x; + s2 y; + s3 e; + f1 z; + f2 w; + f3 v; + f4 u; + m1 m; + m2 n; + m3 o; + a1 a; + a2 b; + + x = foo1( 0 ); + if (x.y != 2) abort(); + y = foo2( 0 ); + if (y.y != 4) abort(); + e = foo3( 0 ); + if (e.z != 7) abort(); + z = foo4( 0 ); + if (z.y != 9) abort(); + w = foo5( 0 ); + if (w.y != 11) abort(); + m = foo6( 0 ); + if (m.w != 15) abort(); + a = foo7( 0 ); + if (a.x[3] != 19) abort(); + b = foo8( 0 ); + if (b.x[3] != 23) abort(); + v = foo9( 0 ); + if (v.x[1] != 25) abort(); + u = foo10( 0 ); + if (u.x[2] != 28) abort(); + n = foo11( 0 ); + if (n.x != 29 || n.y != 30.0) abort(); + o = foo12( 0 ); + if (o.x != 31.0 || o.y != 32) abort(); + + sz8 x8 = { 1, 2}; + return x8; +} + +sz16 call16() +{ + s1 x; + s2 y; + s3 e; + f1 z; + f2 w; + f3 v; + f4 u; + m1 m; + m2 n; + m3 o; + a1 a; + a2 b; + + x = foo1( 0 ); + if (x.y != 2) abort(); + y = foo2( 0 ); + if (y.y != 4) abort(); + e = foo3( 0 ); + if (e.z != 7) abort(); + z = foo4( 0 ); + if (z.y != 9) abort(); + w = foo5( 0 ); + if (w.y != 11) abort(); + m = foo6( 0 ); + if (m.w != 15) abort(); + a = foo7( 0 ); + if (a.x[3] != 19) abort(); + b = foo8( 0 ); + if (b.x[3] != 23) abort(); + v = foo9( 0 ); + if (v.x[1] != 25) abort(); + u = foo10( 0 ); + if (u.x[2] != 28) abort(); + n = foo11( 0 ); + if (n.x != 29 || n.y != 30.0) abort(); + o = foo12( 0 ); + if (o.x != 31.0 || o.y != 32) abort(); + + sz16 x16 = { 1, 2, 3, 4}; + return x16; +} + +sz32 call32() +{ + s1 x; + s2 y; + s3 e; + f1 z; + f2 w; + f3 v; + f4 u; + m1 m; + m2 n; + m3 o; + a1 a; + a2 b; + + x = foo1( 0 ); + if (x.y != 2) abort(); + y = foo2( 0 ); + if (y.y != 4) abort(); + e = foo3( 0 ); + if (e.z != 7) abort(); + z = foo4( 0 ); + if (z.y != 9) abort(); + w = foo5( 0 ); + if (w.y != 11) abort(); + m = foo6( 0 ); + if (m.w != 15) abort(); + a = foo7( 0 ); + if (a.x[3] != 19) abort(); + b = foo8( 0 ); + if (b.x[3] != 23) abort(); + v = foo9( 0 ); + if (v.x[1] != 25) abort(); + u = foo10( 0 ); + if (u.x[2] != 28) abort(); + n = foo11( 0 ); + if (n.x != 29 || n.y != 30.0) abort(); + o = foo12( 0 ); + if (o.x != 31.0 || o.y != 32) abort(); + + sz32 x32 = { 1, 2, 3, 4, 5, 6, 7, 8}; + return x32; +} + +int main() +{ + call8(); + call16(); + call32(); +} diff --git a/testsuite/c_test/driver_test/SANITY0023-cc_sret/expected.txt b/testsuite/c_test/driver_test/SANITY0023-cc_sret/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0023-cc_sret/test.cfg b/testsuite/c_test/driver_test/SANITY0023-cc_sret/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..e23ccfa7bed879b3589e42d0bfe8a7db52e8a40d --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0023-cc_sret/test.cfg @@ -0,0 +1,2 @@ +compile(APP=cc_sret.c,OPTION="--no-maple-phase -o cc_sret") +run(cc_sret) diff --git a/testsuite/c_test/driver_test/SANITY0024-vararg1/expected.txt b/testsuite/c_test/driver_test/SANITY0024-vararg1/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0024-vararg1/test.cfg b/testsuite/c_test/driver_test/SANITY0024-vararg1/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..fe1319a086a5181ade822f8eaa8808092b1f6a9b --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0024-vararg1/test.cfg @@ -0,0 +1,2 @@ +compile(APP=vararg1.c,OPTION="--no-maple-phase -o vararg1") +run(vararg1) diff --git a/testsuite/c_test/driver_test/SANITY0024-vararg1/vararg1.c b/testsuite/c_test/driver_test/SANITY0024-vararg1/vararg1.c new file mode 100644 index 0000000000000000000000000000000000000000..9560448c53b86e54a44c359b388cdbf1107e9435 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0024-vararg1/vararg1.c @@ -0,0 +1,73 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include "stdarg.h" +#include "stdlib.h" + +int a,b; +typedef int vfunc_t(int x, int y, ...); +int foo1( int x, int y, ... ) +{ + va_list ap; + + va_start(ap, y); + a = va_arg(ap, int); + b = va_arg(ap, int); + return (int)a + b; +} + +typedef struct { int i; long long j; } S; +int foo2( int a0, int a1, ... ) +{ + va_list ap; + + va_start(ap, a1); + S b = va_arg(ap, S); + if (b.i+b.j != 30) + abort(); +} + +typedef struct { long long x; long long y; int z; } T; +void foo3( int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, T x, ...) +{ + va_list ap; + + va_start(ap, x); + a = va_arg(ap, int); + if (a != 10) // on the stack + abort(); +} + +int main() +{ + vfunc_t *f = &foo1; + int x; + + x = foo1(1,2,3,4); + if (x != 7) + abort(); + x = (*f)(1,2,5,6); + if (x != 11) + abort(); + + S s = {10,20}; + foo2( 1,2, s ); + + T y = { 1, 2, 3 }; + + foo3(1,2,3,4,5,6,7,8, y,10 ); +} + + diff --git a/testsuite/c_test/driver_test/SANITY0025-cc_param1/cc_param1.c b/testsuite/c_test/driver_test/SANITY0025-cc_param1/cc_param1.c new file mode 100644 index 0000000000000000000000000000000000000000..c2b2865213e9dc88d639a1859eba73d4bff188c1 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0025-cc_param1/cc_param1.c @@ -0,0 +1,65 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +// +// Test calling convention of passing struct param +// +#include +typedef struct { int x; int y; } s1; +typedef struct { long long x; long long y; } s2; +typedef struct { long long x; long long y; int z; } s3; +typedef struct { float x; float y; } f1; +typedef struct { double x; double y; } f2; +typedef struct { float x; char y; char z; short w; } m1; +typedef struct { int x[4]; } a1; +typedef struct { float x[4]; } a2; + +void foo1( s1 x ){ if (x.y != 2) abort(); } // 1 intreg +void foo2( s2 x ){ if (x.y != 4) abort(); } // 2 intregs +void foo3( f1 x ){ if (x.y != 9.0f) abort(); } // 2 fpregs +void foo4( f2 x ){ if (x.y != 11.0) abort(); } // 2 fpregs +void foo5( m1 x ){ if (x.w != 15) abort(); } // 1 intreg +void foo6( int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, s2 x) { + if (x.y != 4) abort(); // 8 intregs + 16-by stk +} +void foo7( int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, s3 x) {; + if (x.z != 7) abort(); // 8 intregs + 8-by stk addr + 24-byte s3 anywhere +} +void foo8( a1 x ){ if (x.x[3] != 19) abort(); } // 2 intregs +void foo9( a2 x ){ if (x.x[3] != 23) abort(); } // 2 intregs + +int main() +{ + s1 x = { 1, 2 }; + s2 y = { 3, 4 }; + s3 e = { 5, 6, 7 }; + f1 z = { 8, 9 }; + f2 w = { 10, 11 };; + m1 m = { 12, 13, 14, 15 }; + a1 a = { 16, 17, 18, 19 }; + a2 b = { 20, 21, 22, 23 }; + + foo1( x ); + foo2( y ); + foo3( z ); + foo4( w ); + foo5( m ); + foo6( 1,2,3,4,5,6,7,8,y ); + foo7( 1,2,3,4,5,6,7,8,e ); + foo8( a ); + foo9( b ); + + return 0; +} diff --git a/testsuite/c_test/driver_test/SANITY0025-cc_param1/expected.txt b/testsuite/c_test/driver_test/SANITY0025-cc_param1/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0025-cc_param1/test.cfg b/testsuite/c_test/driver_test/SANITY0025-cc_param1/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..7dbabda35f1449e9dbb19393db0ee9a2d7fcbcc4 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0025-cc_param1/test.cfg @@ -0,0 +1,2 @@ +compile(APP=cc_param1.c,OPTION="--no-maple-phase -o cc_param1") +run(cc_param1) diff --git a/testsuite/c_test/driver_test/SANITY0026-matrixmult/expected.txt b/testsuite/c_test/driver_test/SANITY0026-matrixmult/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0026-matrixmult/matrixmult.c b/testsuite/c_test/driver_test/SANITY0026-matrixmult/matrixmult.c new file mode 100644 index 0000000000000000000000000000000000000000..d672640fe11937e6e36ef7bf21c66c2ce093c243 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0026-matrixmult/matrixmult.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int main() +{ + int a[3][3], b[3][3], c[3][3]; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + a[i][j] = i; + b[i][j] = j; + c[i][j] = 0; + } + } + + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) { + for (int k = 0; k < 3; ++k) { + c[i][j] += a[i][k] * b[k][j]; + } + } + } + int sum = 0; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; ++j) { + sum += c[i][j]; + //printf("c[%d][%d] = %d\n", i, j, c[i][j]); + } + } + if (sum != 27) { + printf("sum = %d\n", sum); + abort(); + } + + return 0; +} diff --git a/testsuite/c_test/driver_test/SANITY0026-matrixmult/test.cfg b/testsuite/c_test/driver_test/SANITY0026-matrixmult/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..9a28ecb23f1fb08201f62a59dc5fdbb97fd83bdd --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0026-matrixmult/test.cfg @@ -0,0 +1,2 @@ +compile(APP=matrixmult.c,OPTION="--no-maple-phase -o matrixmult") +run(matrixmult) diff --git a/testsuite/c_test/driver_test/SANITY0027-convert/convert.c b/testsuite/c_test/driver_test/SANITY0027-convert/convert.c new file mode 100644 index 0000000000000000000000000000000000000000..848ecbbe99809ca706089b6090e9b180f56a6c1a --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0027-convert/convert.c @@ -0,0 +1,44 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +signed char c = 0xff; +unsigned char uc = 0xff; +short s; +int i; +long long l; + +int main() +{ + s = c; + i = s; + l = i; + //printf("signed = %ld ", l); + if (l != -1) { + abort(); + } + + s = uc; + i = s; + l = i; + //printf("unsigned = %ld\n", l); + if (l != 255) { + abort(); + } + + return 0; +} diff --git a/testsuite/c_test/driver_test/SANITY0027-convert/expected.txt b/testsuite/c_test/driver_test/SANITY0027-convert/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0027-convert/test.cfg b/testsuite/c_test/driver_test/SANITY0027-convert/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..24f68d8f9275472d8c9470e9d5c3772d4f6e4049 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0027-convert/test.cfg @@ -0,0 +1,2 @@ +compile(APP=convert.c,OPTION="--no-maple-phase -o convert") +run(convert) diff --git a/testsuite/c_test/driver_test/SANITY0028-inlineasm/asm.c b/testsuite/c_test/driver_test/SANITY0028-inlineasm/asm.c new file mode 100644 index 0000000000000000000000000000000000000000..a210e3bfc2523ca8b9bafbdf59704391fe0e1296 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0028-inlineasm/asm.c @@ -0,0 +1,500 @@ +#include +#include + +#define TEST01 +#define TEST02 +#define TEST03 +#define TEST04 +#define TEST05 +#define TEST06 // "m" +#undef TEST07 // fail // goto label +#define TEST08 +#define TEST09 // "m" +#define TEST10 +#undef TEST11 // fail // unsupported op +#define TEST12 +#define TEST13 +#undef TEST14 // works on arm server not qemu +#define TEST15 +#define TEST16 +#define TEST17 +#define TEST18 + +#ifdef TEST01 +int test01a(int a, int b) { + int c; +// asm volatile("\tadd %0, %1, %2\n" + asm volatile("\tadd %w0, %w1, %w2\n" + : "=r"(c) + : "r"(a), "r"(b)); + return c; +} +void test01() { + long long l1 = 0x80000000LL; + long long l2 = 0x100000000LL; + if (test01a(l1, l2) != 0x80000000) { + printf("test01 failed\n"); + abort(); + } +} +#endif +#ifdef TEST02 +int test02a(int a, int b) { + int c; + asm volatile("add %w0, %w1, %w2" : "=r"(c) : "r"(a), "r"(b) : "x5", "w4", "s2", "d3", "v9"); + return c; +} +void test02() { + long long l1 = 0x80000000LL; + long long l2 = 0x100000000LL; + if (test02a(l1, l2) != 0x80000000) { + printf("test02 failed\n"); + abort(); + } +} +#endif +#ifdef TEST03 +int test03a(int a, int b) { + int c, d; + asm volatile("add %w0, %w2, %w3\n\t" + "add %w1, %w2, %w3\n" + : "=&r"(c), "=r"(d) : "r"(a), "r"(b) : "x5", "w4", "s2", "d3", "v9"); + return (c + d); +} +void test03() { + long long l1 = 0x00000800LL; + long long l2 = 0x00090000LL; + if (test03a(l1, l2) != 0x00121000) { + printf("test03 failed\n"); + abort(); + } +} +#endif +#ifdef TEST04 +int test04a(int a, int b) { + int *e = &a; + asm ("mov %w[e], %w[b]" : [b] "=r" (b) : [e] "r" (*e)); + return a; +} +void test04() { + long long l1 = 0x00000800LL; + long long l2 = 0x00090000LL; + if (test04a(l1, l2) != 0x00000800) { + printf("test04 failed\n"); + abort(); + } +} +#endif +#ifdef TEST05 +int test05a(int a, int b) { + int c; + asm ("add %w[c], %w1, %w2" : [c] "=r" (c) : "r" (a), "r" (b)); + return c; +} +void test05() { + long long l1 = 0x00000800LL; + long long l2 = 0x00090000LL; + if (test05a(l1, l2) != 0x00090800) { + printf("test05 failed\n"); + abort(); + } +} +#endif +#ifdef TEST06 +int test06a(int a, int b) { + int c; + asm ("ldr %x[c], %x1" : [c] "=r" (c) : "m" (a)); + return c; +} +void test06() { + long long l1 = 0x00000800LL; + long long l2 = 0x00090000LL; + if (test06a(l1, l2) != 0x00000800) { + printf("test06 failed\n"); + abort(); + } +} +#endif +#ifdef TEST07 +int test07a(int a, int b) { + asm goto ("b %l0\n" + : /* no output */ + : /* no input */ + : /* no clobber */ + : gohere); + return 0; +gohere: + return 1; +} +void test07() { + long long l1 = 0x00000800LL; + long long l2 = 0x00090000LL; + if (test07a(l1, l2) != 1) { + printf("test07 failed\n"); + abort(); + } +} +#endif +#ifdef TEST08 +int test08a(int a, int b) { + /* %w[c] should not be in the same reg as %w1 */ + int c; + asm ( + "add %w[c], %w1, %w2\n\t" + "mov %w[c], %w1" + : [c] "+r" (c) + : "r" (a), "r" (b)); + return c; +} +void test08() { + long long l1 = 0x00000800LL; + long long l2 = 0x00090000LL; + if (test08a(l1, l2) != 0x00000800) { + printf("test08 failed\n"); + abort(); + } +} +#endif + +#ifdef TEST09 +long g; +int test09a(long x) { + asm volatile("\tldr %0, %1\n" + : "=r"(x) + : "m"(g)); + return x; +}; +void test09() { + g = 0x400; + long l1 = 0x00000800LL; + if (test09a(l1) != 0x0400) { + printf("test09 failed\n"); + abort(); + } +} +#endif + +#ifdef TEST10 +int h1[2]; +int *h = h1; +int test10a() { + long long y; + int z; + asm volatile("add %x0, %x2, #4\n" + "\tldr %w1, [%x0]\n" + : "=r"(y), "=r"(z) + : "r"(h), "m"(h) + : "x1"); + return z; +} +void test10() { + h1[0] = 0x400; + h1[1] = 0x800; + if (test10a() != 0x0800) { + printf("test10 failed\n"); + abort(); + } +} +#endif + +#ifdef TEST11 +unsigned int +crc32c_arm64_u8(unsigned char data, unsigned int init_val) +{ + __asm__ volatile( + "crc32cb %w[crc], %w[crc], %w[value]" + : [crc] "+r" (init_val) + : [value] "r" (data)); + return init_val; +} +unsigned int test11() { + unsigned char data = 10; + unsigned int init_val = 5; + init_val = crc32c_arm64_u8(data, init_val); + printf("init_val %x\n", init_val); +} +#endif + +#ifdef TEST12 +void +prfm_arm64_u8(void *ptr) +{ + asm volatile( + "prfm pstl1keep, %a0\n" + : + : "p" (ptr)); +} +unsigned int test12() { + long long ptr; + prfm_arm64_u8(&ptr); +} +#endif + +#ifdef TEST13 +#define octeontx_load_pair(val0, val1, addr) ({ \ + asm volatile( \ + "ldp %x[x0], %x[x1], [%x[p1]]" \ + :[x0]"=r"(val0), [x1]"=r"(val1) \ + :[p1]"r"(addr) \ + ); }) + +#define octeontx_store_pair(val0, val1, addr) ({ \ + asm volatile( \ + "stp %x[x0], %x[x1], [%x[p1]]" \ + ::[x0]"r"(val0), [x1]"r"(val1), [p1]"r"(addr) \ + ); }) +void test13() +{ + long long addr[2] = {0x111, 0x222}; + long long val0, val1; + long long *ptr = addr; + octeontx_load_pair(val0, val1, ptr); + if (val0 != 0x111) { + printf("test13 val0 failed\n"); + abort(); + } + if (val1 != 0x222) { + printf("test13 val1 failed\n"); + abort(); + } + addr[0] = 0x333; + addr[1] = 0x444; + octeontx_store_pair(val0, val1, ptr); + if (addr[0] != 0x111) { + printf("test13 addr[0] failed\n"); + abort(); + } + if (addr[1] != 0x222) { + printf("test13 addr[1] failed\n"); + abort(); + } +} +#endif + +#ifdef TEST14 +unsigned long long +test14a(void *addr, long long off) +{ + unsigned long long old_val; + + __asm__ volatile( + " .cpu generic+lse+sve\n\t" + " ldadd %1, %0, [%2]\n" + : "=r" (old_val) : "r" (off), "r" (addr) : "memory"); + + return old_val; +} +void test14() +{ + long long val = 5; + long long off = 1; + if (test14a(&val, off) != 5LL && val != 6) { + printf("test14 failed\n"); + abort(); + } +} +#endif + +#ifdef TEST15 +#include +#include +#include +#include + + uint16x4_t byte_cnt; +unsigned char cp = 5; + unsigned char *p = &cp; + uint8x16_t rxdf; + uint64x2_t rearm; +uint8_t e0p; + uint8_t *e0 = &e0p; +uint8_t e1p; + uint8_t *e1 = &e1p; +uint8_t e2p; + uint8_t *e2 = &e2p; +uint8_t e3p; + uint8_t *e3 = &e3p; + uint8x16_t mcqe_shuf_m1; + uint8x16_t mcqe_shuf_m2; + uint16x8_t crc_adj; + uint8x8_t len_shuf_m; + +uint16x4_t +test15() +{ + __asm__ volatile ( + /* A.1 load mCQEs into a 128bit register. */ + "ld1 {v16.16b - v17.16b}, [%[mcq]] \n\t" + /* B.1 store rearm data to mbuf. */ + "st1 {%[rearm].2d}, [%[e0]] \n\t" + "add %[e0], %[e0], #16 \n\t" + "st1 {%[rearm].2d}, [%[e1]] \n\t" + "add %[e1], %[e1], #16 \n\t" + /* C.1 combine data from mCQEs with rx_descriptor_fields1. */ + "tbl v18.16b, {v16.16b}, %[mcqe_shuf_m1].16b \n\t" + "tbl v19.16b, {v16.16b}, %[mcqe_shuf_m2].16b \n\t" + "sub v18.8h, v18.8h, %[crc_adj].8h \n\t" + "sub v19.8h, v19.8h, %[crc_adj].8h \n\t" + "orr v18.16b, v18.16b, %[rxdf].16b \n\t" + "orr v19.16b, v19.16b, %[rxdf].16b \n\t" + /* D.1 store rx_descriptor_fields1. */ + "st1 {v18.2d}, [%[e0]] \n\t" + "st1 {v19.2d}, [%[e1]] \n\t" + /* B.1 store rearm data to mbuf. */ + "st1 {%[rearm].2d}, [%[e2]] \n\t" + "add %[e2], %[e2], #16 \n\t" + "st1 {%[rearm].2d}, [%[e3]] \n\t" + "add %[e3], %[e3], #16 \n\t" + /* C.1 combine data from mCQEs with rx_descriptor_fields1. */ + "tbl v18.16b, {v17.16b}, %[mcqe_shuf_m1].16b \n\t" + "tbl v19.16b, {v17.16b}, %[mcqe_shuf_m2].16b \n\t" + "sub v18.8h, v18.8h, %[crc_adj].8h \n\t" + "sub v19.8h, v19.8h, %[crc_adj].8h \n\t" + "orr v18.16b, v18.16b, %[rxdf].16b \n\t" + "orr v19.16b, v19.16b, %[rxdf].16b \n\t" + /* D.1 store rx_descriptor_fields1. */ + "st1 {v18.2d}, [%[e2]] \n\t" + "st1 {v19.2d}, [%[e3]] \n\t" + :[byte_cnt]"=&w"(byte_cnt) + :[mcq]"r"(p), + [rxdf]"w"(rxdf), + [rearm]"w"(rearm), + [e3]"r"(e3), [e2]"r"(e2), [e1]"r"(e1), [e0]"r"(e0), + [mcqe_shuf_m1]"w"(mcqe_shuf_m1), + [mcqe_shuf_m2]"w"(mcqe_shuf_m2), + [crc_adj]"w"(crc_adj), + [len_shuf_m]"w"(len_shuf_m) + :"memory", "v16", "v17", "v18", "v19"); + return byte_cnt; +} +#endif + +#ifdef TEST16 +void test16(unsigned int a) { + __asm__ volatile("mrs %x0, CNTV_CTL_EL0\n\t" : "=r" (a) : : "memory"); +} +#endif + +#ifdef TEST17 +int test17a(int a) { + int c; + asm volatile("\tadd %w0, %w1, %2\n" + : "=r"(c) + : "r"(a), "i"(16)); + return c; +} +void test17() { + long long l1 = 0x80000000LL; + if (test17a(l1) != 0x80000010) { + printf("test01 failed\n"); + abort(); + } +} +#endif + +#ifdef TEST18 +#if 0 +#define _ATOMIC_CMPSET(bar, a, l) \ +_ATOMIC_CMPSET_IMPL(8, w, b, bar, a, l) +//_ATOMIC_CMPSET_IMPL(16, w, h, bar, a, l) +//_ATOMIC_CMPSET_IMPL(32, w, , bar, a, l) +//_ATOMIC_CMPSET_IMPL(64, , , bar, a, l) + +#define _ATOMIC_CMPSET_IMPL(t, w, s, bar, a, l) \ +_ATOMIC_CMPSET_PROTO(t, bar, _llsc) \ +{ \ +uint##t##_t tmp; \ +int res; \ + \ +__asm __volatile( \ +"1: mov %w1, #1\n" \ +" ld"#a"xr"#s" %"#w"0, [%2]\n" \ +" cmp %"#w"0, %"#w"3\n" \ +" b.ne 2f\n" \ +" st"#l"xr"#s" %w1, %"#w"4, [%2]\n" \ +" cbnz %w1, 1b\n" \ +"2:" \ +: "=&r"(tmp), "=&r"(res) \ +: "r" (p), "r" (cmpval), "r" (newval) \ +: "cc", "memory" \ +); \ +return (!res); \ + +#endif + +void *p1; +long long cmpval; +int newval; +void test18a() { + unsigned long long tmp; + int res; + __asm __volatile( + "1: mov %w1, #1\n" + " ldr %x0, [%2]\n" + " cmp %x0, %x3\n" + " b.ne 2f\n" + " stp %w1, %w4, [%2]\n" + " cbnz %w1, 1b\n" + "2:" + : "=&r"(tmp), "=&r"(res) + : "r" (p1), "r" (cmpval), "r" (newval) + : "cc", "memory" + ); +} + +//void test18() { +// test18a(); +//} +#endif + +int main() +{ +#ifdef TEST01 + test01(); +#endif +#ifdef TEST02 + test02(); +#endif +#ifdef TEST03 + test03(); +#endif +#ifdef TEST04 + test04(); +#endif +#ifdef TEST05 + test05(); +#endif +#ifdef TEST06 + test06(); +#endif +#ifdef TEST07 + test07(); +#endif +#ifdef TEST08 + test08(); +#endif +#ifdef TEST09 + test09(); +#endif +#ifdef TEST10 + test10(); +#endif +#ifdef TEST11 + test11(); +#endif +#ifdef TEST12 + test12(); +#endif +#ifdef TEST13 + test13(); +#endif +#ifdef TEST14 + test14(); +#endif +#ifdef TEST15 + test15(); +#endif +#ifdef TEST17 + test17(); +#endif +} diff --git a/testsuite/c_test/driver_test/SANITY0028-inlineasm/expected.txt b/testsuite/c_test/driver_test/SANITY0028-inlineasm/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0028-inlineasm/test.cfg b/testsuite/c_test/driver_test/SANITY0028-inlineasm/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..f09e4e7f7afeb201ad2b150b4303bf1367f0e4d8 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0028-inlineasm/test.cfg @@ -0,0 +1,2 @@ +compile(APP=asm.c,OPTION="--no-maple-phase -I${MAPLE_BUILD_OUTPUT}/lib/include -o asm") +run(asm) diff --git a/testsuite/c_test/driver_test/SANITY0029-extensions/expected.txt b/testsuite/c_test/driver_test/SANITY0029-extensions/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0029-extensions/extensions.c b/testsuite/c_test/driver_test/SANITY0029-extensions/extensions.c new file mode 100644 index 0000000000000000000000000000000000000000..538ad2a4736ad6793964e7a4497472eeba7f5c26 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0029-extensions/extensions.c @@ -0,0 +1,86 @@ +#include +#include + +unsigned char u8 = 0x80; +unsigned short u16 = 0x8000; +unsigned int u32 = 0x80000000; +unsigned long long u64 = 0x8000000000000000ULL; + +signed char i8 = 0x80; +signed short i16 = 0x8000; +signed int i32 = 0x80000000; +signed long long i64 = 0x8000000000000000LL; + +int main() { + signed char ti8 = u8; + if (ti8 != 0xffffff80) abort(); + signed short ti16 = u8; + if (ti16 != 0x80) abort(); + signed int ti32 = u8; + if (ti32 != 0x80) abort(); + signed long long ti64 = u8; + if (ti64 != 0x80) abort(); + + ti8 = u16; + if (ti8 != 0) abort(); + ti16 = u16; + if (ti16 != 0xffff8000) abort(); + ti32 = u16; + if (ti32 != 0x8000) abort(); + ti64 = u16; + if (ti64 != 0x8000) abort(); + + ti8 = u32; + if (ti8 != 0) abort(); + ti16 = u32; + if (ti16 != 0) abort(); + ti32 = u32; + if (ti32 != 0x80000000) abort(); + ti64 = u32; + if (ti64 != 0x80000000) abort(); + + ti8 = u64; + if (ti8 != 0) abort(); + ti16 = u64; + if (ti16 != 0) abort(); + ti32 = u64; + if (ti32 != 0) abort(); + ti64 = u64; + if (ti64 != 0x8000000000000000) abort(); + + unsigned char tu8 = i8; + if (tu8 != 0x80) abort(); + unsigned short tu16 = i8; + if (tu16 != 0xff80) abort(); + unsigned int tu32 = i8; + if (tu32 != 0xffffff80) abort(); + unsigned long long tu64 = i8; + if (tu64 != 0xffffffffffffff80) abort(); + + tu8 = i16; + if (tu8 != 0) abort(); + tu16 = i16; + if (tu16 != 0x8000) abort(); + tu32 = i16; + if (tu32 != 0xffff8000) abort(); + tu64 = i16; + if (tu64 != 0xffffffffffff8000) abort(); + + tu8 = i32; + if (tu8 != 0) abort(); + tu16 = i32; + if (tu16 != 0) abort(); + tu32 = i32; + if (tu32 != 0x80000000) abort(); + tu64 = i32; + if (tu64 != 0xffffffff80000000) abort(); + + tu8 = i64; + if (tu8 != 0) abort(); + tu16 = i64; + if (tu16 != 0) abort(); + tu32 = i64; + if (tu32 != 0) abort(); + tu64 = i64; + if (tu64 != 0x8000000000000000) abort(); +} diff --git a/testsuite/c_test/driver_test/SANITY0029-extensions/test.cfg b/testsuite/c_test/driver_test/SANITY0029-extensions/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..a6cee4f3ef45a888dcec2d95219f59ceec0e6e66 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0029-extensions/test.cfg @@ -0,0 +1,2 @@ +compile(APP=extensions.c,OPTION="--no-maple-phase -o extensions") +run(extensions) diff --git a/testsuite/c_test/driver_test/SANITY0029-neonintrinscs/expected.txt b/testsuite/c_test/driver_test/SANITY0029-neonintrinscs/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0029-neonintrinscs/test.cfg b/testsuite/c_test/driver_test/SANITY0029-neonintrinscs/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..a1b8bf22263a2977639f82a33367b19a760ce89c --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0029-neonintrinscs/test.cfg @@ -0,0 +1,2 @@ +compile(APP=test1.c,OPTION="--no-maple-phase -I${MAPLE_BUILD_OUTPUT}/lib/include -o test1") +run(test1) diff --git a/testsuite/c_test/driver_test/SANITY0029-neonintrinscs/test1.c b/testsuite/c_test/driver_test/SANITY0029-neonintrinscs/test1.c new file mode 100644 index 0000000000000000000000000000000000000000..a8ef4ea4013c74bad2d9cf7b4ecb69e32973b1b9 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0029-neonintrinscs/test1.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include "arm_neon.h" +#include +#include + +uint32x4_t foo(void *p) { + uint16x8_t u16 = vld1q_u16(p); + return vpaddlq_u16(u16); +} + +uint16_t foo2(void *p) { + uint16x8_t u16 = vld1q_u16(p); + return vaddvq_u16(u16); +} + +int main() +{ + char s[] = {1,1,1,1, 2,2,2,2, 3,3,3,3, 4,4,4,4}; + uint32x4_t f1 = foo( &s ); + uint32_t t1, t2, t3, t4; + t1 = vgetq_lane_u32(f1, 0); + // printf("t0: 0x%x\n", t1); + t2 = vgetq_lane_u32(f1, 1); + // printf("t1: 0x%x\n", t2); + t3 = vgetq_lane_u32(f1, 2); + // printf("t2: 0x%x\n", t3); + t4 = vgetq_lane_u32(f1, 3); + // printf("t3: 0x%x\n", t4); + if (t1 != 0x202 || t2 != 0x404 || t3 != 0x606 || t4 != 0x808) + abort(); + + // printf("-- Test 2: --\n"); + uint16_t f2 = foo2( &s ); + // printf("f2: %d\n", f2); + if (f2 != 0x1414) + abort(); +} diff --git a/testsuite/c_test/driver_test/SANITY0030-neonintrinscs/expected.txt b/testsuite/c_test/driver_test/SANITY0030-neonintrinscs/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0030-neonintrinscs/test.cfg b/testsuite/c_test/driver_test/SANITY0030-neonintrinscs/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..6e7b404abb0a374a85c2f633fd3922453c1ce02f --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0030-neonintrinscs/test.cfg @@ -0,0 +1,2 @@ +compile(APP=test2.c,OPTION="--no-maple-phase -I${MAPLE_BUILD_OUTPUT}/lib/include -o test2") +run(test2) diff --git a/testsuite/c_test/driver_test/SANITY0030-neonintrinscs/test2.c b/testsuite/c_test/driver_test/SANITY0030-neonintrinscs/test2.c new file mode 100644 index 0000000000000000000000000000000000000000..1fd7deaad86a5eedc0eb3db5b99efd7e4a1b0146 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0030-neonintrinscs/test2.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include "arm_neon.h" +#include +#include + +uint8x16_t foo(void *p) { + uint8x16_t u1 = vld1q_u8(p); + uint8x16_t u2 = vrev32q_u8(u1); /* reverse */ + return vextq_u8(u1, u2, 8); /* merge at 8 */ +} + +int main() +{ + char s[] = {1,1,2,2, 3,3,4,4, 5,5,6,6, 7,7,8,8}; + uint8x16_t f2 = foo( &s ); + long u8m[2]; + vst1q_u8((void*)&u8m, f2); + // printf("f2: 0x%lx,0x%lx\n", u8m[0], u8m[1]); + if (u8m[0] != 0x808070706060505 || u8m[1] != 0x303040401010202) + abort(); +} diff --git a/testsuite/c_test/driver_test/SANITY0031-neonintrinscs/expected.txt b/testsuite/c_test/driver_test/SANITY0031-neonintrinscs/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0031-neonintrinscs/test.cfg b/testsuite/c_test/driver_test/SANITY0031-neonintrinscs/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..a70a5c7ca5c745a648770e3222356d07bedcb0f8 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0031-neonintrinscs/test.cfg @@ -0,0 +1,2 @@ +compile(APP=test3.c,OPTION="--no-maple-phase -I${MAPLE_BUILD_OUTPUT}/lib/include -o test3") +run(test3) diff --git a/testsuite/c_test/driver_test/SANITY0031-neonintrinscs/test3.c b/testsuite/c_test/driver_test/SANITY0031-neonintrinscs/test3.c new file mode 100644 index 0000000000000000000000000000000000000000..d24ed9943e7474adc764a00636139d3b01e8bc5f --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0031-neonintrinscs/test3.c @@ -0,0 +1,41 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include "arm_neon.h" +#include +#include + +uint32_t foo(void *p) { + uint32x4_t u1 = vld1q_u32(p); + uint32_t uit = vgetq_lane_u32(u1, 3); + unsigned int ui = uit; + if (ui != 4) + abort(); + return uit; +} + +int main() +{ + unsigned int s[] = {1, 2, 3, 4}; + uint32_t ui = foo( &s ); + uint32x4_t t = {1, 1, 1, 1}; + t = vsetq_lane_u32(ui, t, 3); + ui = vgetq_lane_u32(t, 1); + if (ui != 1) + abort(); + if (vgetq_lane_u32(t, 3) != 4) + abort(); + // printf("t: 0x%x 0x%x\n", ui, vgetq_lane_u32(t, 3)); +} diff --git a/testsuite/c_test/driver_test/SANITY0032-neonintrinscs/expected.txt b/testsuite/c_test/driver_test/SANITY0032-neonintrinscs/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0032-neonintrinscs/test.cfg b/testsuite/c_test/driver_test/SANITY0032-neonintrinscs/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..feae807c0064f5c4659e836c15fabe06580e5a20 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0032-neonintrinscs/test.cfg @@ -0,0 +1,2 @@ +compile(APP=test4.c,OPTION="--no-maple-phase -I${MAPLE_BUILD_OUTPUT}/lib/include -o test4") +run(test4) diff --git a/testsuite/c_test/driver_test/SANITY0032-neonintrinscs/test4.c b/testsuite/c_test/driver_test/SANITY0032-neonintrinscs/test4.c new file mode 100644 index 0000000000000000000000000000000000000000..7e0772e89bfcc5dbdac500b67fa2dfab8526d143 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0032-neonintrinscs/test4.c @@ -0,0 +1,53 @@ +/* +2 + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include "arm_neon.h" +#include +#include + +int32x4_t foo1(void *p) { + return vandq_s32( vld1q_s32(p), vdupq_n_s32(3)); +} + +uint16x8_t foo2(void *p, void *q) { + return vandq_u16( vld1q_u16(p), vld1q_u16(q)); +} + +int main() +{ + int s[] = {7,7,7,7}; + int32x4_t r = foo1( &s ); + int t[4]; + vst1q_s32((void*)&t, r); + // printf("r: %x %x %x %x\n", t[0], t[1], t[2], t[3]); + if (t[0] != 3 || t[1] != 3 || t[2] != 3 || t[3] != 3) + abort(); + + // printf("-- Test 4b: uint16x8_t --\n"); + unsigned short s2[] = {7,7,7,7,7,7,7,7}; + unsigned short t2[] = {3,3,3,3,3,3,3,3}; + uint32x4_t r2 = vpaddlq_u16( foo2( &s2, &t2 ) ); + // printf("r2: %x %x %x %x\n", + // vgetq_lane_u32(r2, 0), + // vgetq_lane_u32(r2, 1), + // vgetq_lane_u32(r2, 2), + // vgetq_lane_u32(r2, 0)); + if (vgetq_lane_u32(r2, 0) != 6 || + vgetq_lane_u32(r2, 1) != 6 || + vgetq_lane_u32(r2, 2) != 6 || + vgetq_lane_u32(r2, 0) != 6) + abort(); +} diff --git a/testsuite/c_test/driver_test/SANITY0033-neonintrinscs/expected.txt b/testsuite/c_test/driver_test/SANITY0033-neonintrinscs/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0033-neonintrinscs/test.cfg b/testsuite/c_test/driver_test/SANITY0033-neonintrinscs/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..cdb4b6f408cafb8f5439993e6abaf28ec600cb2f --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0033-neonintrinscs/test.cfg @@ -0,0 +1,2 @@ +compile(APP=test5.c,OPTION="--no-maple-phase -I${MAPLE_BUILD_OUTPUT}/lib/include -o test5") +run(test5) diff --git a/testsuite/c_test/driver_test/SANITY0033-neonintrinscs/test5.c b/testsuite/c_test/driver_test/SANITY0033-neonintrinscs/test5.c new file mode 100644 index 0000000000000000000000000000000000000000..7e0772e89bfcc5dbdac500b67fa2dfab8526d143 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0033-neonintrinscs/test5.c @@ -0,0 +1,53 @@ +/* +2 + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include "arm_neon.h" +#include +#include + +int32x4_t foo1(void *p) { + return vandq_s32( vld1q_s32(p), vdupq_n_s32(3)); +} + +uint16x8_t foo2(void *p, void *q) { + return vandq_u16( vld1q_u16(p), vld1q_u16(q)); +} + +int main() +{ + int s[] = {7,7,7,7}; + int32x4_t r = foo1( &s ); + int t[4]; + vst1q_s32((void*)&t, r); + // printf("r: %x %x %x %x\n", t[0], t[1], t[2], t[3]); + if (t[0] != 3 || t[1] != 3 || t[2] != 3 || t[3] != 3) + abort(); + + // printf("-- Test 4b: uint16x8_t --\n"); + unsigned short s2[] = {7,7,7,7,7,7,7,7}; + unsigned short t2[] = {3,3,3,3,3,3,3,3}; + uint32x4_t r2 = vpaddlq_u16( foo2( &s2, &t2 ) ); + // printf("r2: %x %x %x %x\n", + // vgetq_lane_u32(r2, 0), + // vgetq_lane_u32(r2, 1), + // vgetq_lane_u32(r2, 2), + // vgetq_lane_u32(r2, 0)); + if (vgetq_lane_u32(r2, 0) != 6 || + vgetq_lane_u32(r2, 1) != 6 || + vgetq_lane_u32(r2, 2) != 6 || + vgetq_lane_u32(r2, 0) != 6) + abort(); +} diff --git a/testsuite/c_test/driver_test/SANITY0034-neonintrinscs/expected.txt b/testsuite/c_test/driver_test/SANITY0034-neonintrinscs/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0034-neonintrinscs/test.cfg b/testsuite/c_test/driver_test/SANITY0034-neonintrinscs/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..326a3e5f6a7dd1cd96959b647373b362c50f9b18 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0034-neonintrinscs/test.cfg @@ -0,0 +1,2 @@ +compile(APP=test6.c,OPTION="--no-maple-phase -I${MAPLE_BUILD_OUTPUT}/lib/include -o test6") +run(test6) diff --git a/testsuite/c_test/driver_test/SANITY0034-neonintrinscs/test6.c b/testsuite/c_test/driver_test/SANITY0034-neonintrinscs/test6.c new file mode 100644 index 0000000000000000000000000000000000000000..eaa326e6a1a2d05d6f815ede9753ee5325303df7 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0034-neonintrinscs/test6.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include "arm_neon.h" +#include +#include +#include + +int main() +{ + char s[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + uint8x16_t p = vld1q_u8((void*)s); + uint8x16_t idx = vrev32q_u8(p); + char r[17] = {0}; + uint8x16_t x; + + x = vqtbl1q_u8(p, idx); // reverse + vst1q_u8((void*)r, x); + //printf("r = %s\n", r); + char answer[] = {5, 4, 3, 2, 9, 8, 7, 6, 13, 12, 11, 10, 0, 16, 15, 14}; + if (memcmp(r, answer, 16)) + abort(); +} diff --git a/testsuite/c_test/driver_test/SANITY0035-neonintrinscs/expected.txt b/testsuite/c_test/driver_test/SANITY0035-neonintrinscs/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0035-neonintrinscs/test.cfg b/testsuite/c_test/driver_test/SANITY0035-neonintrinscs/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..05cc29a55999122c0d5cd82b1c20d13b62308cf4 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0035-neonintrinscs/test.cfg @@ -0,0 +1,2 @@ +compile(APP=test7.c,OPTION="--no-maple-phase -I${MAPLE_BUILD_OUTPUT}/lib/include -o test7") +run(test7) diff --git a/testsuite/c_test/driver_test/SANITY0035-neonintrinscs/test7.c b/testsuite/c_test/driver_test/SANITY0035-neonintrinscs/test7.c new file mode 100644 index 0000000000000000000000000000000000000000..f8d20d4c18095d8adfec689a8919146e928efec6 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0035-neonintrinscs/test7.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include "arm_neon.h" +#include +#include + +void foo1() +{ + uint32x2_t c = {1,1}; + + uint8x16_t x = vdupq_n_u8(10); + uint64x2_t y = vreinterpretq_u64_u8(x); + uint64x2_t z = vmlal_u32(y, c, vdup_n_u32(1)); + uint32x4_t r = vreinterpretq_u32_u64(z); + //printf("r: 0x%x 0x%x 0x%x 0x%x\n", vgetq_lane_u32(r, 0), vgetq_lane_u32(r, 1), + // vgetq_lane_u32(r, 2), vgetq_lane_u32(r, 3)); + // printf("z = 0x%lx, 0x%lx\n", vget_high_u64(z), vget_low_u64(z)); + if (vgetq_lane_u32(r, 0) != 0xa0a0a0b || vgetq_lane_u32(r, 1) != 0xa0a0a0a || + vgetq_lane_u32(r, 2) != 0xa0a0a0b || vgetq_lane_u32(r, 3) != 0xa0a0a0a) + abort(); +} + +void foo2() { + uint64x2_t x = { 2, 4 }; + uint32x4_t zero = { 0, 0, 0, 0 }; + uint32x4_t r = veorq_u32( vreinterpretq_u32_u64(x), zero ); + if (vgetq_lane_u32(r, 0) != 2) + abort(); + if (vgetq_lane_u32(r, 1) != 0) + abort(); + if (vgetq_lane_u32(r, 2) != 4) + abort(); + if (vgetq_lane_u32(r, 3) != 0) + abort(); +} + +void foo3() { + uint64x2_t x = { 2, 4 }; + uint64x2_t zero = { 0, 0 }; + uint32x4_t r = vreinterpretq_u32_u64( veorq_u64( x, zero ) ); + if (vgetq_lane_u32(r, 0) != 2) + abort(); + if (vgetq_lane_u32(r, 1) != 0) + abort(); + if (vgetq_lane_u32(r, 2) != 4) + abort(); + if (vgetq_lane_u32(r, 3) != 0) + abort(); +} + +void foo4() { +#if 0 // Turn off temporarily, awaiting arm_neon.h to be updated. Turn on + // again after that. + uint32x2_t a = {1, 0}; + uint32x2_t b = vdup_n_u32(10); + uint32x4_t r = vreinterpretq_u32_u64( vmull_u32(a, b) ); + if (vgetq_lane_u32(r, 0) != 0xa || vgetq_lane_u32(r, 1) != 0 || + vgetq_lane_u32(r, 2) != 0 || vgetq_lane_u32(r, 3) != 0) + abort(); +#endif +} + +int main() +{ + foo1(); + foo2(); + foo3(); + foo4(); +} diff --git a/testsuite/c_test/driver_test/SANITY0036-neonintrinscs/expected.txt b/testsuite/c_test/driver_test/SANITY0036-neonintrinscs/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0036-neonintrinscs/test.cfg b/testsuite/c_test/driver_test/SANITY0036-neonintrinscs/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..5eef22367a6b499f5e874d6935ce015c1d0a3fa8 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0036-neonintrinscs/test.cfg @@ -0,0 +1,2 @@ +compile(APP=test8.c,OPTION="--no-maple-phase -I${MAPLE_BUILD_OUTPUT}/lib/include -o test8") +run(test8) diff --git a/testsuite/c_test/driver_test/SANITY0036-neonintrinscs/test8.c b/testsuite/c_test/driver_test/SANITY0036-neonintrinscs/test8.c new file mode 100644 index 0000000000000000000000000000000000000000..b1bf636d0f81943da445b521c76c29c2c4d72b18 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0036-neonintrinscs/test8.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include "arm_neon.h" +#include + +int32x4_t f1( int32x4_t p, int32x4_t q ) +{ + return p << q; +} + +uint32x2_t f2( uint32x2_t p, uint32x2_t q ) +{ + return p >> q; +} + +int main() +{ + int32x4_t x = vdupq_n_s32( 1 ); + int32x4_t y = vdupq_n_s32( 1 ); + + int32x4_t m1 = f1( x, y ); + uint32x4_t c1 = m1 == 2; + if (vgetq_lane_u32(c1, 0) != 0xffffffff || + vgetq_lane_u32(c1, 1) != 0xffffffff || + vgetq_lane_u32(c1, 2) != 0xffffffff || + vgetq_lane_u32(c1, 3) != 0xffffffff) + abort(); + + uint32x2_t x2 = vdup_n_u32( 2 ); + uint32x2_t y2 = vdup_n_u32( 1 ); + + uint32x2_t m2 = f2( x2, y2 ); + uint32x2_t c2 = m2 == y2; + if (vget_lane_u32(c2, 0) != 0xffffffff || + vget_lane_u32(c2, 1) != 0xffffffff) + abort(); +} diff --git a/testsuite/c_test/driver_test/SANITY0037-neonintrinscs/expected.txt b/testsuite/c_test/driver_test/SANITY0037-neonintrinscs/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0037-neonintrinscs/test.cfg b/testsuite/c_test/driver_test/SANITY0037-neonintrinscs/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..b61963492c67db02d8ce879814434034c9467062 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0037-neonintrinscs/test.cfg @@ -0,0 +1,2 @@ +compile(APP=test9.c,OPTION="--no-maple-phase -I${MAPLE_BUILD_OUTPUT}/lib/include -o test9") +run(test9) diff --git a/testsuite/c_test/driver_test/SANITY0037-neonintrinscs/test9.c b/testsuite/c_test/driver_test/SANITY0037-neonintrinscs/test9.c new file mode 100644 index 0000000000000000000000000000000000000000..3bbe0841be1bda3fb5fa046ca211c054e2f7141b --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0037-neonintrinscs/test9.c @@ -0,0 +1,34 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include "arm_neon.h" +#include + +int main() +{ + uint16x8_t s1 = { 1, 2, 3, 4, 5, 6, 7, 8 }; + + uint16x8_t r1 = s1 == s1; + uint16x8_t r2 = vceqq_u16(s1, s1); + uint16x8_t r3 = r1 == r2; // all 1s + int64x2_t r4 = (int64x2_t)r3; + int64x2_t r5 = ~r4; // all 0s + uint32x4_t r6 = (uint32x4_t) (r5 < 0); // zero compare instr + if (vgetq_lane_u32(r6, 0) != 0 || + vgetq_lane_u32(r6, 1) != 0 || + vgetq_lane_u32(r6, 2) != 0 || + vgetq_lane_u32(r6, 3) != 0) + abort(); +} diff --git a/testsuite/c_test/driver_test/SANITY0038-neonintrinscs/expected.txt b/testsuite/c_test/driver_test/SANITY0038-neonintrinscs/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0038-neonintrinscs/test.cfg b/testsuite/c_test/driver_test/SANITY0038-neonintrinscs/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..77cc108587a67665b09bc4c0638a984385916172 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0038-neonintrinscs/test.cfg @@ -0,0 +1,2 @@ +compile(APP=test10.c,OPTION="--no-maple-phase -I${MAPLE_BUILD_OUTPUT}/lib/include -o test10") +run(test10) diff --git a/testsuite/c_test/driver_test/SANITY0038-neonintrinscs/test10.c b/testsuite/c_test/driver_test/SANITY0038-neonintrinscs/test10.c new file mode 100644 index 0000000000000000000000000000000000000000..23f99d43ae5006c903eba59c0a31d8966912d7df --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0038-neonintrinscs/test10.c @@ -0,0 +1,53 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ +#include "arm_neon.h" +#include "stdlib.h" + +uint64x1_t foo1( uint64x2_t s ) +{ + return vget_high_u64(s) + vget_low_u64(s); +} + +uint16x4_t foo2( uint16x8_t s ) +{ + return vget_high_u16(s) + vget_low_u16(s); +} + +int64x1_t foo3( int32x2_t s ) +{ + return vpaddl_s32(s); +} + +int main() +{ + uint64x2_t s = { 10, 20 }; + uint64x1_t r1 = foo1( s ); + if ((long)r1 != 30) + abort(); + +#if 0 + uint16x8_t s2 = { 1,1,1,1,2,2,2,2 }; + uint16x4_t r2 = foo2( s2 ); + if (vget_lane_u16(r2,0) != 3 || + vget_lane_u16(r2,3) != 3) + abort(); + + int32x2_t s3 = { 10, 20 }; + int64x1_t t3 = foo3( s3 ); + if ((long)t3 != 30) + abort(); +#endif +} + diff --git a/testsuite/c_test/driver_test/SANITY0039-neonintrinscs/expected.txt b/testsuite/c_test/driver_test/SANITY0039-neonintrinscs/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0039-neonintrinscs/test.cfg b/testsuite/c_test/driver_test/SANITY0039-neonintrinscs/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..1874f7dd949f790aca77ffad62f66dcc694510c7 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0039-neonintrinscs/test.cfg @@ -0,0 +1,2 @@ +compile(APP=test11.c,OPTION="--no-maple-phase -I${MAPLE_BUILD_OUTPUT}/lib/include -o test11") +run(test11) diff --git a/testsuite/c_test/driver_test/SANITY0039-neonintrinscs/test11.c b/testsuite/c_test/driver_test/SANITY0039-neonintrinscs/test11.c new file mode 100644 index 0000000000000000000000000000000000000000..2000c202de4fdaf027df0550b64c73a172b03c40 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0039-neonintrinscs/test11.c @@ -0,0 +1,64 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ +#include "arm_neon.h" +#include + +uint32x2x2_t foo( uint32x4_t data, uint32x2x2_t a ) +{ + uint32x2x2_t r = vzip_u32( vget_low_u32(data), vget_high_u32(data) ); + uint32x2_t t1 = r.val[0] == a.val[0]; + uint32x2_t t2 = r.val[1] == a.val[1]; + + if (vget_lane_u32(t1, 0) != 0xffffffff || + vget_lane_u32(t1, 1) != 0xffffffff || + vget_lane_u32(t2, 0) != 0xffffffff || + vget_lane_u32(t2, 1) != 0xffffffff) + abort(); + + return r; +} + +int main() +{ + uint32x4_t data = { 10, 20, 30, 40 }; + uint32x2x2_t a; + uint32x2x2_t r; + + a.val[0] = vset_lane_u32(10, a.val[0], 0); + a.val[0] = vset_lane_u32(30, a.val[0], 1); + a.val[1] = vset_lane_u32(20, a.val[1], 0); + a.val[1] = vset_lane_u32(40, a.val[1], 1); + + r = foo( data, a ); + + uint32x2_t a1 = { 1, 3 }; + uint32x2_t b1 = { 2, 4 }; + uint32x2_t m1 = { 1, 2 }; + uint32x2_t m2 = { 4, 5 }; + + uint32x2x2_t c = vzip_u32( a1, b1 ); + uint32x2_t r1 = c.val[0] == m1; // vzip_u32(a,b).val[0] == m1; + if (vget_lane_u32(r1, 0) != 0xffffffff || + vget_lane_u32(r1, 1) != 0xffffffff) + abort(); + + m1 = c.val[1] + 1; + uint32x2_t r2 = m1 == m2; + if (vget_lane_u32(r2, 0) != 0xffffffff || + vget_lane_u32(r2, 1) != 0xffffffff) + abort(); +} + + diff --git a/testsuite/c_test/driver_test/SANITY0040-neonintrinscs/expected.txt b/testsuite/c_test/driver_test/SANITY0040-neonintrinscs/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/testsuite/c_test/driver_test/SANITY0040-neonintrinscs/test.cfg b/testsuite/c_test/driver_test/SANITY0040-neonintrinscs/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..82b4ea6b82bddd5c9a14056462739edf21f87c60 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0040-neonintrinscs/test.cfg @@ -0,0 +1,2 @@ +compile(APP=test12.c,OPTION="--no-maple-phase -I${MAPLE_BUILD_OUTPUT}/lib/include -o test12") +run(test12) diff --git a/testsuite/c_test/driver_test/SANITY0040-neonintrinscs/test12.c b/testsuite/c_test/driver_test/SANITY0040-neonintrinscs/test12.c new file mode 100644 index 0000000000000000000000000000000000000000..d3e945572ed03878ede650a40b80c59c8c142786 --- /dev/null +++ b/testsuite/c_test/driver_test/SANITY0040-neonintrinscs/test12.c @@ -0,0 +1,75 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ +#include "arm_neon.h" +#include + +/* Testing calling convention of 64x1 */ + +uint64x1_t foo1( uint64x1_t x, uint64x1_t y ) +{ + return x + y; +} + +int64x1_t G = { 40 }; +int64x1_t foo2() { + return G; +} + +int64x1_t foo3( int64x1_t x ) +{ + return x; +} + +typedef struct S { + int x; + int64x1_t y; +} SS; + +int main() +{ + uint64x1_t a = { 10 }; + uint64x1_t b = { 20 }; + + uint64x1_t r1 = foo1( a, b ); + if ((uint64_t)r1 != 30) + abort(); + + int64x1_t r2 = foo3( foo2() ); + if ((int64_t)r2 != 40) + abort(); + + SS s1 = { 1, 50 }; + int64x1_t r3 = foo3( s1.y ); + if ((int64_t)r3 != 50) + abort(); + + SS s2 = { 1, 50 }; + SS *ps = &s2; + int64x1_t r4 = foo3( ps->y ); + if ((int64_t)r4 != 50) + abort(); + + int64x1_t c = { 60 }; + int64x1_t *p = &c; + int64x1_t **q = &p; + int64x1_t r5 = foo3( **q ); + if ((int64_t)r5 != 60) + abort(); + + int64x1_t (*fp)(int64x1_t) = foo3; + uint64x1_t r6 = (uint64x1_t)foo3( fp(c) ); + if ((int64_t)r6 != 60) + abort(); +} diff --git a/testsuite/c_test/driver_test/issue-AST0061-NEON-Mpl/Mpl.c b/testsuite/c_test/driver_test/issue-AST0061-NEON-Mpl/Mpl.c new file mode 100644 index 0000000000000000000000000000000000000000..d1bbc881fbbb06e49181e30fb0ca366007031492 --- /dev/null +++ b/testsuite/c_test/driver_test/issue-AST0061-NEON-Mpl/Mpl.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include "stdio.h" +#include + +// void print_float64x1(float64x1_t *a, int n) { +// float64_t *p = (float64_t *)a; +// int i; +// for (i = 0; i < n; i++) { +// printf("%f ", *(p+i)); +// } +// printf("\n"); +// } + +// int main() { +// float64x1_t A = {2.2}, B = {4.4}; +// float64x1_t C; +// C = __builtin_mpl_vector_merge_v1f64(A, B, 0); +// print_float64x1(&C,1); + +// return 0; +// } + +// int main() { +// int64x1_t A = {2}; +// int64_t B; +// B = __builtin_mpl_vector_get_element_v1i64(A, 0); +// printf("%d", B); + +// return 0; +// } + +void print_int64x1(int64x1_t *a, int n) { + int64_t *p = (int64_t *)a; + int i; + for (i = 0; i < n; i++) { + printf("%d ", *(p+i)); + } + printf("\n"); +} + +int main() { + int64x1_t A = {2}; + A = __builtin_mpl_vector_set_element_v1i64(9, A, 0); + print_int64x1(&A, 1); + + return 0; +} + diff --git a/testsuite/c_test/driver_test/issue-AST0061-NEON-Mpl/expected.txt b/testsuite/c_test/driver_test/issue-AST0061-NEON-Mpl/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..ec635144f60048986bc560c5576355344005e6e7 --- /dev/null +++ b/testsuite/c_test/driver_test/issue-AST0061-NEON-Mpl/expected.txt @@ -0,0 +1 @@ +9 diff --git a/testsuite/c_test/driver_test/issue-AST0061-NEON-Mpl/test.cfg b/testsuite/c_test/driver_test/issue-AST0061-NEON-Mpl/test.cfg new file mode 100644 index 0000000000000000000000000000000000000000..142e86cf47233c1dfda928ac19c7635e77aeddaf --- /dev/null +++ b/testsuite/c_test/driver_test/issue-AST0061-NEON-Mpl/test.cfg @@ -0,0 +1,2 @@ +compile(APP=Mpl.c,OPTION="--no-maple-phase -o Mpl") +run(Mpl) diff --git a/testsuite/driver/src/mode/DRIVER.py b/testsuite/driver/src/mode/DRIVER.py index 0743434509b1d88c394f778a42367b8e905ce627..324d98eba1bc53d2aa9f66ab033cdf8afb61b0d7 100644 --- a/testsuite/driver/src/mode/DRIVER.py +++ b/testsuite/driver/src/mode/DRIVER.py @@ -24,7 +24,7 @@ DRIVER = { ], "run": [ Shell( - "${OUT_ROOT}/tools/bin/qemu-aarch64 -L ${OUT_ROOT}/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc ${APP}.out > output.log 2>&1" + "${OUT_ROOT}/tools/bin/qemu-aarch64 -L ${OUT_ROOT}/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc ${APP} > output.log 2>&1" ), CheckFileEqual( file1="output.log",