All of lore.kernel.org
 help / color / mirror / Atom feed
* [styhead][PATCH] Backport: Fix c++: tweak for Wrange-loop-construct
@ 2024-12-11 17:22 sunilkumar.dora
  2024-12-11 20:11 ` Randy MacLeod
  0 siblings, 1 reply; 2+ messages in thread
From: sunilkumar.dora @ 2024-12-11 17:22 UTC (permalink / raw)
  To: openembedded-core; +Cc: Randy.MacLeod, Naveen.Gowda, Sundeep.Kokkonda

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:6ac4e2f4b2ca9980670e7d3815a9140730df1005]

Signed-off-by: Marek Polacek <polacek@redhat.com>
Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
---
 meta/recipes-devtools/gcc/gcc-14.2.inc        |   1 +
 ...ix-c-tweak-for-Wrange-loop-construct.patch | 114 ++++++++++++++++++
 2 files changed, 115 insertions(+)
 create mode 100644 meta/recipes-devtools/gcc/gcc/0026-Backport-Fix-c-tweak-for-Wrange-loop-construct.patch

diff --git a/meta/recipes-devtools/gcc/gcc-14.2.inc b/meta/recipes-devtools/gcc/gcc-14.2.inc
index e90b5b4c2a..1378cfc1c3 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} \
            file://0023-Fix-install-path-of-linux64.h.patch \
            file://0024-Avoid-hardcoded-build-paths-into-ppc-libgcc.patch \
            file://0025-gcc-testsuite-tweaks-for-mips-OE.patch \
+	   file://0026-Backport-Fix-c-tweak-for-Wrange-loop-construct.patch \
            file://gcc.git-ab884fffe3fc82a710bea66ad651720d71c938b8.patch \
 "
 
diff --git a/meta/recipes-devtools/gcc/gcc/0026-Backport-Fix-c-tweak-for-Wrange-loop-construct.patch b/meta/recipes-devtools/gcc/gcc/0026-Backport-Fix-c-tweak-for-Wrange-loop-construct.patch
new file mode 100644
index 0000000000..0a2db4e36a
--- /dev/null
+++ b/meta/recipes-devtools/gcc/gcc/0026-Backport-Fix-c-tweak-for-Wrange-loop-construct.patch
@@ -0,0 +1,114 @@
+From acc5e13c2ea91d2a138c03cd9e5d8826a1a74e4d Mon Sep 17 00:00:00 2001
+From: Sunil Dora <sunilkumar.dora@windriver.com>
+Date: Wed, 11 Dec 2024 00:09:43 -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:6ac4e2f4b2ca9980670e7d3815a9140730df1005]
+
+Signed-off-by: Marek Polacek <polacek@redhat.com>
+Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
+---
+ gcc/cp/parser.cc                              |  8 ++-
+ .../g++.dg/warn/Wrange-loop-construct3.C      | 57 +++++++++++++++++++
+ 2 files changed, 62 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 7e81c1010..8206489a2 100644
+--- a/gcc/cp/parser.cc
++++ b/gcc/cp/parser.cc
+@@ -14301,11 +14301,13 @@ 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 vec = make_tree_vec (1);
++  TREE_VEC_ELT (vec, 0) = 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, vec)))
+     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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [styhead][PATCH] Backport: Fix c++: tweak for Wrange-loop-construct
  2024-12-11 17:22 [styhead][PATCH] Backport: Fix c++: tweak for Wrange-loop-construct sunilkumar.dora
@ 2024-12-11 20:11 ` Randy MacLeod
  0 siblings, 0 replies; 2+ messages in thread
From: Randy MacLeod @ 2024-12-11 20:11 UTC (permalink / raw)
  To: sunilkumar.dora, openembedded-core, steve@sakoman.com
  Cc: Naveen.Gowda, Sundeep.Kokkonda

[-- Attachment #1: Type: text/plain, Size: 2164 bytes --]

Steve,
Ignore this one, a v2 has been submitted.

Sunil,

Please follow-up on your own patches like this to help people know that
they should ignore a patch that you have sent. Steve has 10s of emails 
or more
to deal with so clear instructions are helpful.

For future commit revisions, please also indicate that the patch is v2, 
v3 again,
so that anyone reading your thread can follow along. Some people even thread
follow-ups to the initial commit using --in-reply-to=<identifier> but 
that's not required.

You can use:
    git send-email ... --subject-prefix="branch-foo][PATCH v2"
See:
https://lore.kernel.org/openembedded-core/?q=v2
and:
https://docs.yoctoproject.org/contributor-guide/submit-changes.html#sending-patches-via-email

Thanks,

../Randy


On 2024-12-11 12:22 p.m., sunilkumar.dora@windriver.com 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:6ac4e2f4b2ca9980670e7d3815a9140730df1005]
>
> Signed-off-by: Marek Polacek<polacek@redhat.com>
> Signed-off-by: Sunil Dora<sunilkumar.dora@windriver.com>
> ---
>   meta/recipes-devtools/gcc/gcc-14.2.inc        |   1 +
>   ...ix-c-tweak-for-Wrange-loop-construct.patch | 114 ++++++++++++++++++
>   2 files changed, 115 insertions(+)
>   create mode 100644 meta/recipes-devtools/gcc/gcc/0026-Backport-Fix-c-tweak-for-Wrange-loop-construct.patch
>
> diff --git a/meta/recipes-devtools/gcc/gcc-14.2.inc b/meta/recipes-devtools/gcc/gcc-14.2.inc
> ...


-- 
# Randy MacLeod
# Wind River Linux

[-- Attachment #2: Type: text/html, Size: 4286 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-12-11 20:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-11 17:22 [styhead][PATCH] Backport: Fix c++: tweak for Wrange-loop-construct sunilkumar.dora
2024-12-11 20:11 ` Randy MacLeod

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.