1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
From bf537e82d452ee9b79f438df721c2e0dfaae12a0 Mon Sep 17 00:00:00 2001
From: Xiong Zhou <xiongzhou4@huawei.com>
Date: Fri, 5 May 2023 11:57:40 +0800
Subject: [PATCH 1/2] - bogus -Wstringop-overflow with VLA of elements larger
than byte
---
gcc/calls.c | 5 ++
gcc/testsuite/gcc.dg/Wstringop-overflow-67.c | 92 ++++++++++++++++++++
2 files changed, 97 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/Wstringop-overflow-67.c
diff --git a/gcc/calls.c b/gcc/calls.c
index 26894342c..45c137cee 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -2112,6 +2112,11 @@ maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp)
}
else
{
+ /* If the size cannot be determined clear it to keep it from
+ being taken as real (and excessive). */
+ if (objsize && integer_all_onesp (objsize))
+ objsize = NULL_TREE;
+
/* For read-only and read-write attributes also set the source
size. */
srcsize = objsize;
diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-67.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-67.c
new file mode 100644
index 000000000..7b8f3f014
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-67.c
@@ -0,0 +1,92 @@
+/* PR middle-end/100571 - bogus -Wstringop-overflow with VLA of elements
+ larger than byte
+ { dg-do compile }
+ { dg-options "-O2 -Wall" } */
+
+__attribute__ ((access (read_only, 1, 2))) void fro (int *, int);
+__attribute__ ((access (write_only, 1, 2))) void fwo (int *, int);
+__attribute__ ((access (read_write, 1, 2))) void frw (int *, int);
+
+extern __SIZE_TYPE__ n;
+
+void alloca_ro (void)
+{
+ int *a = __builtin_alloca (n * sizeof *a);
+ a[0] = 0;
+ fro (a, n);
+}
+
+void alloca_wo (void)
+{
+ int *a = __builtin_alloca (n * sizeof *a);
+ fwo (a, n);
+}
+
+void alloca_rw (void)
+{
+ int *a = __builtin_alloca (n * sizeof *a);
+ a[0] = 0;
+ frw (a, n);
+}
+
+
+void calloc_ro (void)
+{
+ int *a = __builtin_calloc (n, sizeof *a);
+ fro (a, n);
+}
+
+void calloc_wo (void)
+{
+ int *a = __builtin_calloc (n, sizeof *a);
+ fwo (a, n);
+}
+
+void calloc_rw (void)
+{
+ int *a = __builtin_calloc (n, sizeof *a);
+ a[0] = 0;
+ frw (a, n);
+}
+
+
+void malloc_ro (void)
+{
+ int *a = __builtin_malloc (n * sizeof *a);
+ a[0] = 0;
+ fro (a, n);
+}
+
+void malloc_wo (void)
+{
+ int *a = __builtin_malloc (n * sizeof *a);
+ fwo (a, n);
+}
+
+void malloc_rw (void)
+{
+ int *a = __builtin_malloc (n * sizeof *a);
+ a[0] = 0;
+ frw (a, n);
+}
+
+
+void vla_ro (void)
+{
+ int a[n];
+ a[0] = 0;
+ fro (a, n);
+}
+
+void vla_wo (void)
+{
+ int a[n];
+ fwo (a, n);
+}
+
+void vla_rw (void)
+{
+ int a[n];
+ a[0] = 0;
+ frw (a, n);
+}
--
2.33.0
|