| 1 |
# Process this file with autom4te to create testsuite. -*- Autotest -*- |
| 2 |
# Copyright (C) 2005-2025 Sergey Poznyakoff |
| 3 |
# |
| 4 |
# This program is free software; you can redistribute it and/or |
| 5 |
# modify it under the terms of the GNU General Public License as |
| 6 |
# published by the Free Software Foundation; either version 3, or (at |
| 7 |
# your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, but |
| 10 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
# General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
AT_BANNER([struct]) |
| 18 |
|
| 19 |
CFLOW_TEST([struct definition followed by attribute], |
| 20 |
[struct struct-attr attribute], |
| 21 |
[struct bar { |
| 22 |
struct foo *dummy; |
| 23 |
} __attribute__((aligned(8))); |
| 24 |
|
| 25 |
int |
| 26 |
main(int argc, char **argv) |
| 27 |
{ |
| 28 |
} |
| 29 |
], |
| 30 |
[main() <int main (int argc, char **argv) at prog:6> |
| 31 |
]) |
| 32 |
|
| 33 |
CFLOW_OPT([--symbol __attribute__:wrapper],[ |
| 34 |
CFLOW_TEST([struct definition followed by wrapper], |
| 35 |
[struct struct01 struct-wrapper wrapper], |
| 36 |
[struct bar { |
| 37 |
struct foo *dummy; |
| 38 |
} __attribute__((aligned(8))); |
| 39 |
|
| 40 |
int |
| 41 |
main(int argc, char **argv) |
| 42 |
{ |
| 43 |
} |
| 44 |
], |
| 45 |
[main() <int main (int argc, char **argv) at prog:6> |
| 46 |
]) |
| 47 |
]) |
| 48 |
|
| 49 |
CFLOW_TEST([ANSI C function returning a struct], |
| 50 |
[struct struct02 ret-struct], |
| 51 |
[struct s * |
| 52 |
foo(int arg) |
| 53 |
{ |
| 54 |
bar(); |
| 55 |
} |
| 56 |
int |
| 57 |
main(int argc, char **argv) |
| 58 |
{ |
| 59 |
foo(); |
| 60 |
} |
| 61 |
], |
| 62 |
[main() <int main (int argc, char **argv) at prog:7>: |
| 63 |
foo() <struct s *foo (int arg) at prog:2>: |
| 64 |
bar() |
| 65 |
]) |
| 66 |
|
| 67 |
CFLOW_TEST([K&R C function returning a struct], |
| 68 |
[struct struct03 ret-struct], |
| 69 |
[struct s * |
| 70 |
foo(arg) |
| 71 |
int arg; |
| 72 |
{ |
| 73 |
bar(); |
| 74 |
} |
| 75 |
int |
| 76 |
main(argc, argv) |
| 77 |
int argc; |
| 78 |
char **argv; |
| 79 |
{ |
| 80 |
foo(); |
| 81 |
} |
| 82 |
], |
| 83 |
[main() <int main (argc, argv) at prog:8>: |
| 84 |
foo() <struct s *foo (arg) at prog:2>: |
| 85 |
bar() |
| 86 |
]) |
| 87 |
|
| 88 |
CFLOW_OPT([-m foo],[ |
| 89 |
CFLOW_TEST([struct as argument], |
| 90 |
[struct struct04 arg-struct], |
| 91 |
[int |
| 92 |
foo(struct bar *x) |
| 93 |
{ |
| 94 |
} |
| 95 |
], |
| 96 |
[foo() <int foo (struct bar *x) at prog:2> |
| 97 |
]) |
| 98 |
]) |
| 99 |
|
| 100 |
CFLOW_OPT([-x -ix],[ |
| 101 |
CFLOW_TEST([struct variable], |
| 102 |
[struct struct05 var-struct], |
| 103 |
[struct { int x; int y; } point; |
| 104 |
], |
| 105 |
[point * prog:1 struct { ... } point |
| 106 |
]) |
| 107 |
]) |
| 108 |
|
| 109 |
CFLOW_OPT([-x -ix],[ |
| 110 |
CFLOW_TEST([array of structs], |
| 111 |
[struct struct06 arr-struct], |
| 112 |
[[struct X { |
| 113 |
char *name; |
| 114 |
} X[] = { |
| 115 |
{ "foo" }, |
| 116 |
}; |
| 117 |
]], |
| 118 |
[[X * prog:3 struct X { char *name } X[] |
| 119 |
]]) |
| 120 |
]) |
| 121 |
|
| 122 |
CFLOW_TEST([union in typedefs], |
| 123 |
[struct struct07 union typedef], |
| 124 |
[int foo(int status) |
| 125 |
{ |
| 126 |
/* |
| 127 |
* The following construct is a simplified expansion of the |
| 128 |
* WTERMSIG macro from glibc. |
| 129 |
*/ |
| 130 |
int x = (((((union { unisgned __in; int __i; }) { .__in = (status) }).__i)) & 0x7f); |
| 131 |
}], |
| 132 |
[foo() <int foo (int status) at prog:1> |
| 133 |
]) |