diff options
| -rw-r--r-- | meta/recipes-devtools/gcc/gcc-13.3.inc | 1 | ||||
| -rw-r--r-- | meta/recipes-devtools/gcc/gcc/0028-gcc-Fix-c-tweak-for-Wrange-loop-construct.patch | 113 |
2 files changed, 114 insertions, 0 deletions
diff --git a/meta/recipes-devtools/gcc/gcc-13.3.inc b/meta/recipes-devtools/gcc/gcc-13.3.inc index ffe90c7188..8b6c2a5938 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} \ | |||
| 66 | file://0024-Avoid-hardcoded-build-paths-into-ppc-libgcc.patch \ | 66 | file://0024-Avoid-hardcoded-build-paths-into-ppc-libgcc.patch \ |
| 67 | file://0025-gcc-testsuite-tweaks-for-mips-OE.patch \ | 67 | file://0025-gcc-testsuite-tweaks-for-mips-OE.patch \ |
| 68 | file://0027-Fix-gcc-vect-module-testcases.patch \ | 68 | file://0027-Fix-gcc-vect-module-testcases.patch \ |
| 69 | file://0028-gcc-Fix-c-tweak-for-Wrange-loop-construct.patch \ | ||
| 69 | file://gcc.git-ab884fffe3fc82a710bea66ad651720d71c938b8.patch \ | 70 | file://gcc.git-ab884fffe3fc82a710bea66ad651720d71c938b8.patch \ |
| 70 | " | 71 | " |
| 71 | SRC_URI[sha256sum] = "0845e9621c9543a13f484e94584a49ffc0129970e9914624235fc1d061a0c083" | 72 | SRC_URI[sha256sum] = "0845e9621c9543a13f484e94584a49ffc0129970e9914624235fc1d061a0c083" |
diff --git a/meta/recipes-devtools/gcc/gcc/0028-gcc-Fix-c-tweak-for-Wrange-loop-construct.patch b/meta/recipes-devtools/gcc/gcc/0028-gcc-Fix-c-tweak-for-Wrange-loop-construct.patch new file mode 100644 index 0000000000..745b38f7f1 --- /dev/null +++ b/meta/recipes-devtools/gcc/gcc/0028-gcc-Fix-c-tweak-for-Wrange-loop-construct.patch | |||
| @@ -0,0 +1,113 @@ | |||
| 1 | From 66aa69e2add2b8641a652768b0eac30f00427145 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Sunil Dora <sunilkumar.dora@windriver.com> | ||
| 3 | Date: Wed, 11 Dec 2024 09:48:16 -0800 | ||
| 4 | Subject: [PATCH] gcc: Fix c++: tweak for Wrange-loop-construct | ||
| 5 | |||
| 6 | This 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 | ||
| 8 | to types that can be copied trivially, whereas "trivially constructible" is the correct check | ||
| 9 | for types that can be trivially default-constructed. | ||
| 10 | |||
| 11 | This change ensures the warning is more accurate and aligns with the proper type traits. | ||
| 12 | |||
| 13 | LLVM accepted a similar fix: | ||
| 14 | https://github.com/llvm/llvm-project/issues/47355 | ||
| 15 | |||
| 16 | PR c++/116731 [https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116731] | ||
| 17 | |||
| 18 | Upstream-Status: Backport [https://gcc.gnu.org/g:179dc0f0fe01012675c1b430591b9891ce96c26e] | ||
| 19 | |||
| 20 | Signed-off-by: Marek Polacek <polacek@redhat.com> | ||
| 21 | Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com> | ||
| 22 | --- | ||
| 23 | gcc/cp/parser.cc | 7 ++- | ||
| 24 | .../g++.dg/warn/Wrange-loop-construct3.C | 57 +++++++++++++++++++ | ||
| 25 | 2 files changed, 61 insertions(+), 3 deletions(-) | ||
| 26 | create mode 100644 gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C | ||
| 27 | |||
| 28 | diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc | ||
| 29 | index 4e67da6ff..5dd94357d 100644 | ||
| 30 | --- a/gcc/cp/parser.cc | ||
| 31 | +++ b/gcc/cp/parser.cc | ||
| 32 | @@ -13854,11 +13854,12 @@ 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 list = build_tree_list (NULL_TREE, TREE_TYPE (expr)); | ||
| 41 | if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST | ||
| 42 | || (tree_to_uhwi (TYPE_SIZE_UNIT (type)) <= 64 | ||
| 43 | - && trivially_copyable_p (type))) | ||
| 44 | + && is_trivially_xible (INIT_EXPR, type, list))) | ||
| 45 | return; | ||
| 46 | |||
| 47 | /* If we can initialize a reference directly, suggest that to avoid the | ||
| 48 | diff --git a/gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C b/gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C | ||
| 49 | new file mode 100644 | ||
| 50 | index 000000000..3d9d0c908 | ||
| 51 | --- /dev/null | ||
| 52 | +++ b/gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C | ||
| 53 | @@ -0,0 +1,57 @@ | ||
| 54 | +// PR c++/116731 | ||
| 55 | +// { dg-do compile { target c++11 } } | ||
| 56 | +// { dg-options "-Wrange-loop-construct" } | ||
| 57 | + | ||
| 58 | +void | ||
| 59 | +f0 () | ||
| 60 | +{ | ||
| 61 | + struct S { | ||
| 62 | + char a[64]; | ||
| 63 | + S& operator=(const S&) { return *this; }; | ||
| 64 | + }; | ||
| 65 | + | ||
| 66 | + S arr[8]; | ||
| 67 | + for (const auto r : arr) | ||
| 68 | + (void) r; | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | +void | ||
| 72 | +f1 () | ||
| 73 | +{ | ||
| 74 | + struct S { | ||
| 75 | + char a[65]; | ||
| 76 | + S& operator=(const S&) { return *this; }; | ||
| 77 | + }; | ||
| 78 | + | ||
| 79 | + S arr[8]; | ||
| 80 | + for (const auto r : arr) // { dg-warning "creates a copy" } | ||
| 81 | + (void) r; | ||
| 82 | +} | ||
| 83 | + | ||
| 84 | +void | ||
| 85 | +f2 () | ||
| 86 | +{ | ||
| 87 | + struct S { | ||
| 88 | + char a[64]; | ||
| 89 | + S& operator=(const S&) { return *this; }; | ||
| 90 | + ~S() { } | ||
| 91 | + }; | ||
| 92 | + | ||
| 93 | + S arr[8]; | ||
| 94 | + for (const auto r : arr) // { dg-warning "creates a copy" } | ||
| 95 | + (void) r; | ||
| 96 | +} | ||
| 97 | + | ||
| 98 | +void | ||
| 99 | +f3 () | ||
| 100 | +{ | ||
| 101 | + struct S { | ||
| 102 | + char a[65]; | ||
| 103 | + S& operator=(const S&) { return *this; }; | ||
| 104 | + ~S() { } | ||
| 105 | + }; | ||
| 106 | + | ||
| 107 | + S arr[8]; | ||
| 108 | + for (const auto r : arr) // { dg-warning "creates a copy" } | ||
| 109 | + (void) r; | ||
| 110 | +} | ||
| 111 | -- | ||
| 112 | 2.43.0 | ||
| 113 | |||
