Message ID | 20241211171420.3859335-1-sunilkumar.dora@windriver.com |
---|---|
State | Superseded |
Delegated to: | Steve Sakoman |
Headers | show |
Series | [scarthgap] Backport: Fix c++: tweak for Wrange-loop-construct | expand |
the commit summary should start with gcc: not backport:. And the Upstream-Status belongs to .patch it's not necessary do duplicate that in oe-core commit message. On Wed, Dec 11, 2024 at 6:14 PM SunilKumar.Dora via lists.openembedded.org <SunilKumar.Dora=windriver.com@lists.openembedded.org> wrote: > > From: Sunil Dora <sunilkumar.dora@windriver.com> > > This commit updates the warning to use a check for "trivially constructible" instead of > "trivially copyable." The original check was incorrect, as "trivially copyable" only applies > to types that can be copied trivially, whereas "trivially constructible" is the correct check > for types that can be trivially default-constructed. > > This change ensures the warning is more accurate and aligns with the proper type traits. > > LLVM accepted a similar fix: > https://github.com/llvm/llvm-project/issues/47355 > > PR c++/116731 [https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116731] > > Upstream-Status: Backport [https://gcc.gnu.org/g:179dc0f0fe01012675c1b430591b9891ce96c26e] > > Signed-off-by: Marek Polacek <polacek@redhat.com> > Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com> > --- > meta/recipes-devtools/gcc/gcc-13.3.inc | 1 + > ...ix-c-tweak-for-Wrange-loop-construct.patch | 113 ++++++++++++++++++ > 2 files changed, 114 insertions(+) > create mode 100644 meta/recipes-devtools/gcc/gcc/0028-Backport-Fix-c-tweak-for-Wrange-loop-construct.patch > > diff --git a/meta/recipes-devtools/gcc/gcc-13.3.inc b/meta/recipes-devtools/gcc/gcc-13.3.inc > index ffe90c7188..65477a29bc 100644 > --- a/meta/recipes-devtools/gcc/gcc-13.3.inc > +++ b/meta/recipes-devtools/gcc/gcc-13.3.inc > @@ -66,6 +66,7 @@ SRC_URI = "${BASEURI} \ > file://0024-Avoid-hardcoded-build-paths-into-ppc-libgcc.patch \ > file://0025-gcc-testsuite-tweaks-for-mips-OE.patch \ > file://0027-Fix-gcc-vect-module-testcases.patch \ > + file://0028-Backport-Fix-c-tweak-for-Wrange-loop-construct.patch \ > file://gcc.git-ab884fffe3fc82a710bea66ad651720d71c938b8.patch \ > " > SRC_URI[sha256sum] = "0845e9621c9543a13f484e94584a49ffc0129970e9914624235fc1d061a0c083" > diff --git a/meta/recipes-devtools/gcc/gcc/0028-Backport-Fix-c-tweak-for-Wrange-loop-construct.patch b/meta/recipes-devtools/gcc/gcc/0028-Backport-Fix-c-tweak-for-Wrange-loop-construct.patch > new file mode 100644 > index 0000000000..406578eebf > --- /dev/null > +++ b/meta/recipes-devtools/gcc/gcc/0028-Backport-Fix-c-tweak-for-Wrange-loop-construct.patch > @@ -0,0 +1,113 @@ > +From 096ff216265bb114b28a5b717d0139f37d03c322 Mon Sep 17 00:00:00 2001 > +From: Sunil Dora <sunilkumar.dora@windriver.com> > +Date: Wed, 11 Dec 2024 00:53:31 -0800 > +Subject: [PATCH] Backport: Fix c++: tweak for Wrange-loop-construct > + > +This commit updates the warning to use a check for "trivially constructible" instead of > +"trivially copyable." The original check was incorrect, as "trivially copyable" only applies > +to types that can be copied trivially, whereas "trivially constructible" is the correct check > +for types that can be trivially default-constructed. > + > +This change ensures the warning is more accurate and aligns with the proper type traits. > + > +LLVM accepted a similar fix: > +https://github.com/llvm/llvm-project/issues/47355 > + > +PR c++/116731 [https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116731] > + > +Upstream-Status: Backport [https://gcc.gnu.org/g:179dc0f0fe01012675c1b430591b9891ce96c26e] > + > +Signed-off-by: Marek Polacek <polacek@redhat.com> > +Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com> > +--- > + gcc/cp/parser.cc | 7 ++- > + .../g++.dg/warn/Wrange-loop-construct3.C | 57 +++++++++++++++++++ > + 2 files changed, 61 insertions(+), 3 deletions(-) > + create mode 100644 gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C > + > +diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc > +index 4e67da6ff..5dd94357d 100644 > +--- a/gcc/cp/parser.cc > ++++ b/gcc/cp/parser.cc > +@@ -13854,11 +13854,12 @@ warn_for_range_copy (tree decl, tree expr) > + else if (!CP_TYPE_CONST_P (type)) > + return; > + > +- /* Since small trivially copyable types are cheap to copy, we suppress the > +- warning for them. 64B is a common size of a cache line. */ > ++ /* Since small trivially constructible types are cheap to construct, we > ++ suppress the warning for them. 64B is a common size of a cache line. */ > ++ tree list = build_tree_list (NULL_TREE, TREE_TYPE (expr)); > + if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST > + || (tree_to_uhwi (TYPE_SIZE_UNIT (type)) <= 64 > +- && trivially_copyable_p (type))) > ++ && is_trivially_xible (INIT_EXPR, type, list))) > + return; > + > + /* If we can initialize a reference directly, suggest that to avoid the > +diff --git a/gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C b/gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C > +new file mode 100644 > +index 000000000..3d9d0c908 > +--- /dev/null > ++++ b/gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C > +@@ -0,0 +1,57 @@ > ++// PR c++/116731 > ++// { dg-do compile { target c++11 } } > ++// { dg-options "-Wrange-loop-construct" } > ++ > ++void > ++f0 () > ++{ > ++ struct S { > ++ char a[64]; > ++ S& operator=(const S&) { return *this; }; > ++ }; > ++ > ++ S arr[8]; > ++ for (const auto r : arr) > ++ (void) r; > ++} > ++ > ++void > ++f1 () > ++{ > ++ struct S { > ++ char a[65]; > ++ S& operator=(const S&) { return *this; }; > ++ }; > ++ > ++ S arr[8]; > ++ for (const auto r : arr) // { dg-warning "creates a copy" } > ++ (void) r; > ++} > ++ > ++void > ++f2 () > ++{ > ++ struct S { > ++ char a[64]; > ++ S& operator=(const S&) { return *this; }; > ++ ~S() { } > ++ }; > ++ > ++ S arr[8]; > ++ for (const auto r : arr) // { dg-warning "creates a copy" } > ++ (void) r; > ++} > ++ > ++void > ++f3 () > ++{ > ++ struct S { > ++ char a[65]; > ++ S& operator=(const S&) { return *this; }; > ++ ~S() { } > ++ }; > ++ > ++ S arr[8]; > ++ for (const auto r : arr) // { dg-warning "creates a copy" } > ++ (void) r; > ++} > +-- > +2.43.0 > + > -- > 2.43.0 > > > -=-=-=-=-=-=-=-=-=-=-=- > Links: You receive all messages sent to this group. > View/Reply Online (#208596): https://lists.openembedded.org/g/openembedded-core/message/208596 > Mute This Topic: https://lists.openembedded.org/mt/110065245/3617156 > Group Owner: openembedded-core+owner@lists.openembedded.org > Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [martin.jansa@gmail.com] > -=-=-=-=-=-=-=-=-=-=-=- >
diff --git a/meta/recipes-devtools/gcc/gcc-13.3.inc b/meta/recipes-devtools/gcc/gcc-13.3.inc index ffe90c7188..65477a29bc 100644 --- a/meta/recipes-devtools/gcc/gcc-13.3.inc +++ b/meta/recipes-devtools/gcc/gcc-13.3.inc @@ -66,6 +66,7 @@ SRC_URI = "${BASEURI} \ file://0024-Avoid-hardcoded-build-paths-into-ppc-libgcc.patch \ file://0025-gcc-testsuite-tweaks-for-mips-OE.patch \ file://0027-Fix-gcc-vect-module-testcases.patch \ + file://0028-Backport-Fix-c-tweak-for-Wrange-loop-construct.patch \ file://gcc.git-ab884fffe3fc82a710bea66ad651720d71c938b8.patch \ " SRC_URI[sha256sum] = "0845e9621c9543a13f484e94584a49ffc0129970e9914624235fc1d061a0c083" diff --git a/meta/recipes-devtools/gcc/gcc/0028-Backport-Fix-c-tweak-for-Wrange-loop-construct.patch b/meta/recipes-devtools/gcc/gcc/0028-Backport-Fix-c-tweak-for-Wrange-loop-construct.patch new file mode 100644 index 0000000000..406578eebf --- /dev/null +++ b/meta/recipes-devtools/gcc/gcc/0028-Backport-Fix-c-tweak-for-Wrange-loop-construct.patch @@ -0,0 +1,113 @@ +From 096ff216265bb114b28a5b717d0139f37d03c322 Mon Sep 17 00:00:00 2001 +From: Sunil Dora <sunilkumar.dora@windriver.com> +Date: Wed, 11 Dec 2024 00:53:31 -0800 +Subject: [PATCH] Backport: Fix c++: tweak for Wrange-loop-construct + +This commit updates the warning to use a check for "trivially constructible" instead of +"trivially copyable." The original check was incorrect, as "trivially copyable" only applies +to types that can be copied trivially, whereas "trivially constructible" is the correct check +for types that can be trivially default-constructed. + +This change ensures the warning is more accurate and aligns with the proper type traits. + +LLVM accepted a similar fix: +https://github.com/llvm/llvm-project/issues/47355 + +PR c++/116731 [https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116731] + +Upstream-Status: Backport [https://gcc.gnu.org/g:179dc0f0fe01012675c1b430591b9891ce96c26e] + +Signed-off-by: Marek Polacek <polacek@redhat.com> +Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com> +--- + gcc/cp/parser.cc | 7 ++- + .../g++.dg/warn/Wrange-loop-construct3.C | 57 +++++++++++++++++++ + 2 files changed, 61 insertions(+), 3 deletions(-) + create mode 100644 gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C + +diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc +index 4e67da6ff..5dd94357d 100644 +--- a/gcc/cp/parser.cc ++++ b/gcc/cp/parser.cc +@@ -13854,11 +13854,12 @@ warn_for_range_copy (tree decl, tree expr) + else if (!CP_TYPE_CONST_P (type)) + return; + +- /* Since small trivially copyable types are cheap to copy, we suppress the +- warning for them. 64B is a common size of a cache line. */ ++ /* Since small trivially constructible types are cheap to construct, we ++ suppress the warning for them. 64B is a common size of a cache line. */ ++ tree list = build_tree_list (NULL_TREE, TREE_TYPE (expr)); + if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST + || (tree_to_uhwi (TYPE_SIZE_UNIT (type)) <= 64 +- && trivially_copyable_p (type))) ++ && is_trivially_xible (INIT_EXPR, type, list))) + return; + + /* If we can initialize a reference directly, suggest that to avoid the +diff --git a/gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C b/gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C +new file mode 100644 +index 000000000..3d9d0c908 +--- /dev/null ++++ b/gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C +@@ -0,0 +1,57 @@ ++// PR c++/116731 ++// { dg-do compile { target c++11 } } ++// { dg-options "-Wrange-loop-construct" } ++ ++void ++f0 () ++{ ++ struct S { ++ char a[64]; ++ S& operator=(const S&) { return *this; }; ++ }; ++ ++ S arr[8]; ++ for (const auto r : arr) ++ (void) r; ++} ++ ++void ++f1 () ++{ ++ struct S { ++ char a[65]; ++ S& operator=(const S&) { return *this; }; ++ }; ++ ++ S arr[8]; ++ for (const auto r : arr) // { dg-warning "creates a copy" } ++ (void) r; ++} ++ ++void ++f2 () ++{ ++ struct S { ++ char a[64]; ++ S& operator=(const S&) { return *this; }; ++ ~S() { } ++ }; ++ ++ S arr[8]; ++ for (const auto r : arr) // { dg-warning "creates a copy" } ++ (void) r; ++} ++ ++void ++f3 () ++{ ++ struct S { ++ char a[65]; ++ S& operator=(const S&) { return *this; }; ++ ~S() { } ++ }; ++ ++ S arr[8]; ++ for (const auto r : arr) // { dg-warning "creates a copy" } ++ (void) r; ++} +-- +2.43.0 +