summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/recipes-devtools/gcc/gcc-14.2.inc1
-rw-r--r--meta/recipes-devtools/gcc/gcc/0026-gcc-Fix-c-tweak-for-Wrange-loop-construct.patch114
2 files changed, 115 insertions, 0 deletions
diff --git a/meta/recipes-devtools/gcc/gcc-14.2.inc b/meta/recipes-devtools/gcc/gcc-14.2.inc
index e90b5b4c2a..932a27995b 100644
--- a/meta/recipes-devtools/gcc/gcc-14.2.inc
+++ b/meta/recipes-devtools/gcc/gcc-14.2.inc
@@ -68,6 +68,7 @@ SRC_URI = "${BASEURI} \
68 file://0023-Fix-install-path-of-linux64.h.patch \ 68 file://0023-Fix-install-path-of-linux64.h.patch \
69 file://0024-Avoid-hardcoded-build-paths-into-ppc-libgcc.patch \ 69 file://0024-Avoid-hardcoded-build-paths-into-ppc-libgcc.patch \
70 file://0025-gcc-testsuite-tweaks-for-mips-OE.patch \ 70 file://0025-gcc-testsuite-tweaks-for-mips-OE.patch \
71 file://0026-gcc-Fix-c-tweak-for-Wrange-loop-construct.patch \
71 file://gcc.git-ab884fffe3fc82a710bea66ad651720d71c938b8.patch \ 72 file://gcc.git-ab884fffe3fc82a710bea66ad651720d71c938b8.patch \
72" 73"
73 74
diff --git a/meta/recipes-devtools/gcc/gcc/0026-gcc-Fix-c-tweak-for-Wrange-loop-construct.patch b/meta/recipes-devtools/gcc/gcc/0026-gcc-Fix-c-tweak-for-Wrange-loop-construct.patch
new file mode 100644
index 0000000000..c9bc863eea
--- /dev/null
+++ b/meta/recipes-devtools/gcc/gcc/0026-gcc-Fix-c-tweak-for-Wrange-loop-construct.patch
@@ -0,0 +1,114 @@
1From 05106fea707f010779369c5d6e89787953d2976f Mon Sep 17 00:00:00 2001
2From: Sunil Dora <sunilkumar.dora@windriver.com>
3Date: Wed, 11 Dec 2024 10:04:56 -0800
4Subject: [PATCH] gcc: Fix c++: tweak for Wrange-loop-construct
5
6This commit updates the warning to use a check for "trivially constructible" instead of
7"trivially copyable." The original check was incorrect, as "trivially copyable" only applies
8to types that can be copied trivially, whereas "trivially constructible" is the correct check
9for types that can be trivially default-constructed.
10
11This change ensures the warning is more accurate and aligns with the proper type traits.
12
13LLVM accepted a similar fix:
14https://github.com/llvm/llvm-project/issues/47355
15
16PR c++/116731 [https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116731]
17
18Upstream-Status: Backport [https://gcc.gnu.org/g:6ac4e2f4b2ca9980670e7d3815a9140730df1005]
19
20Signed-off-by: Marek Polacek <polacek@redhat.com>
21Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
22---
23 gcc/cp/parser.cc | 8 ++-
24 .../g++.dg/warn/Wrange-loop-construct3.C | 57 +++++++++++++++++++
25 2 files changed, 62 insertions(+), 3 deletions(-)
26 create mode 100644 gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C
27
28diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
29index 7e81c1010..8206489a2 100644
30--- a/gcc/cp/parser.cc
31+++ b/gcc/cp/parser.cc
32@@ -14301,11 +14301,13 @@ warn_for_range_copy (tree decl, tree expr)
33 else if (!CP_TYPE_CONST_P (type))
34 return;
35
36- /* Since small trivially copyable types are cheap to copy, we suppress the
37- warning for them. 64B is a common size of a cache line. */
38+ /* Since small trivially constructible types are cheap to construct, we
39+ suppress the warning for them. 64B is a common size of a cache line. */
40+ tree vec = make_tree_vec (1);
41+ TREE_VEC_ELT (vec, 0) = TREE_TYPE (expr);
42 if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST
43 || (tree_to_uhwi (TYPE_SIZE_UNIT (type)) <= 64
44- && trivially_copyable_p (type)))
45+ && is_trivially_xible (INIT_EXPR, type, vec)))
46 return;
47
48 /* If we can initialize a reference directly, suggest that to avoid the
49diff --git a/gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C b/gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C
50new file mode 100644
51index 000000000..3d9d0c908
52--- /dev/null
53+++ b/gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C
54@@ -0,0 +1,57 @@
55+// PR c++/116731
56+// { dg-do compile { target c++11 } }
57+// { dg-options "-Wrange-loop-construct" }
58+
59+void
60+f0 ()
61+{
62+ struct S {
63+ char a[64];
64+ S& operator=(const S&) { return *this; };
65+ };
66+
67+ S arr[8];
68+ for (const auto r : arr)
69+ (void) r;
70+}
71+
72+void
73+f1 ()
74+{
75+ struct S {
76+ char a[65];
77+ S& operator=(const S&) { return *this; };
78+ };
79+
80+ S arr[8];
81+ for (const auto r : arr) // { dg-warning "creates a copy" }
82+ (void) r;
83+}
84+
85+void
86+f2 ()
87+{
88+ struct S {
89+ char a[64];
90+ S& operator=(const S&) { return *this; };
91+ ~S() { }
92+ };
93+
94+ S arr[8];
95+ for (const auto r : arr) // { dg-warning "creates a copy" }
96+ (void) r;
97+}
98+
99+void
100+f3 ()
101+{
102+ struct S {
103+ char a[65];
104+ S& operator=(const S&) { return *this; };
105+ ~S() { }
106+ };
107+
108+ S arr[8];
109+ for (const auto r : arr) // { dg-warning "creates a copy" }
110+ (void) r;
111+}
112--
1132.43.0
114