Skip to content

Commit 42a1bbd

Browse files
committed
tests/examples/find-global-state: don't report const arrays
1 parent 2f208bb commit 42a1bbd

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

tests/examples/find-global-state/input.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<http://www.gnu.org/licenses/>.
1818
*/
1919

20+
#include <stdio.h>
21+
2022
static int a_global;
2123

2224
struct {
@@ -39,3 +41,9 @@ int test2(int j)
3941
i += j;
4042
return j * i;
4143
}
44+
45+
int test3(int k)
46+
{
47+
/* We should *not* report about __FUNCTION__ here: */
48+
printf("%s:%i:%s\n", __FILE__, __LINE__, __FUNCTION__);
49+
}

tests/examples/find-global-state/script.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,19 @@
2121
def on_pass_execution(p, fn):
2222
if p.name == '*free_lang_data':
2323
for var in gcc.get_variables():
24+
type_ = var.decl.type
25+
26+
# Don't bother warning about an array of const e.g.
27+
# const char []
28+
if isinstance(type_, gcc.ArrayType):
29+
item_type = type_.dereference
30+
if hasattr(item_type, 'const'):
31+
if item_type.const:
32+
continue
33+
2434
gcc.inform(var.decl.location,
2535
'global state "%s %s" defined here'
26-
% (var.decl.type, var.decl))
36+
% (type_, var.decl))
2737

2838
gcc.register_callback(gcc.PLUGIN_PASS_EXECUTION,
2939
on_pass_execution)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
tests/examples/find-global-state/input.c:38:14: note: global state "int i" defined here
2-
tests/examples/find-global-state/input.c:24:3: note: global state "struct
1+
tests/examples/find-global-state/input.c:40:14: note: global state "int i" defined here
2+
tests/examples/find-global-state/input.c:26:3: note: global state "struct
33
{
44
int i;
55
} bar" defined here
6-
tests/examples/find-global-state/input.c:20:12: note: global state "int a_global" defined here
6+
tests/examples/find-global-state/input.c:22:12: note: global state "int a_global" defined here

0 commit comments

Comments
 (0)