[gcc/devel/omp/gcc-14] OpenACC 2.7: update _OPENACC symbol to 201811
https://gcc.gnu.org/g:28244925ed45fc74f0c0b01a646456d9538d commit 28244925ed45fc74f0c0b01a646456d9538d Author: Chung-Lin Tang Date: Fri Apr 11 08:46:12 2025 + OpenACC 2.7: update _OPENACC symbol to 201811 This patch updates the _OPENACC preprocessor symbol to "201811", to indicate OpenACC 2.7 support. 2025-04-11 Chung-Lin Tang gcc/c-family/ChangeLog: * c-cppbuiltin.cc (c_cpp_builtins): Updated _OPENACC to "201811" for OpenACC 2.7. gcc/fortran/ChangeLog: * cpp.cc (cpp_define_builtins): Updated _OPENACC to "201811" for OpenACC 2.7. Diff: --- gcc/c-family/c-cppbuiltin.cc | 2 +- gcc/fortran/cpp.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc index 79e4abd01520..24a8b94b36ae 100644 --- a/gcc/c-family/c-cppbuiltin.cc +++ b/gcc/c-family/c-cppbuiltin.cc @@ -1620,7 +1620,7 @@ c_cpp_builtins (cpp_reader *pfile) cpp_define (pfile, "__SSP__=1"); if (flag_openacc) -cpp_define (pfile, "_OPENACC=201711"); +cpp_define (pfile, "_OPENACC=201811"); if (flag_openmp) cpp_define (pfile, "_OPENMP=201511"); diff --git a/gcc/fortran/cpp.cc b/gcc/fortran/cpp.cc index 3a6dbdc2003c..fdb588f22316 100644 --- a/gcc/fortran/cpp.cc +++ b/gcc/fortran/cpp.cc @@ -170,7 +170,7 @@ cpp_define_builtins (cpp_reader *pfile) cpp_define (pfile, "_LANGUAGE_FORTRAN=1"); if (flag_openacc) -cpp_define (pfile, "_OPENACC=201711"); +cpp_define (pfile, "_OPENACC=201811"); if (flag_openmp) cpp_define (pfile, "_OPENMP=201511");
[gcc r15-9378] libstdc++: Add P1206R7 from_range members to std::string [PR111055]
https://gcc.gnu.org/g:882d3b319dbf50ae64080731a1398031c100b7c7 commit r15-9378-g882d3b319dbf50ae64080731a1398031c100b7c7 Author: Jonathan Wakely Date: Thu Apr 10 13:40:53 2025 +0100 libstdc++: Add P1206R7 from_range members to std::string [PR111055] This is the last piece of P1206R7, adding new members to std::basic_string. libstdc++-v3/ChangeLog: PR libstdc++/111055 * include/bits/basic_string.h (_S_copy_range): New function. (basic_string(from_range_t, R%%, const Alloc&)): New constructor. (append_range, assign_range, insert_range, replace_with_range): New functions. * include/bits/cow_string.h: Likewise. * testsuite/21_strings/basic_string/cons/from_range.cc: New test. * testsuite/21_strings/basic_string/modifiers/append/append_range.cc: New test. * testsuite/21_strings/basic_string/modifiers/assign/assign_range.cc: New test. * testsuite/21_strings/basic_string/modifiers/insert/insert_range.cc: New test. * testsuite/21_strings/basic_string/modifiers/replace/replace_with_range.cc: New test. Co-authored-by: Tomasz Kamiński Diff: --- libstdc++-v3/include/bits/basic_string.h | 182 + libstdc++-v3/include/bits/cow_string.h | 115 + .../21_strings/basic_string/cons/from_range.cc | 124 ++ .../basic_string/modifiers/append/append_range.cc | 125 ++ .../basic_string/modifiers/assign/assign_range.cc | 116 + .../basic_string/modifiers/insert/insert_range.cc | 130 +++ .../modifiers/replace/replace_with_range.cc| 133 +++ 7 files changed, 925 insertions(+) diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 886e7e6b19ec..7670bace4793 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -51,6 +51,11 @@ # include #endif +#if __glibcxx_ranges_to_container // C++ >= 23 +# include // ranges::copy +# include // ranges::subrange +#endif + #if __cplusplus > 202302L # include #endif @@ -501,6 +506,21 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 _GLIBCXX_NOEXCEPT { _S_copy(__p, __k1, __k2 - __k1); } +#if __glibcxx_ranges_to_container // C++ >= 23 + // pre: __n == ranges::distance(__rg). __p+[0,__n) is a valid range. + template + static constexpr void + _S_copy_range(pointer __p, _Rg&& __rg, size_type __n) + { + if constexpr (ranges::contiguous_range<_Rg> + && is_same_v, _CharT>) + _S_copy(__p, ranges::data(std::forward<_Rg>(__rg)), __n); + else + for (auto&& __e : __rg) + traits_type::assign(*__p++, std::forward(__e)); + } +#endif + _GLIBCXX20_CONSTEXPR static int _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT @@ -717,6 +737,33 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 __str._M_set_length(0); } +#if __glibcxx_ranges_to_container // C++ >= 23 + /** + * @brief Construct a string from a range. + * @since C++23 + */ + template<__detail::__container_compatible_range<_CharT> _Rg> + constexpr + basic_string(from_range_t, _Rg&& __rg, const _Alloc& __a = _Alloc()) + : basic_string(__a) + { + if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>) + { + const auto __n = static_cast(ranges::distance(__rg)); + reserve(__n); + _S_copy_range(_M_data(), std::forward<_Rg>(__rg), __n); + _M_set_length(__n); + } + else + { + auto __first = ranges::begin(__rg); + const auto __last = ranges::end(__rg); + for (; __first != __last; ++__first) + push_back(*__first); + } + } +#endif + /** * @brief Construct string from an initializer %list. * @param __l std::initializer_list of characters. @@ -1526,6 +1573,58 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 append(size_type __n, _CharT __c) { return _M_replace_aux(this->size(), size_type(0), __n, __c); } +#if __glibcxx_ranges_to_container // C++ >= 23 + /** + * @brief Append a range to the string. + * @param __rg A range of values that are convertible to `value_type`. + * @since C++23 + * + * The range `__rg` is allowed to overlap with `*this`. + */ + template<__detail::__container_compatible_range<_CharT> _Rg> + constexpr basic_string& + append_range(_Rg&& __rg) + { + // N.B. __rg may overlap with *this, so we must copy from __rg before + // existing elements or iterators referring to *this are invalidated. +
[gcc/devel/omp/gcc-14] OpenACC 2.7: update _OPENACC value test in testcases
https://gcc.gnu.org/g:b05827d5665cff4cdaccfdd063a8d615eb561dc8 commit b05827d5665cff4cdaccfdd063a8d615eb561dc8 Author: Chung-Lin Tang Date: Fri Apr 11 10:36:22 2025 + OpenACC 2.7: update _OPENACC value test in testcases Adjust value test of _OPENACC to 201811 for OpenACC 2.7 update. 2025-04-11 Chung-Lin Tang gcc/testsuite/ChangeLog: * c-c++-common/cpp/openacc-define-3.c: Adjust test. * gfortran.dg/openacc-define-3.f90: Adjust test. Diff: --- gcc/testsuite/c-c++-common/cpp/openacc-define-3.c | 2 +- gcc/testsuite/gfortran.dg/openacc-define-3.f90| 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/c-c++-common/cpp/openacc-define-3.c b/gcc/testsuite/c-c++-common/cpp/openacc-define-3.c index f2122f57dd9d..51f0c6902a7c 100644 --- a/gcc/testsuite/c-c++-common/cpp/openacc-define-3.c +++ b/gcc/testsuite/c-c++-common/cpp/openacc-define-3.c @@ -6,6 +6,6 @@ # error _OPENACC not defined #endif -#if _OPENACC != 201711 +#if _OPENACC != 201811 # error _OPENACC defined to wrong value #endif diff --git a/gcc/testsuite/gfortran.dg/openacc-define-3.f90 b/gcc/testsuite/gfortran.dg/openacc-define-3.f90 index dcc52b6b4cb5..1a229f82ebba 100644 --- a/gcc/testsuite/gfortran.dg/openacc-define-3.f90 +++ b/gcc/testsuite/gfortran.dg/openacc-define-3.f90 @@ -6,6 +6,6 @@ # error _OPENACC not defined #endif -#if _OPENACC != 201711 +#if _OPENACC != 201811 # error _OPENACC defined to wrong value #endif
[gcc r15-9379] d: Merge upstream dmd 1b34fea478, phobos 40ffbb364
https://gcc.gnu.org/g:b905ce8caf04253e02e153d60d6ea8f99d300af6 commit r15-9379-gb905ce8caf04253e02e153d60d6ea8f99d300af6 Author: Iain Buclaw Date: Fri Apr 11 12:39:23 2025 +0200 d: Merge upstream dmd 1b34fea478, phobos 40ffbb364 D front-end changes: - Import latest fixes from dmd v2.111.1-rc.1. Phobos changes: - Import latest fixes from phobos v2.111.1-rc.1. - Restore compatibility with older Linux platforms where `getrandom' is unavailable. gcc/d/ChangeLog: * dmd/MERGE: Merge upstream dmd 1b34fea478. libphobos/ChangeLog: * src/MERGE: Merge upstream phobos 40ffbb364. * Makefile.in: Regenerate. * configure: Regenerate. * configure.ac: Call DRUNTIME_OS_FEATURES. * libdruntime/Makefile.am (AM_DFLAGS): Add OS_DFLAGS. * libdruntime/Makefile.in: Regenerate. * m4/druntime/os.m4 (DRUNTIME_OS_FEATURES): Define. * src/Makefile.am: Add OS_DFLAGS. * src/Makefile.in: Regenerate. * testsuite/Makefile.in: Regenerate. * testsuite/testsuite_flags.in: Add OS_DFLAGS. Diff: --- gcc/d/dmd/MERGE| 2 +- gcc/d/dmd/globals.h| 1 + gcc/d/dmd/lexer.d | 4 +- gcc/d/dmd/location.d | 23 +--- gcc/d/dmd/typesem.d| 16 +- gcc/testsuite/gdc.test/compilable/test21179.d | 11 .../gdc.test/fail_compilation/fail_pretty_errors.d | 18 +++--- libphobos/Makefile.in | 1 + libphobos/configure| 53 - libphobos/configure.ac | 1 + libphobos/libdruntime/Makefile.am | 3 +- libphobos/libdruntime/Makefile.in | 4 +- libphobos/m4/druntime/os.m4| 27 + libphobos/src/MERGE| 2 +- libphobos/src/Makefile.am | 3 +- libphobos/src/Makefile.in | 4 +- libphobos/src/std/format/write.d | 11 +++- libphobos/src/std/random.d | 66 ++ libphobos/testsuite/Makefile.in| 1 + libphobos/testsuite/testsuite_flags.in | 2 +- 20 files changed, 210 insertions(+), 43 deletions(-) diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index a05a50eefb8d..ee5eb853284b 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -51816cd01deee5cc1d7d2c6e1e24788ec655b73e +1b34fea4788136b54ec77c6ed9678754d109fc79 The first line of this file holds the git revision number of the last merge done from the dlang/dmd repository. diff --git a/gcc/d/dmd/globals.h b/gcc/d/dmd/globals.h index 59952a2c1053..62a575e322e3 100644 --- a/gcc/d/dmd/globals.h +++ b/gcc/d/dmd/globals.h @@ -421,6 +421,7 @@ struct SourceLoc uint32_t line; uint32_t column; uint32_t fileOffset; +DString fileContent; }; struct Loc diff --git a/gcc/d/dmd/lexer.d b/gcc/d/dmd/lexer.d index 63313ac2eddf..ed9f7f1ce775 100644 --- a/gcc/d/dmd/lexer.d +++ b/gcc/d/dmd/lexer.d @@ -132,7 +132,7 @@ class Lexer // debug printf("Lexer::Lexer(%p)\n", base); // debug printf("lexer.filename = %s\n", filename); token = Token.init; -this.baseLoc = newBaseLoc(filename, endoffset); +this.baseLoc = newBaseLoc(filename, base[0 .. endoffset]); this.linnum = 1; this.base = base; this.end = base + endoffset; @@ -224,7 +224,7 @@ class Lexer inTokenStringConstant = 0; lastDocLine = 0; -baseLoc = newBaseLoc("#defines", slice.length); +baseLoc = newBaseLoc("#defines", slice); scanloc = baseLoc.getLoc(0); } diff --git a/gcc/d/dmd/location.d b/gcc/d/dmd/location.d index 54b3fb6e0aed..393ffb8a92d4 100644 --- a/gcc/d/dmd/location.d +++ b/gcc/d/dmd/location.d @@ -64,7 +64,7 @@ nothrow: extern (C++) static Loc singleFilename(const char* filename) { Loc result; -locFileTable ~= new BaseLoc(filename.toDString, locIndex, 0, [0]); +locFileTable ~= new BaseLoc(filename.toDString, null, locIndex, 0, [0]); result.index = locIndex++; return result; } @@ -235,16 +235,20 @@ struct SourceLoc uint column; /// column number (starts at 1) uint fileOffset; /// byte index into file +/// Index `fileOffset` into this to to obtain source code context of this location +const(char)[] fileContent; + // aliases for backwards compatibility alias linnum = line; alias charnum = column; -this(const(char)[] filename, uint line, uint column, uint fileOffset = 0) nothrow @nogc pure @safe +this(const(char)[] filename, uint line, uint column, uint fil
[gcc r13-9505] middle-end/115110 - Fix view_converted_memref_p
https://gcc.gnu.org/g:97fa1ba84849a940c55eaecc2d7798d2582d39e4 commit r13-9505-g97fa1ba84849a940c55eaecc2d7798d2582d39e4 Author: Richard Biener Date: Fri May 17 11:02:29 2024 +0200 middle-end/115110 - Fix view_converted_memref_p view_converted_memref_p was checking the reference type against the pointer type of the offset operand rather than its pointed-to type which leads to all refs being subject to view-convert treatment in get_alias_set causing numerous testsuite fails but with its new uses from r15-512-g9b7cad5884f21c is also a wrong-code issue. PR middle-end/115110 * tree-ssa-alias.cc (view_converted_memref_p): Fix. (cherry picked from commit a5b3721c06646bf5b9b50a22964e8e2bd4d03f5f) Diff: --- gcc/tree-ssa-alias.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc index f2dc1563ae93..dcb65648ec04 100644 --- a/gcc/tree-ssa-alias.cc +++ b/gcc/tree-ssa-alias.cc @@ -2045,8 +2045,9 @@ view_converted_memref_p (tree base) { if (TREE_CODE (base) != MEM_REF && TREE_CODE (base) != TARGET_MEM_REF) return false; - return same_type_for_tbaa (TREE_TYPE (base), -TREE_TYPE (TREE_OPERAND (base, 1))) != 1; + return (same_type_for_tbaa (TREE_TYPE (base), + TREE_TYPE (TREE_TYPE (TREE_OPERAND (base, 1 + != 1); } /* Return true if an indirect reference based on *PTR1 constrained
[gcc r13-9509] tree-optimization/112859 - add comment
https://gcc.gnu.org/g:0f86e86a869a7defefa63469a1c411ab4bb36c25 commit r13-9509-g0f86e86a869a7defefa63469a1c411ab4bb36c25 Author: Richard Biener Date: Tue Jan 28 15:01:25 2025 +0100 tree-optimization/112859 - add comment This adds a comment before the workaround, indicating flaky dependence analysis. PR tree-optimization/112859 * tree-loop-distribution.cc (loop_distribution::pg_add_dependence_edges): Add comment. (cherry picked from commit 3ccbc8c9d182c380e396631b2b5a683de4fddba9) Diff: --- gcc/tree-loop-distribution.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc index 66474c495d59..3beffaf92c5d 100644 --- a/gcc/tree-loop-distribution.cc +++ b/gcc/tree-loop-distribution.cc @@ -2178,7 +2178,9 @@ loop_distribution::pg_add_dependence_edges (struct graph *rdg, int dir, this_dir = -this_dir; } /* When then dependence distance of the innermost common -loop of the DRs is zero we have a conflict. */ +loop of the DRs is zero we have a conflict. This is +due to wonky dependence analysis which sometimes +ends up using a zero distance in place of unknown. */ auto l1 = gimple_bb (DR_STMT (dr1))->loop_father; auto l2 = gimple_bb (DR_STMT (dr2))->loop_father; int idx = index_in_loop_nest (find_common_loop (l1, l2)->num,
[gcc r13-9508] tree-optimization/112859 - bogus loop distribution
https://gcc.gnu.org/g:330a02b893eed85f10c85ab3974ec913616672e8 commit r13-9508-g330a02b893eed85f10c85ab3974ec913616672e8 Author: Richard Biener Date: Thu Jan 23 13:10:17 2025 +0100 tree-optimization/112859 - bogus loop distribution When we get a zero distance vector we still have to check for the situation of a common inner loop with zero distance. But we can still allow a zero distance for the loop we distribute (gcc.dg/tree-ssa/ldist-33.c is such a case). This is because zero distances in non-outermost loops are a misrepresentation of dependence by dependence analysis. Note that test coverage of loop distribution of loop nests is very low. PR tree-optimization/112859 PR tree-optimization/115347 * tree-loop-distribution.cc (loop_distribution::pg_add_dependence_edges): For a zero distance vector still make sure to not have an inner loop with zero distance. * gcc.dg/torture/pr112859.c: New testcase. * gcc.dg/torture/pr115347.c: Likewise. (cherry picked from commit 04ba1300407f106a6dd10d346f58a51d87e6d43e) Diff: --- gcc/testsuite/gcc.dg/torture/pr112859.c | 24 gcc/testsuite/gcc.dg/torture/pr115347.c | 21 + gcc/tree-loop-distribution.cc | 27 --- 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr112859.c b/gcc/testsuite/gcc.dg/torture/pr112859.c new file mode 100644 index ..18f5bf40cb70 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr112859.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-additional-options "-ftree-loop-distribution" } */ + +struct a { + char b; + int c; +} f, *i = &f; +static struct a e[4]; +int *d, **g = &d; +static int h, j; +int main() +{ + for (; h < 1; h++) { +struct a k = {1, 1}; +for (j = 0; j < 2; j++) { + *i = e[h]; + e[h] = k; +} +*g = 0; + } + if (f.c != 1) +__builtin_abort(); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr115347.c b/gcc/testsuite/gcc.dg/torture/pr115347.c new file mode 100644 index ..2299495144b9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr115347.c @@ -0,0 +1,21 @@ +/* { dg-do run } */ +/* { dg-additional-options "-ftree-loop-distribution" } */ + +struct a { + int b; + int c; +} d, e[2]; +int f, g, h; +int main() +{ + for (; f < 1; f++) { +for (h = 0; h < 2; h++) { + d = e[f]; + g = e[1].c; + e[f].c = 1; +} + } + if (d.c != 1) +__builtin_abort(); + return 0; +} diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc index 601ab3d0fb2e..66474c495d59 100644 --- a/gcc/tree-loop-distribution.cc +++ b/gcc/tree-loop-distribution.cc @@ -2163,25 +2163,30 @@ loop_distribution::pg_add_dependence_edges (struct graph *rdg, int dir, gcc.dg/tree-ssa/pr94969.c. */ if (DDR_NUM_DIST_VECTS (ddr) != 1) this_dir = 2; - /* If the overlap is exact preserve stmt order. */ - else if (lambda_vector_zerop (DDR_DIST_VECT (ddr, 0), - DDR_NB_LOOPS (ddr))) - ; - /* Else as the distance vector is lexicographic positive swap -the dependence direction. */ else { - if (DDR_REVERSED_P (ddr)) - this_dir = -this_dir; - this_dir = -this_dir; - + /* If the overlap is exact preserve stmt order. */ + if (lambda_vector_zerop (DDR_DIST_VECT (ddr, 0), + DDR_NB_LOOPS (ddr))) + ; + /* Else as the distance vector is lexicographic positive swap +the dependence direction. */ + else + { + if (DDR_REVERSED_P (ddr)) + this_dir = -this_dir; + this_dir = -this_dir; + } /* When then dependence distance of the innermost common loop of the DRs is zero we have a conflict. */ auto l1 = gimple_bb (DR_STMT (dr1))->loop_father; auto l2 = gimple_bb (DR_STMT (dr2))->loop_father; int idx = index_in_loop_nest (find_common_loop (l1, l2)->num, DDR_LOOP_NEST (ddr)); - if (DDR_DIST_VECT (ddr, 0)[idx] == 0) + if (DDR_DIST_VECT (ddr, 0)[idx] == 0 + /* Unless it is the outermost loop which is the one +we eventually distribute. */ + && idx != 0) this_dir = 2; } }
[gcc r13-9507] ipa/111245 - bogus modref analysis for store in call that might throw
https://gcc.gnu.org/g:fb17a8b24cbba558ae2108de2aada1ed5031162c commit r13-9507-gfb17a8b24cbba558ae2108de2aada1ed5031162c Author: Richard Biener Date: Fri Feb 28 11:44:26 2025 +0100 ipa/111245 - bogus modref analysis for store in call that might throw We currently record a kill for *x_4(D) = always_throws (); because we consider the store always executing since the appropriate check for whether the stmt could throw is guarded by !cfun->can_throw_non_call_exceptions. PR ipa/111245 * ipa-modref.cc (modref_access_analysis::analyze_store): Do not guard the check of whether the stmt could throw by cfun->can_throw_non_call_exceptions. * g++.dg/torture/pr111245.C: New testcase. (cherry picked from commit e6037af6d5e5a43c437257580d75bc8b35a6dcfd) Diff: --- gcc/ipa-modref.cc | 3 +-- gcc/testsuite/g++.dg/torture/pr111245.C | 23 +++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/gcc/ipa-modref.cc b/gcc/ipa-modref.cc index c98e38524dfb..d633c8331956 100644 --- a/gcc/ipa-modref.cc +++ b/gcc/ipa-modref.cc @@ -1745,8 +1745,7 @@ modref_access_analysis::analyze_store (gimple *stmt, tree, tree op, void *data) t->record_access_lto (t->m_summary_lto->stores, &r, a); if (t->m_always_executed && a.useful_for_kill_p () - && (!cfun->can_throw_non_call_exceptions - || !stmt_could_throw_p (cfun, stmt))) + && !stmt_could_throw_p (cfun, stmt)) { if (dump_file) fprintf (dump_file, " - Recording kill\n"); diff --git a/gcc/testsuite/g++.dg/torture/pr111245.C b/gcc/testsuite/g++.dg/torture/pr111245.C new file mode 100644 index ..785f4a51761d --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr111245.C @@ -0,0 +1,23 @@ +/* { dg-do run } */ + +struct Int { + int value; +}; + +__attribute__((noipa)) Int always_throws() { throw 123; } + +void foo(Int &x) { + try { +x = always_throws(); + } catch (...) { + } +} + +int main() +{ + Int x; + x.value = 5; + foo(x); + if (x.value != 5) +__builtin_abort (); +}
[gcc r13-9506] testsuite: add testcase for fixed PR107467
https://gcc.gnu.org/g:35aede5a6bc9b2cf7e7d019148debb6f227c6eb1 commit r13-9506-g35aede5a6bc9b2cf7e7d019148debb6f227c6eb1 Author: Sam James Date: Mon Oct 21 12:11:42 2024 +0100 testsuite: add testcase for fixed PR107467 PR107467 ended up being fixed by the fix for PR115110, but let's add the testcase on top. gcc/testsuite/ChangeLog: PR tree-optimization/107467 PR middle-end/115110 * g++.dg/lto/pr107467_0.C: New test. (cherry picked from commit 4e09ae37dbe0a10f48490214f50ff733cc92280a) Diff: --- gcc/testsuite/g++.dg/lto/pr107467_0.C | 52 +++ 1 file changed, 52 insertions(+) diff --git a/gcc/testsuite/g++.dg/lto/pr107467_0.C b/gcc/testsuite/g++.dg/lto/pr107467_0.C new file mode 100644 index ..a871aca82459 --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/pr107467_0.C @@ -0,0 +1,52 @@ +/* { dg-lto-do run } */ +/* { dg-lto-options {{ -O2 -fno-strict-aliasing -flto }} } */ + +template +struct pair +{ +int first; +T second; +}; + +template +[[gnu::optimize("strict-aliasing")]] +bool __attribute__((noinline)) +compare_pairs(const pair &lhs, const pair &rhs) { + return lhs.first == rhs.first && lhs.second == rhs.second; +} + +template struct Combined { + pair +__attribute__((noinline)) get_const() { +return pair{123, nullptr}; + } +[[gnu::optimize("strict-aliasing")]] + bool +__attribute__((noinline)) clashy() { +return compare_pairs(get_const(), get_const()); + } +}; + +class SomeClass {}; +class OtherClass {}; + +[[gnu::optimize("strict-aliasing")]] +[[gnu::used]] +void some_func() { + Combined myvar; + __builtin_printf("%i\n", myvar.clashy()); +} + +[[gnu::optimize("strict-aliasing")]] +void other_func() { + Combined myvar; + int t = myvar.clashy(); + if (!t) + __builtin_abort(); +} + +[[gnu::optimize("O0")]] +int main() +{ + other_func(); +}
[gcc r13-9511] tree-optimization/114052 - consider infinite sub-loops when lowering iter bound
https://gcc.gnu.org/g:2f37a08b51ef8022a2ef0b596006df65ceb44314 commit r13-9511-g2f37a08b51ef8022a2ef0b596006df65ceb44314 Author: Richard Biener Date: Wed Jan 29 13:25:14 2025 +0100 tree-optimization/114052 - consider infinite sub-loops when lowering iter bound When we walk stmts to find always executed stmts with UB in the last iteration to be able to reduce the iteration count by one we fail to consider infinite subloops in the last iteration that would make such stmt not execute. The following adds this. PR tree-optimization/114052 * tree-ssa-loop-niter.cc (maybe_lower_iteration_bound): Check for infinite subloops we might not exit. * gcc.dg/pr114052-1.c: New testcase. (cherry picked from commit d1c7837d2d6e5a2997228681166ed8c814891881) Diff: --- gcc/testsuite/gcc.dg/pr114052-1.c | 40 +++ gcc/tree-ssa-loop-niter.cc| 9 - 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/pr114052-1.c b/gcc/testsuite/gcc.dg/pr114052-1.c new file mode 100644 index ..e971f6844146 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr114052-1.c @@ -0,0 +1,40 @@ +/* { dg-do run } */ +/* { dg-require-effective-target signal } */ +/* { dg-options "-O2" } */ + +#include +#include +#include +#include + +volatile int y; +void __attribute__((noipa)) put(int x) +{ + if (y) +__builtin_printf ("%i\n", x); +} + +void __attribute__((noipa)) f(void) +{ + int counter = 0; + while (1) { + if (counter >= 2) continue; + put (counter++); + } +} + +void do_exit (int i) +{ + exit (0); +} + +int main() +{ + struct sigaction s; + sigemptyset (&s.sa_mask); + s.sa_handler = do_exit; + s.sa_flags = 0; + sigaction (SIGALRM, &s, NULL); + alarm (1); + f(); +} diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc index 878442bdeb45..4e6bd5176b6f 100644 --- a/gcc/tree-ssa-loop-niter.cc +++ b/gcc/tree-ssa-loop-niter.cc @@ -4680,7 +4680,14 @@ maybe_lower_iteration_bound (class loop *loop) FOR_EACH_EDGE (e, ei, bb->succs) { if (loop_exit_edge_p (loop, e) - || e == loop_latch_edge (loop)) + || e == loop_latch_edge (loop) + /* When exiting an inner loop, verify it is finite. */ + || (!flow_bb_inside_loop_p (bb->loop_father, e->dest) + && !finite_loop_p (bb->loop_father)) + /* When we enter an irreducible region and the entry +does not contain a bounding stmt assume it might be +infinite. */ + || (bb->flags & BB_IRREDUCIBLE_LOOP)) { found_exit = true; break;
[gcc r13-9512] lto/114501 - missed free-lang-data for CONSTRUCTOR index
https://gcc.gnu.org/g:4e49ae8d905d760e97d0c0310f40c7e3a0e4e9df commit r13-9512-g4e49ae8d905d760e97d0c0310f40c7e3a0e4e9df Author: Richard Biener Date: Thu Mar 6 13:48:16 2025 +0100 lto/114501 - missed free-lang-data for CONSTRUCTOR index The following makes sure to also walk CONSTRUCTOR element indexes which can be FIELD_DECLs, referencing otherwise unused types we need to clean. walk_tree only walks CONSTRUCTOR element data. PR lto/114501 * ipa-free-lang-data.cc (find_decls_types_r): Explicitly handle CONSTRUCTORs as walk_tree handling of those is incomplete. * g++.dg/pr114501_0.C: New testcase. (cherry picked from commit fdd95e1cf29137a19baed25f8c817d320dfe63e3) Diff: --- gcc/ipa-free-lang-data.cc | 14 ++ gcc/testsuite/g++.dg/pr114501_0.C | 20 2 files changed, 34 insertions(+) diff --git a/gcc/ipa-free-lang-data.cc b/gcc/ipa-free-lang-data.cc index b87063b5900d..b12cdb01e786 100644 --- a/gcc/ipa-free-lang-data.cc +++ b/gcc/ipa-free-lang-data.cc @@ -841,6 +841,20 @@ find_decls_types_r (tree *tp, int *ws, void *data) fld_worklist_push (tem, fld); fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t), fld); } + /* walk_tree does not visit ce->index which can be a FIELD_DECL, pulling + in otherwise unused structure fields so handle CTORs explicitly. */ + else if (TREE_CODE (t) == CONSTRUCTOR) +{ + unsigned HOST_WIDE_INT idx; + constructor_elt *ce; + for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce); idx++) + { + if (ce->index) + fld_worklist_push (ce->index, fld); + fld_worklist_push (ce->value, fld); + } + *ws = 0; +} if (TREE_CODE (t) != IDENTIFIER_NODE && CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_TYPED)) diff --git a/gcc/testsuite/g++.dg/pr114501_0.C b/gcc/testsuite/g++.dg/pr114501_0.C new file mode 100644 index ..0439ee5f6e23 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr114501_0.C @@ -0,0 +1,20 @@ +// { dg-do compile } +// { dg-require-effective-target c++17 } +// { dg-require-effective-target lto } +// { dg-options "-flto" } + +typedef long unsigned int size_t; +struct basic_string_view { + typedef long unsigned int size_type; + constexpr size_type size() const { return 0; } +}; +struct array { + char _M_elems[1]; +}; +inline constexpr auto make_it() { + constexpr basic_string_view view; + array arr{}; + arr._M_elems[view.size()] = 'a'; + return arr; +} +auto bar = make_it();
[gcc r13-9513] tree-optimization/116906 - unsafe PRE with never executed edges
https://gcc.gnu.org/g:9ade99bfbc7f47975d7f8765366904f4d2496afc commit r13-9513-g9ade99bfbc7f47975d7f8765366904f4d2496afc Author: Richard Biener Date: Tue Oct 1 10:37:16 2024 +0200 tree-optimization/116906 - unsafe PRE with never executed edges When we're computing ANTIC for PRE we treat edges to not yet visited blocks as having a maximum ANTIC solution to get at an optimistic solution in the iteration. That assumes the edges visted eventually execute. This is a wrong assumption that can lead to wrong code (and not only non-optimality) when possibly trapping expressions are involved as the testcases in the PR show. The following mitigates this by pruning trapping expressions from ANTIC computed when maximum sets are involved. PR tree-optimization/116906 * tree-ssa-pre.cc (prune_clobbered_mems): Add clean_traps argument. (compute_antic_aux): Direct prune_clobbered_mems to prune all traps when any MAX solution was involved in the ANTIC computation. (compute_partial_antic_aux): Adjust. * gcc.dg/pr116906-1.c: New testcase. * gcc.dg/pr116906-2.c: Likewise. (cherry picked from commit 3e1bd6470e4deba1a3ad14621037098311ad1350) Diff: --- gcc/testsuite/gcc.dg/pr116906-1.c | 43 +++ gcc/testsuite/gcc.dg/pr116906-2.c | 40 gcc/tree-ssa-pre.cc | 16 +-- 3 files changed, 93 insertions(+), 6 deletions(-) diff --git a/gcc/testsuite/gcc.dg/pr116906-1.c b/gcc/testsuite/gcc.dg/pr116906-1.c new file mode 100644 index ..27b1fdae02bf --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr116906-1.c @@ -0,0 +1,43 @@ +/* { dg-do run { target *-*-linux* *-*-gnu* *-*-uclinux* } } */ +/* { dg-options "-O2" } */ + +#include +#include +#include +#include + +int a = 1, b = 0; + +uint64_t safe_mod(uint64_t a, uint64_t b) +{ +if (b == 0) return a; +else return a % b; +} + +int __attribute__((noipa)) +f(uint64_t p) +{ +int c = 0; +j: +b = safe_mod( +(c = ((a &= (0 < p)) && 1), 1), p); +if (!c) +goto j; +return 0; +} + +void do_exit (int i) +{ + exit (0); +} + +int main() +{ + struct sigaction s; + sigemptyset (&s.sa_mask); + s.sa_handler = do_exit; + s.sa_flags = 0; + sigaction (SIGALRM, &s, NULL); + alarm (1); + f(b); +} diff --git a/gcc/testsuite/gcc.dg/pr116906-2.c b/gcc/testsuite/gcc.dg/pr116906-2.c new file mode 100644 index ..3478771678ce --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr116906-2.c @@ -0,0 +1,40 @@ +/* { dg-do run { target *-*-linux* *-*-gnu* *-*-uclinux* } } */ +/* { dg-options "-O2 -fno-tree-ch" } */ + +#include +#include +#include + +int x; + +void __attribute__((noipa)) +foo (int *p, unsigned n) +{ + unsigned i = 0; + do +{ + if (i == n) +break; + if (p) +x = *p; + i += 2; +} + while (1); + x = *p; +} + +void do_exit (int i) +{ + exit (0); +} + +int main() +{ + struct sigaction s; + sigemptyset (&s.sa_mask); + s.sa_handler = do_exit; + s.sa_flags = 0; + sigaction (SIGALRM, &s, NULL); + alarm (1); + foo ((int *)0, 1); +} diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc index b570e9e26f02..6289b96f5b0b 100644 --- a/gcc/tree-ssa-pre.cc +++ b/gcc/tree-ssa-pre.cc @@ -2008,10 +2008,11 @@ clean (bitmap_set_t set1, bitmap_set_t set2 = NULL) } /* Clean the set of expressions that are no longer valid in SET because - they are clobbered in BLOCK or because they trap and may not be executed. */ + they are clobbered in BLOCK or because they trap and may not be executed. + When CLEAN_TRAPS is true remove all possibly trapping expressions. */ static void -prune_clobbered_mems (bitmap_set_t set, basic_block block) +prune_clobbered_mems (bitmap_set_t set, basic_block block, bool clean_traps) { bitmap_iterator bi; unsigned i; @@ -2049,7 +2050,7 @@ prune_clobbered_mems (bitmap_set_t set, basic_block block) a possible exit point. ??? This is overly conservative if we translate AVAIL_OUT as the available expression might be after the exit point. */ - if (BB_MAY_NOTRETURN (block) + if ((BB_MAY_NOTRETURN (block) || clean_traps) && vn_reference_may_trap (ref)) to_remove = i; } @@ -2060,7 +2061,7 @@ prune_clobbered_mems (bitmap_set_t set, basic_block block) a possible exit point. ??? This is overly conservative if we translate AVAIL_OUT as the available expression might be after the exit point. */ - if (BB_MAY_NOTRETURN (block) + if ((BB_MAY_NOTRETURN (block) || clean_traps) && vn_nary_may_trap (nary)) to_remove = i; } @@ -2114,6 +2115,8 @@ compute_antic_aux (basic_block block, bool block_has_abnormal_pred_edge) bool was_visited = BB_VISITED
[gcc r13-9514] tree-optimization/117113 - ICE with unroll-and-jam
https://gcc.gnu.org/g:8ee6631540ca9d5c437ce4bf3236d6d6ae22c475 commit r13-9514-g8ee6631540ca9d5c437ce4bf3236d6d6ae22c475 Author: Richard Biener Date: Mon Feb 3 15:12:52 2025 +0100 tree-optimization/117113 - ICE with unroll-and-jam When there's an inner loop without virtual header PHI but the outer loop has one the fusion process cannot handle the need to create an inner loop virtual header PHI. Punt in this case. PR tree-optimization/117113 * gimple-loop-jam.cc (unroll_jam_possible_p): Detect when we cannot handle virtual SSA update. * gcc.dg/torture/pr117113.c: New testcase. (cherry picked from commit 0675eb17480bada678bf2769d39732027abcd6d0) Diff: --- gcc/gimple-loop-jam.cc | 12 +++- gcc/testsuite/gcc.dg/torture/pr117113.c | 20 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/gcc/gimple-loop-jam.cc b/gcc/gimple-loop-jam.cc index c6b2fc28d1c3..19aa4b68d073 100644 --- a/gcc/gimple-loop-jam.cc +++ b/gcc/gimple-loop-jam.cc @@ -279,13 +279,17 @@ unroll_jam_possible_p (class loop *outer, class loop *loop) body would be the after-iter value of the first body) if it's over an associative and commutative operation. We wouldn't be able to handle unknown cycles. */ + bool inner_vdef = false; for (psi = gsi_start_phis (loop->header); !gsi_end_p (psi); gsi_next (&psi)) { affine_iv iv; tree op = gimple_phi_result (psi.phi ()); if (virtual_operand_p (op)) - continue; + { + inner_vdef = true; + continue; + } if (!simple_iv (loop, loop, op, &iv, true)) return false; /* The inductions must be regular, loop invariant step and initial @@ -301,6 +305,12 @@ unroll_jam_possible_p (class loop *outer, class loop *loop) copy, _not_ the next value of the second body. */ } + /* When there's no inner loop virtual PHI IV we cannot handle the update + required to the inner loop if that doesn't already have one. See + PR117113. */ + if (!inner_vdef && get_virtual_phi (outer->header)) +return false; + return true; } diff --git a/gcc/testsuite/gcc.dg/torture/pr117113.c b/gcc/testsuite/gcc.dg/torture/pr117113.c new file mode 100644 index ..e90ad034a4d3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr117113.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fno-tree-dce -fno-inline" } */ + +int a, b, c; +volatile int d[1]; +void e() {} +void f(int g) {} +int main() { + int i; + for (; b; b--) { +for (i = 0; i < 3; i++) { + e(); + f(d[0]); + d[0]; +} +if (a) + c++; + } + return 0; +}
[gcc r13-9516] tree-optimization/119145 - avoid stray .MASK_CALL after vectorization
https://gcc.gnu.org/g:68b740f9e3112f7c0778bcb9dfd10b23cd1df1c0 commit r13-9516-g68b740f9e3112f7c0778bcb9dfd10b23cd1df1c0 Author: Richard Biener Date: Fri Mar 7 10:15:20 2025 +0100 tree-optimization/119145 - avoid stray .MASK_CALL after vectorization When we BB vectorize an if-converted loop body we make sure to not leave around .MASK_LOAD or .MASK_STORE created by if-conversion but we failed to check for .MASK_CALL. PR tree-optimization/119145 * tree-vectorizer.cc (try_vectorize_loop_1): Avoid BB vectorizing an if-converted loop body when there's a .MASK_CALL in the loop body. * gcc.dg/vect/pr119145.c: New testcase. (cherry picked from commit 7950d4cceb9fc7559b1343c95fc651cefbe287a0) Diff: --- gcc/testsuite/gcc.dg/vect/pr119145.c | 35 +++ gcc/tree-vectorizer.cc | 4 +++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/vect/pr119145.c b/gcc/testsuite/gcc.dg/vect/pr119145.c new file mode 100644 index ..55a84a603c49 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr119145.c @@ -0,0 +1,35 @@ +/* { dg-do compile } */ + +typedef short Quantum; +Quantum ComplexImages_Bi_0, ComplexImages_Ai_0, ComplexImages_Ai_1; +long ComplexImages_x; +__attribute__((__simd__)) double atan2(double, double); +typedef enum { MagickFalse } MagickBooleanType; + +struct { +MagickBooleanType matte; +} *ComplexImages_images; + +typedef struct { +Quantum blue, opacity; +} PixelPacket; + +typedef enum { MagnitudePhaseComplexOperator } ComplexOperator; +PixelPacket ComplexImages_Ar, ComplexImages_Br; +PixelPacket *ComplexImages_Ci; +ComplexOperator ComplexImages_op; + +void ComplexImages() +{ + for (; ComplexImages_x; ComplexImages_x++) +switch (ComplexImages_op) + { + case MagnitudePhaseComplexOperator: +if (ComplexImages_images->matte) + ComplexImages_Ci->opacity + = atan2(ComplexImages_Ai_1, ComplexImages_Ar.opacity); + ComplexImages_Ci->blue + = 1.0 / (ComplexImages_Ai_0 * ComplexImages_Br.blue + + ComplexImages_Ar.blue * ComplexImages_Bi_0); + } +} diff --git a/gcc/tree-vectorizer.cc b/gcc/tree-vectorizer.cc index 89cd0b88b611..33022217afb7 100644 --- a/gcc/tree-vectorizer.cc +++ b/gcc/tree-vectorizer.cc @@ -1103,7 +1103,9 @@ try_vectorize_loop_1 (hash_table *&simduid_to_vf_htab, if (call && gimple_call_internal_p (call)) { internal_fn ifn = gimple_call_internal_fn (call); - if (ifn == IFN_MASK_LOAD || ifn == IFN_MASK_STORE + if (ifn == IFN_MASK_LOAD + || ifn == IFN_MASK_STORE + || ifn == IFN_MASK_CALL /* Don't keep the if-converted parts when the ifn with specifc type is not supported by the backend. */ || (direct_internal_fn_p (ifn)
[gcc r13-9510] lto/113207 - fix free_lang_data_in_type
https://gcc.gnu.org/g:949f38047860b19a4276b8191d012a3b05aab1e2 commit r13-9510-g949f38047860b19a4276b8191d012a3b05aab1e2 Author: Richard Biener Date: Mon Feb 3 14:27:01 2025 +0100 lto/113207 - fix free_lang_data_in_type When we process function types we strip volatile and const qualifiers after building a simplified type variant (which preserves those). The qualified type handling of both isn't really compatible, so avoid bad interaction by swapping this, first dropping const/volatile qualifiers and then building the simplified type thereof. PR lto/113207 * ipa-free-lang-data.cc (free_lang_data_in_type): First drop const/volatile qualifiers from function argument types, then build a simplified type. * gcc.dg/pr113207.c: New testcase. (cherry picked from commit a55e14b239181381204c615335929b3316d75370) Diff: --- gcc/ipa-free-lang-data.cc | 3 +-- gcc/testsuite/gcc.dg/pr113207.c | 10 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gcc/ipa-free-lang-data.cc b/gcc/ipa-free-lang-data.cc index ff9657a6e068..b87063b5900d 100644 --- a/gcc/ipa-free-lang-data.cc +++ b/gcc/ipa-free-lang-data.cc @@ -436,9 +436,7 @@ free_lang_data_in_type (tree type, class free_lang_data_d *fld) different front ends. */ for (tree p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p)) { - TREE_VALUE (p) = fld_simplified_type (TREE_VALUE (p), fld); tree arg_type = TREE_VALUE (p); - if (TYPE_READONLY (arg_type) || TYPE_VOLATILE (arg_type)) { int quals = TYPE_QUALS (arg_type) @@ -448,6 +446,7 @@ free_lang_data_in_type (tree type, class free_lang_data_d *fld) if (!fld->pset.add (TREE_VALUE (p))) free_lang_data_in_type (TREE_VALUE (p), fld); } + TREE_VALUE (p) = fld_simplified_type (TREE_VALUE (p), fld); /* C++ FE uses TREE_PURPOSE to store initial values. */ TREE_PURPOSE (p) = NULL; } diff --git a/gcc/testsuite/gcc.dg/pr113207.c b/gcc/testsuite/gcc.dg/pr113207.c new file mode 100644 index ..81f53d8fcc2f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr113207.c @@ -0,0 +1,10 @@ +/* { dg-compile } */ +/* { dg-require-effective-target lto } */ +/* { dg-options "-flto -fchecking" } */ + +typedef struct cl_lispunion *cl_object; +struct cl_lispunion {}; +cl_object cl_error() __attribute__((noreturn)); +volatile cl_object cl_coerce_value0; +void cl_coerce() { cl_error(); } +void L66safe_canonical_type(cl_object volatile);
[gcc r13-9515] tree-optimization/117424 - invalid LIM of trapping ref
https://gcc.gnu.org/g:7b0936da8dbe30b1876bf89b9ae59f1b7fa87dc9 commit r13-9515-g7b0936da8dbe30b1876bf89b9ae59f1b7fa87dc9 Author: Richard Biener Date: Tue Jan 28 12:28:14 2025 +0100 tree-optimization/117424 - invalid LIM of trapping ref The following addresses a bug in tree_could_trap_p leading to hoisting of a possibly trapping, because of out-of-bound, access. We only ensured the first accessed byte is within a decl there, the patch makes sure the whole base of the reference is within it. This is pessimistic if a handled component would then subset to a sub-object within the decl but upcasting of a decl to larger types should be uncommon, questionable, and wrong without -fno-strict-aliasing. The testcase is a bit fragile, but I could not devise a (portable) way to ensure an out-of-bound access to a decl would fault. PR tree-optimization/117424 * tree-eh.cc (tree_could_trap_p): Verify the base is fully contained within a decl. * gcc.dg/tree-ssa/ssa-lim-25.c: New testcase. (cherry picked from commit f1e776ce58ae4a6ae67886adb4ae806598e2c7ef) Diff: --- gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-25.c | 18 ++ gcc/tree-eh.cc | 9 +++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-25.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-25.c new file mode 100644 index ..3e0f013d1e0d --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-25.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-lim2-details" } */ + +char x; + +long foo (int n) +{ + long y = 0; + for (int j = 0; j < 1024; ++j) +for (int i = 0; i < n; ++i) + y += *(long *)&x; + return y; +} + +/* Because *(long *)&x may trap we have to preserve execution and + only hoist it from the innermost loop (after the header check). */ +/* { dg-final { scan-tree-dump-not "out of loop 1" "lim2" } } */ +/* { dg-final { scan-tree-dump "out of loop 2" "lim2" } } */ diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc index 41cf57d2b305..550c1c61c354 100644 --- a/gcc/tree-eh.cc +++ b/gcc/tree-eh.cc @@ -2728,11 +2728,16 @@ tree_could_trap_p (tree expr) if (TREE_CODE (base) == STRING_CST) return maybe_le (TREE_STRING_LENGTH (base), off); tree size = DECL_SIZE_UNIT (base); + tree refsz = TYPE_SIZE_UNIT (TREE_TYPE (expr)); if (size == NULL_TREE + || refsz == NULL_TREE || !poly_int_tree_p (size) - || maybe_le (wi::to_poly_offset (size), off)) + || !poly_int_tree_p (refsz) + || maybe_le (wi::to_poly_offset (size), off) + || maybe_gt (off + wi::to_poly_offset (refsz), + wi::to_poly_offset (size))) return true; - /* Now we are sure the first byte of the access is inside + /* Now we are sure the whole base of the access is inside the object. */ return false; }
[gcc r15-9380] libstdc++: Define __cpp_lib_containers_ranges in appropriate headers [PR111055]
https://gcc.gnu.org/g:ae54d8cb51eb5cc1f5a3d319cc1840d2e9bfcbfc commit r15-9380-gae54d8cb51eb5cc1f5a3d319cc1840d2e9bfcbfc Author: Tomasz Kamiński Date: Fri Mar 21 12:55:48 2025 +0100 libstdc++: Define __cpp_lib_containers_ranges in appropriate headers [PR111055] This is final piece of P1206R7, adding a feature test macros, as range constructors and member operations are now implemented for all containers and adaptors. For consistency with the proposal, all new container operations and helpers are now defined if __glibcxx_containers_ranges, instead of __glibcxx_ranges_to_container. PR libstdc++/111055 libstdc++-v3/ChangeLog: * include/bits/version.def (containers_ranges): Define. * include/bits/version.h: Regenerate. * include/bits/ranges_base.h (__detail::__container_compatible_range) (__detail::__range_to_alloc_type, __detail::__range_mapped_type) (__detail::__range_key_type): Depend on __glibcxx_containers_ranges instead of __glibcxx_ranges_to_container. * include/bits/basic_string.h: Replace __glibcxx_ranges_to_container with __glibcxx_containers_ranges. * include/bits/cow_string.h: Likewise. * include/bits/deque.tcc: Likewise. * include/bits/forward_list.h: Likewise. * include/bits/stl_bvector.h: Likewise. * include/bits/stl_deque.h: Likewise. * include/bits/stl_list.h: Likewise. * include/bits/stl_map.h: Likewise. * include/bits/stl_multimap.h: Likewise. * include/bits/stl_multiset.h: Likewise. * include/bits/stl_queue.h: Likewise. * include/bits/stl_set.h: Likewise. * include/bits/stl_stack.h: Likewise. * include/bits/stl_vector.h: Likewise. * include/bits/unordered_map.h: Likewise. * include/bits/unordered_set.h: Likewise. * include/bits/vector.tcc: Likewise. * include/debug/deque: Likewise. * include/debug/forward_list: Likewise. * include/debug/list: Likewise. * include/debug/map.h: Likewise. * include/debug/multimap.h: Likewise. * include/debug/multiset.h: Likewise. * include/debug/set.h: Likewise. * include/debug/unordered_map: Likewise. * include/debug/unordered_set: Likewise. * include/debug/vector: Likewise. * include/std/deque: Provide __cpp_lib_containers_ranges. * include/std/forward_list: Likewise. * include/std/list: Likewise. * include/std/map: Likewise. * include/std/queue: Likewise. * include/std/set: Likewise. * include/std/stack: Likewise. * include/std/string: Likewise. * include/std/unordered_map: Likewise. * include/std/unordered_set: Likewise. * include/std/vector: Likewise. * testsuite/21_strings/basic_string/cons/from_range.cc: Test for value __cpp_lib_containers_ranges. * testsuite/23_containers/deque/cons/from_range.cc: Likewise. * testsuite/23_containers/forward_list/cons/from_range.cc: Likewise. * testsuite/23_containers/list/cons/from_range.cc: Likewise. * testsuite/23_containers/map/cons/from_range.cc: Likewise. * testsuite/23_containers/multimap/cons/from_range.cc: Likewise. * testsuite/23_containers/multiset/cons/from_range.cc: Likewise. * testsuite/23_containers/priority_queue/cons_from_range.cc: Likewise. * testsuite/23_containers/queue/cons_from_range.cc: Likewise. * testsuite/23_containers/set/cons/from_range.cc: Likewise. * testsuite/23_containers/stack/cons_from_range.cc: Likewise. * testsuite/23_containers/unordered_map/cons/from_range.cc: Likewise. * testsuite/23_containers/unordered_multimap/cons/from_range.cc: Likewise. * testsuite/23_containers/unordered_multiset/cons/from_range.cc: Likewise. * testsuite/23_containers/unordered_set/cons/from_range.cc: Likewise. * testsuite/23_containers/vector/bool/cons/from_range.cc: Likewise. * testsuite/23_containers/vector/cons/from_range.cc: Likewise. Reviewed-by: Jonathan Wakely Signed-off-by: Tomasz Kamiński Diff: --- libstdc++-v3/include/bits/basic_string.h | 16 libstdc++-v3/include/bits/cow_string.h | 10 +- libstdc++-v3/include/bits/deque.tcc | 4 ++-- libstdc++-v3/include/bits/forward_list.h | 20 ++-- libstdc++-v3/include/bits/ranges_base.h | 4 +++- libstdc++-v3/include/bits/stl_bvector.h | 8 libstdc++-v3/include/bits/stl_deque.h
[gcc r15-9381] libstdc++: Use constexpr-if for std::basic_string::_S_copy_chars
https://gcc.gnu.org/g:648d5c26e25497249e1d381449f2bf66418b997c commit r15-9381-g648d5c26e25497249e1d381449f2bf66418b997c Author: Jonathan Wakely Date: Thu Apr 10 12:21:26 2025 +0100 libstdc++: Use constexpr-if for std::basic_string::_S_copy_chars For C++11 and later we can remove four overloads of _S_copy_chars and use constexpr-if in the generic _S_copy_chars. This simplifies overload resolution for _S_copy_chars, and also means that we use the optimized memcpy path for other iterators such as std::vector::iterator. We still need all the _S_copy_chars overloads to be part of the explicit instantiation definition, so make them depend on the macro that is defined by src/c++11/string-inst.cc for that purpose. For C++98 the _S_copy_chars overloads are still needed, but the macros _GLIBCXX_NOEXCEPT and _GLIBCXX20_CONSTEXPR do nothing for C++98, so this change removes them from those overloads. When instantiated in src/c++11/string-inst.cc the removed _GLIBCXX_NOEXCEPT macros would expand to 'noexcept', but in practice that doesn't make any difference for those instantiations. At -O2 the instantiations inline all the calls to _S_copy_chars and the presence or absence of noexcept doesn't change anything in the generated code. libstdc++-v3/ChangeLog: * include/bits/basic_string.h (_S_copy_chars): Replace overloads with constexpr-if and extend optimization to all contiguous iterators. * src/c++11/string-inst.cc: Extend comment. Reviewed-by: Tomasz Kaminski Diff: --- libstdc++-v3/include/bits/basic_string.h | 31 +++ libstdc++-v3/src/c++11/string-inst.cc| 3 ++- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 630ff1af8d3f..9c431c765ab4 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -473,6 +473,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 traits_type::assign(__d, __n, __c); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wc++17-extensions" // _S_copy_chars is a separate template to permit specialization // to optimize for the common case of pointers as iterators. template @@ -480,31 +482,44 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 static void _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2) { +#if __cplusplus >= 201103L + using _IterBase = decltype(std::__niter_base(__k1)); + if constexpr (__or_, + is_same<_IterBase, const _CharT*>>::value) + _S_copy(__p, std::__niter_base(__k1), __k2 - __k1); +#if __cpp_lib_concepts + else if constexpr (contiguous_iterator<_Iterator> + && is_same_v, _CharT>) + { + const auto __d = __k2 - __k1; + (void) (__k1 + __d); // See P3349R1 + _S_copy(__p, std::to_address(__k1), static_cast(__d)); + } +#endif + else +#endif for (; __k1 != __k2; ++__k1, (void)++__p) traits_type::assign(*__p, *__k1); // These types are off. } +#pragma GCC diagnostic pop - _GLIBCXX20_CONSTEXPR +#if __cplusplus < 201103L || defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS static void - _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT + _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) { _S_copy_chars(__p, __k1.base(), __k2.base()); } - _GLIBCXX20_CONSTEXPR static void _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2) - _GLIBCXX_NOEXCEPT { _S_copy_chars(__p, __k1.base(), __k2.base()); } - _GLIBCXX20_CONSTEXPR static void - _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT + _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) { _S_copy(__p, __k1, __k2 - __k1); } - _GLIBCXX20_CONSTEXPR static void _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2) - _GLIBCXX_NOEXCEPT { _S_copy(__p, __k1, __k2 - __k1); } +#endif #if __glibcxx_containers_ranges // C++ >= 23 // pre: __n == ranges::distance(__rg). __p+[0,__n) is a valid range. diff --git a/libstdc++-v3/src/c++11/string-inst.cc b/libstdc++-v3/src/c++11/string-inst.cc index c4864794d40b..34df909b31a2 100644 --- a/libstdc++-v3/src/c++11/string-inst.cc +++ b/libstdc++-v3/src/c++11/string-inst.cc @@ -40,7 +40,8 @@ // replaced by constrained function templates, so that we instantiate the // pre-C++17 definitions. // This also causes the instantiation of the non-standard C++0x-era -// insert(iterator, initializer_list) overload, see PR libstdc++/83328 +// insert(iterator, initializer_list) overload, see PR libstdc++/83328, +// and overlo
[gcc r15-9382] libstdc++: Support aarch64-w64-mingw32 target in fast_float
https://gcc.gnu.org/g:c3ba75f6ac7d1e72faabe0cf62453f463359278f commit r15-9382-gc3ba75f6ac7d1e72faabe0cf62453f463359278f Author: Evgeny Karpov Date: Tue Sep 3 09:09:52 2024 + libstdc++: Support aarch64-w64-mingw32 target in fast_float This patch resolves the GCC compilation issue for the C++ language targeting aarch64-w64-mingw32. The change in fast_float has been upstreamed. https://github.com/fastfloat/fast_float/pull/269 libstdc++-v3/ChangeLog: * src/c++17/fast_float/fast_float.h (full_multiplication): Support aarch64-w64-mingw32 target. Diff: --- libstdc++-v3/src/c++17/fast_float/fast_float.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/src/c++17/fast_float/fast_float.h b/libstdc++-v3/src/c++17/fast_float/fast_float.h index 7551c4f89ef7..3da58f2850ce 100644 --- a/libstdc++-v3/src/c++17/fast_float/fast_float.h +++ b/libstdc++-v3/src/c++17/fast_float/fast_float.h @@ -275,7 +275,8 @@ fastfloat_really_inline value128 full_multiplication(uint64_t a, // But MinGW on ARM64 doesn't have native support for 64-bit multiplications answer.high = __umulh(a, b); answer.low = a * b; -#elif defined(FASTFLOAT_32BIT) || (defined(_WIN64) && !defined(__clang__)) +#elif defined(FASTFLOAT_32BIT) || \ +(defined(_WIN64) && !defined(__clang__) && !defined(_M_ARM64)) answer.low = _umul128(a, b, &answer.high); // _umul128 not available on ARM64 #elif defined(FASTFLOAT_64BIT) __uint128_t r = ((__uint128_t)a) * b;
[gcc r15-9383] libstdc++: Add fast_float patch to LOCAL_PATCHES
https://gcc.gnu.org/g:44478b69d70ff0095a1fd06392e380827de4688a commit r15-9383-g44478b69d70ff0095a1fd06392e380827de4688a Author: Jonathan Wakely Date: Fri Apr 11 14:21:35 2025 +0100 libstdc++: Add fast_float patch to LOCAL_PATCHES libstdc++-v3/ChangeLog: * src/c++17/fast_float/LOCAL_PATCHES: Update. Diff: --- libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES | 1 + 1 file changed, 1 insertion(+) diff --git a/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES b/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES index 71495d6728bf..28d86fd4d70d 100644 --- a/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES +++ b/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES @@ -1,2 +1,3 @@ r12-6647 r12-6648 +r15-9382
[gcc/devel/omp/gcc-14] OpenACC 2.7: adjust 2.6 references to 2.7
https://gcc.gnu.org/g:ea9516fe4998fd1cd6420e7b0a9d8ab8ed60c2ce commit ea9516fe4998fd1cd6420e7b0a9d8ab8ed60c2ce Author: Chung-Lin Tang Date: Fri Apr 11 13:51:55 2025 + OpenACC 2.7: adjust 2.6 references to 2.7 More adjustments to indicate OpenACC 2.7 support. 2025-04-11 Chung-Lin Tang gcc/fortran/ChangeLog: * intrinsic.texi (OpenACC Module OPENACC): Adjust version references to 2.7 from 2.6. libgomp/ChangeLog: * libgomp.texi (Enabling OpenACC): Adjust version references to 2.7 from 2.6. * openacc.f90 (module openacc): Adjust openacc_version to 201811. * openacc_lib.h (openacc_version): Adjust openacc_version to 201811. * testsuite/libgomp.oacc-fortran/openacc_version-1.f: Adjust test value to 201811. * testsuite/libgomp.oacc-fortran/openacc_version-2.f90: Likewise. Diff: --- gcc/fortran/intrinsic.texi | 6 +++--- libgomp/libgomp.texi | 8 libgomp/openacc.f90 | 2 +- libgomp/openacc_lib.h| 2 +- libgomp/testsuite/libgomp.oacc-fortran/openacc_version-1.f | 2 +- libgomp/testsuite/libgomp.oacc-fortran/openacc_version-2.f90 | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/gcc/fortran/intrinsic.texi b/gcc/fortran/intrinsic.texi index 0445feaf73a7..eedfb83231e7 100644 --- a/gcc/fortran/intrinsic.texi +++ b/gcc/fortran/intrinsic.texi @@ -15400,7 +15400,7 @@ The following scalar integer named constants are of the kind @section OpenACC Module @code{OPENACC} @table @asis @item @emph{Standard}: -OpenACC Application Programming Interface v2.6 +OpenACC Application Programming Interface v2.7 @end table @@ -15414,9 +15414,9 @@ are listed below. For details refer to the actual @uref{https://www.openacc.org/, -OpenACC Application Programming Interface v2.6}. +OpenACC Application Programming Interface v2.7}. @code{OPENACC} provides the scalar default-integer named constant @code{openacc_version} with a value of the form @var{mm}, where @code{} is the year and @var{mm} the month -of the OpenACC version; for OpenACC v2.6 the value is @code{201711}. +of the OpenACC version; for OpenACC v2.7 the value is @code{201811}. diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi index e303cb513c5a..5190a04f6648 100644 --- a/libgomp/libgomp.texi +++ b/libgomp/libgomp.texi @@ -4578,7 +4578,7 @@ See @uref{https://gcc.gnu.org/wiki/OpenACC} for more information. A complete description of all OpenACC directives accepted may be found in the @uref{https://www.openacc.org, OpenACC} Application Programming -Interface manual, version 2.6. +Interface manual, version 2.7. @@ -4590,14 +4590,14 @@ Interface manual, version 2.6. @chapter OpenACC Runtime Library Routines The runtime routines described here are defined by section 3 of the OpenACC -specifications in version 2.6. +specifications in version 2.7. They have C linkage, and do not throw exceptions. Generally, they are available only for the host, with the exception of @code{acc_on_device}, which is available for both the host and the acceleration device. This list has not yet been updated for the OpenACC specification in -version 2.6. +version 2.7. @menu * acc_get_num_devices:: Get number of devices for the given device @@ -4688,7 +4688,7 @@ for the device type specified in @var{devicetype}. @end multitable @item @emph{Reference}: -@uref{https://www.openacc.org, OpenACC specification v2.6}, section +@uref{https://www.openacc.org, OpenACC specification v2.7}, section 3.2.1. @end table diff --git a/libgomp/openacc.f90 b/libgomp/openacc.f90 index 4e24ee46a977..6ee68630114d 100644 --- a/libgomp/openacc.f90 +++ b/libgomp/openacc.f90 @@ -798,7 +798,7 @@ module openacc public :: acc_memcpy_to_device, acc_memcpy_to_device_async public :: acc_memcpy_from_device, acc_memcpy_from_device_async - integer, parameter :: openacc_version = 201711 + integer, parameter :: openacc_version = 201811 interface acc_get_num_devices procedure :: acc_get_num_devices_h diff --git a/libgomp/openacc_lib.h b/libgomp/openacc_lib.h index 913c3f1aa3dc..47779125ff29 100644 --- a/libgomp/openacc_lib.h +++ b/libgomp/openacc_lib.h @@ -70,7 +70,7 @@ integer (acc_handle_kind), parameter :: acc_async_noval = -1 integer (acc_handle_kind), parameter :: acc_async_sync = -2 - integer, parameter :: openacc_version = 201711 + integer, parameter :: openacc_version = 201811 interface acc_get_num_devices function acc_get_num_devices_h (devicetype) diff --git a/libgomp/testsuite/libgomp.oacc-fortran/openacc_version-1.f b/libgomp/testsuite/libgomp.oacc-fortran/openacc_version-1.f index 36e9844bb157..8d4e3f35880a 100644 --- a/libgomp/testsuite/libgomp.oacc
[gcc r15-9385] [committed] [RISC-V] Fix testsuite fallout from recent changes
https://gcc.gnu.org/g:992be16d83814694d6dbce448f9b5cb47ba4c8d4 commit r15-9385-g992be16d83814694d6dbce448f9b5cb47ba4c8d4 Author: Jeff Law Date: Fri Apr 11 08:28:22 2025 -0600 [committed] [RISC-V] Fix testsuite fallout from recent changes Recent changes have started triggering: > Tests that now fail, but worked before (3 tests): > > unix/-march=rv64gc_zba_zbb_zbs_zicond: gcc: gcc.target/riscv/rvv/base/pr115068-run.c (test for excess errors) > unix/-march=rv64gc_zba_zbb_zbs_zicond: gcc: gcc.target/riscv/rvv/base/pr115068.c (test for excess errors) > unix/-march=rv64gc_zba_zbb_zbs_zicond: gcc: gcc.target/riscv/rvv/base/vwaddsub-1.c (test for excess errors) We're emitting a pedantic diagnostic on the #include_next. This just turns off the pedantic warnings. Pushing as obvious. gcc/testsuite * gcc.target/riscv/rvv/base/pr115068-run.c: Turn off pedantic diagnostics. * gcc.target/riscv/rvv/base/pr115068.c: Likewise. * gcc.target/riscv/rvv/base/vwaddsub-1.c: Likewise. Diff: --- gcc/testsuite/gcc.target/riscv/rvv/base/pr115068-run.c | 2 +- gcc/testsuite/gcc.target/riscv/rvv/base/pr115068.c | 2 +- gcc/testsuite/gcc.target/riscv/rvv/base/vwaddsub-1.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr115068-run.c b/gcc/testsuite/gcc.target/riscv/rvv/base/pr115068-run.c index d552eb568f67..e9e41f7db87f 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/base/pr115068-run.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr115068-run.c @@ -1,6 +1,6 @@ /* { dg-do run } */ /* { dg-require-effective-target riscv_v_ok } */ /* { dg-add-options riscv_v } */ -/* { dg-additional-options "-std=gnu99" } */ +/* { dg-additional-options "-std=gnu99 -Wno-pedantic" } */ #include "pr115068.c" diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr115068.c b/gcc/testsuite/gcc.target/riscv/rvv/base/pr115068.c index 8144d29b8378..ce9a3892a700 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/base/pr115068.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr115068.c @@ -1,6 +1,6 @@ /* { dg-do compile { target { ! riscv_abi_e } } } */ /* { dg-add-options riscv_v } */ -/* { dg-additional-options "-std=gnu99" } */ +/* { dg-additional-options "-std=gnu99 -Wno-pedantic" } */ #include #include "riscv_vector.h" diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/vwaddsub-1.c b/gcc/testsuite/gcc.target/riscv/rvv/base/vwaddsub-1.c index c0ca9fcbf908..43be202ebe9a 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/base/vwaddsub-1.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/vwaddsub-1.c @@ -1,6 +1,6 @@ /* { dg-do compile { target { { ! riscv_abi_e } && rv64 } } } */ /* { dg-add-options riscv_v } */ -/* { dg-additional-options "-std=gnu99 -O3 -fno-schedule-insns -fno-schedule-insns2" } */ +/* { dg-additional-options "-std=gnu99 -O3 -fno-schedule-insns -fno-schedule-insns2 -Wno-pedantic" } */ #include #include "riscv_vector.h"
[gcc r15-9384] c++: avoid ARM -Wunused-value [PR114970]
https://gcc.gnu.org/g:4acdfb71d4fdaa43c2707ad7b2fb7b2b7bddfc42 commit r15-9384-g4acdfb71d4fdaa43c2707ad7b2fb7b2b7bddfc42 Author: Jason Merrill Date: Thu Apr 10 18:16:37 2025 -0400 c++: avoid ARM -Wunused-value [PR114970] Because of the __builtin_is_constant_evaluated, maybe_constant_init in expand_default_init fails, so the constexpr constructor isn't folded until cp_fold, which then calls cp_build_init_expr_for_ctor, which builds a COMPOUND_EXPR in case the enclosing expression is relying on the ARM behavior of returning 'this'. As in other places, avoid -Wunused-value on artificial COMPOUND_EXPR. PR c++/114970 gcc/cp/ChangeLog: * cp-gimplify.cc (cp_build_init_expr_for_ctor): Suppress warnings on return_this COMPOUND_EXPR. gcc/testsuite/ChangeLog: * g++.dg/opt/is_constant_evaluated4.C: New test. Diff: --- gcc/cp/cp-gimplify.cc | 7 +-- gcc/testsuite/g++.dg/opt/is_constant_evaluated4.C | 20 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index 550cea29dd29..f5625ab0daad 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -1199,8 +1199,11 @@ cp_build_init_expr_for_ctor (tree call, tree init) tree s = build_fold_indirect_ref_loc (loc, a); init = cp_build_init_expr (s, init); if (return_this) -init = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (call), init, - fold_convert_loc (loc, TREE_TYPE (call), a)); +{ + init = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (call), init, +fold_convert_loc (loc, TREE_TYPE (call), a)); + suppress_warning (init); +} return init; } diff --git a/gcc/testsuite/g++.dg/opt/is_constant_evaluated4.C b/gcc/testsuite/g++.dg/opt/is_constant_evaluated4.C new file mode 100644 index ..9650004ced1e --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/is_constant_evaluated4.C @@ -0,0 +1,20 @@ +// PR c++/114970 +// { dg-do compile { target c++17 } } +// { dg-additional-options "-O -Wunused-value" } + +struct sv +{ + const char* str; + unsigned len; + + constexpr sv(const char *p): str(p), len(0) + { +if (__builtin_is_constant_evaluated ()) { len = 42; } + } +}; + +int main() +{ + sv s ("foo"); + return s.len; +}
[gcc r14-11596] c++: avoid ARM -Wunused-value [PR114970]
https://gcc.gnu.org/g:45c949fb697d4602fa8ce8e87213cf17e1acf60b commit r14-11596-g45c949fb697d4602fa8ce8e87213cf17e1acf60b Author: Jason Merrill Date: Thu Apr 10 18:16:37 2025 -0400 c++: avoid ARM -Wunused-value [PR114970] Because of the __builtin_is_constant_evaluated, maybe_constant_init in expand_default_init fails, so the constexpr constructor isn't folded until cp_fold, which builds a COMPOUND_EXPR in case the enclosing expression is relying on the ARM behavior of returning 'this'. As in other places, avoid -Wunused-value on artificial COMPOUND_EXPR. PR c++/114970 gcc/cp/ChangeLog: * cp-gimplify.cc (cp_fold): Suppress warnings on return_this COMPOUND_EXPR. gcc/testsuite/ChangeLog: * g++.dg/opt/is_constant_evaluated4.C: New test. (cherry picked from commit 4acdfb71d4fdaa43c2707ad7b2fb7b2b7bddfc42) Diff: --- gcc/cp/cp-gimplify.cc | 7 +-- gcc/testsuite/g++.dg/opt/is_constant_evaluated4.C | 20 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index 7b52fc301d61..37dc4a286a0a 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -3437,8 +3437,11 @@ cp_fold (tree x, fold_flags_t flags) tree s = build_fold_indirect_ref_loc (loc, a); r = cp_build_init_expr (s, r); if (return_this) - r = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (x), r, - fold_convert_loc (loc, TREE_TYPE (x), a)); + { + r = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (x), r, + fold_convert_loc (loc, TREE_TYPE (x), a)); + suppress_warning (r); + } } x = r; break; diff --git a/gcc/testsuite/g++.dg/opt/is_constant_evaluated4.C b/gcc/testsuite/g++.dg/opt/is_constant_evaluated4.C new file mode 100644 index ..9650004ced1e --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/is_constant_evaluated4.C @@ -0,0 +1,20 @@ +// PR c++/114970 +// { dg-do compile { target c++17 } } +// { dg-additional-options "-O -Wunused-value" } + +struct sv +{ + const char* str; + unsigned len; + + constexpr sv(const char *p): str(p), len(0) + { +if (__builtin_is_constant_evaluated ()) { len = 42; } + } +}; + +int main() +{ + sv s ("foo"); + return s.len; +}
[gcc r15-9386] testcase: Add testcase for shrink wrapping of vector::push_back [PR118502]
https://gcc.gnu.org/g:33b255a1aa2f21889a8cfecb7a67a63fefa19460 commit r15-9386-g33b255a1aa2f21889a8cfecb7a67a63fefa19460 Author: Andrew Pinski Date: Thu Jan 16 23:47:36 2025 -0800 testcase: Add testcase for shrink wrapping of vector::push_back [PR118502] LLVM folks noticed that GCC was shrink wrapping the call to vector::push_back. So I thought it was a good idea to commit a testcase to make sure GCC does not regress in this area unknowning. Note the shrink wrapping started with r15-1619-g3b9b8d6cfdf593. Note this enables the testcase for x86_64 (!ia32), powerpc, aarch64 and riscv which I tested via godbolt to see the shrink wrapping occurs. Also tested the testcase for both x86_64-linux-gnu and aarch64-linux-gnu to make sure I got the target selects correct. Changes since v1: * v2: Fix some comments typos that was mentioned in the bug report. PR rtl-optimization/118502 gcc/testsuite/ChangeLog: * g++.dg/opt/shrink-wrapping-vector-1.C: New test. Signed-off-by: Andrew Pinski Diff: --- gcc/testsuite/g++.dg/opt/shrink-wrapping-vector-1.C | 17 + 1 file changed, 17 insertions(+) diff --git a/gcc/testsuite/g++.dg/opt/shrink-wrapping-vector-1.C b/gcc/testsuite/g++.dg/opt/shrink-wrapping-vector-1.C new file mode 100644 index ..8b1ad53fa805 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/shrink-wrapping-vector-1.C @@ -0,0 +1,17 @@ +// { dg-do compile { target { { { i?86-*-* x86_64-*-* } && { ! ia32 } } || { powerpc*-*-* aarch64*-*-* riscv*-*-* } } } } +// { dg-options "-O2 -fdump-rtl-pro_and_epilogue" } +// { dg-skip-if "requires hosted libstdc++ for vector" { ! hostedlib } } + +// PR rtl-optimization/118502 + +// The shrink-wrapping should happen around the slow path of vector::push_back, +// The fast path is just checking if there is enough space and doing a few stores. +// We want to verify that shrink wrapping always happens. + +#include + +void push_back(std::vector& xs, unsigned char x) { +xs.push_back(x); +} + +/* { dg-final { scan-rtl-dump "Performing shrink-wrapping" "pro_and_epilogue" } } */
[gcc r15-9387] testsuite: arm: rename arm_v8_1_lob_ok into arm_v8_1m_lob_hw
https://gcc.gnu.org/g:5cc8a75140032b0ac70ca0d25e0e5fda350d8511 commit r15-9387-g5cc8a75140032b0ac70ca0d25e0e5fda350d8511 Author: Christophe Lyon Date: Thu Apr 10 13:39:23 2025 + testsuite: arm: rename arm_v8_1_lob_ok into arm_v8_1m_lob_hw All arm effective-targets using check_runtime use the "_hw" or "_multilib" suffix, so rename arm_v8_1_lob_ok into arm_v8_1m_lob_hw for consistency. Since "lob" applies only to M-profile, replace v8_1 with v8_1m in arm_v8_1_lob_ok, arm_thumb2_no_arm_v8_1_lob and arm_thumb2_ok_no_arm_v8_1_lob. gcc/testsuite/ChangeLog * lib/target-supports.exp: Rename arm_v8_1_lob_ok into arm_v8_1m_lob_hw. Rename arm_thumb2_no_arm_v8_1_lob into arm_thumb2_no_arm_v8_1m_lob. Rename arm_thumb2_ok_no_arm_v8_1_lob into arm_thumb2_ok_no_arm_v8_1m_lob. * gcc.target/arm/lob1.c: Likewise. * gcc.target/arm/lob6.c: Likewise. * gcc.target/arm/ivopts.c: Likewise. * gcc.target/arm/unsigned-extend-2.c: Likewise. Diff: --- gcc/testsuite/gcc.target/arm/ivopts.c| 2 +- gcc/testsuite/gcc.target/arm/lob1.c | 2 +- gcc/testsuite/gcc.target/arm/lob6.c | 2 +- gcc/testsuite/gcc.target/arm/unsigned-extend-2.c | 2 +- gcc/testsuite/lib/target-supports.exp| 12 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gcc/testsuite/gcc.target/arm/ivopts.c b/gcc/testsuite/gcc.target/arm/ivopts.c index d7d72a59d9c3..582fdab7836d 100644 --- a/gcc/testsuite/gcc.target/arm/ivopts.c +++ b/gcc/testsuite/gcc.target/arm/ivopts.c @@ -11,6 +11,6 @@ tr5 (short array[], int n) } /* { dg-final { scan-tree-dump-times "PHI <" 1 "ivopts"} } */ -/* { dg-final { object-size text <= 20 { target { arm_thumb2_no_arm_v8_1_lob } } } } */ +/* { dg-final { object-size text <= 20 { target { arm_thumb2_no_arm_v8_1m_lob } } } } */ /* { dg-final { object-size text <= 32 { target { arm_nothumb && { ! arm_iwmmxt_ok } } } } } */ /* { dg-final { object-size text <= 36 { target { arm_nothumb && arm_iwmmxt_ok } } } } */ diff --git a/gcc/testsuite/gcc.target/arm/lob1.c b/gcc/testsuite/gcc.target/arm/lob1.c index c8ce653a5c39..f42a36748d62 100644 --- a/gcc/testsuite/gcc.target/arm/lob1.c +++ b/gcc/testsuite/gcc.target/arm/lob1.c @@ -1,7 +1,7 @@ /* Check that GCC generates Armv8.1-M low over head loop instructions for some simple loops. */ /* { dg-do run } */ -/* { dg-require-effective-target arm_v8_1_lob_ok } */ +/* { dg-require-effective-target arm_v8_1m_lob_hw } */ /* { dg-skip-if "avoid conflicting multilib options" { *-*-* } { "-marm" "-mcpu=*" } } */ /* { dg-options "-march=armv8.1-m.main -mthumb -O3 --save-temps" } */ #include diff --git a/gcc/testsuite/gcc.target/arm/lob6.c b/gcc/testsuite/gcc.target/arm/lob6.c index 4fe116e2c2be..e19635b6d96a 100644 --- a/gcc/testsuite/gcc.target/arm/lob6.c +++ b/gcc/testsuite/gcc.target/arm/lob6.c @@ -1,7 +1,7 @@ /* Check that GCC generates Armv8.1-M low over head loop instructions with some less trivial loops and the result is correct. */ /* { dg-do run } */ -/* { dg-require-effective-target arm_v8_1_lob_ok } */ +/* { dg-require-effective-target arm_v8_1m_lob_hw } */ /* { dg-skip-if "avoid conflicting multilib options" { *-*-* } { "-marm" "-mcpu=*" } } */ /* { dg-options "-march=armv8.1-m.main -mthumb -O3 --save-temps" } */ #include diff --git a/gcc/testsuite/gcc.target/arm/unsigned-extend-2.c b/gcc/testsuite/gcc.target/arm/unsigned-extend-2.c index 9272e4ce9b8c..41ee994c1ec2 100644 --- a/gcc/testsuite/gcc.target/arm/unsigned-extend-2.c +++ b/gcc/testsuite/gcc.target/arm/unsigned-extend-2.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-require-effective-target arm_thumb2_ok_no_arm_v8_1_lob } */ +/* { dg-require-effective-target arm_thumb2_ok_no_arm_v8_1m_lob } */ /* { dg-options "-O" } */ unsigned short foo (unsigned short x, unsigned short c) diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index ee4138aa6971..a62f459ad7ed 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -13489,11 +13489,11 @@ proc check_effective_target_arm_v8_3a_bkey_directive { } { # Return 1 if the target supports executing the Armv8.1-M Mainline Low # Overhead Loop, 0 otherwise. The test is valid for ARM. -proc check_effective_target_arm_v8_1_lob_ok { } { +proc check_effective_target_arm_v8_1m_lob_hw { } { if { ![check_effective_target_arm_cortex_m] } { return 0; } else { - return [check_runtime arm_v8_1_lob_hw_available { + return [check_runtime arm_v8_1m_lob_hw_available { int main (void) { int i = 0; @@ -13513,9 +13513,9 @@ proc check_effective_target_arm_v8_1_lob_ok { } { # the Armv8.1-M Mainline Low Overhead Loop, 0 otherwise. The test is # valid for ARM. -p
[gcc r15-9388] PR modula2/119735: Remove single quotes from m2 source code comments.
https://gcc.gnu.org/g:985ae5ae9d76f5ea10996ec7466c4d636840495a commit r15-9388-g985ae5ae9d76f5ea10996ec7466c4d636840495a Author: Gaius Mulley Date: Fri Apr 11 19:34:17 2025 +0100 PR modula2/119735: Remove single quotes from m2 source code comments. Removing ' from all m2 comments so that make gcc.pot does not generate any warnings. Also hide %n from comments. gcc/m2/ChangeLog: PR modula2/119735 * gm2-compiler/M2MetaError.def: Hide %n from comment. * gm2-compiler/SymbolTable.def (PutIncludedByDefinition): Remove ' from comment. * gm2-gcc/m2expr.def (init): Ditto. * gm2-libiberty/pexecute.def: Ditto. * gm2-libs-coroutines/Executive.def (InitSemaphore): Ditto. (Wait): Ditto. * gm2-libs-iso/ClientSocket.def: Ditto. * gm2-libs-log/BlockOps.def (BlockMoveBackward): Ditto. * gm2-libs-log/InOut.def: Ditto. * mc/mcFileName.def: Ditto. Signed-off-by: Gaius Mulley Diff: --- gcc/m2/gm2-compiler/M2MetaError.def | 3 ++- gcc/m2/gm2-compiler/SymbolTable.def | 2 +- gcc/m2/gm2-gcc/m2expr.def| 2 +- gcc/m2/gm2-libiberty/pexecute.def| 16 gcc/m2/gm2-libs-coroutines/Executive.def | 6 +++--- gcc/m2/gm2-libs-iso/ClientSocket.def | 2 +- gcc/m2/gm2-libs-log/BlockOps.def | 2 +- gcc/m2/gm2-libs-log/InOut.def| 4 ++-- gcc/m2/mc/mcFileName.def | 2 +- 9 files changed, 20 insertions(+), 19 deletions(-) diff --git a/gcc/m2/gm2-compiler/M2MetaError.def b/gcc/m2/gm2-compiler/M2MetaError.def index 92c4ad2b8d8e..cfe9195adf94 100644 --- a/gcc/m2/gm2-compiler/M2MetaError.def +++ b/gcc/m2/gm2-compiler/M2MetaError.def @@ -73,7 +73,8 @@ FROM NameKey IMPORT Name ; {%kword} the string word is unquoted and rendered as a keyword. {%C} chain this error on the previous rooted error. {%R} this error will be the root of the future chained errors. -{%n} decimal number. Not quoted. +{% n} decimal number. Not quoted. There is no space between the + % and n (this has been added to hide this comment from gettext). {%N} count (number), for example, 1st, 2nd, 3rd, 4th. Not quoted. {%X} push contents of the output string onto the string stack. {%Yname} place contents of dictionary entry name onto the output string. diff --git a/gcc/m2/gm2-compiler/SymbolTable.def b/gcc/m2/gm2-compiler/SymbolTable.def index d9d4c87a80e5..85a36727c6ed 100644 --- a/gcc/m2/gm2-compiler/SymbolTable.def +++ b/gcc/m2/gm2-compiler/SymbolTable.def @@ -2025,7 +2025,7 @@ PROCEDURE PutIncludedByDefinition (Sym: CARDINAL) ; (* IsIncludedByDefinition - returns TRUE if definition module symbol, Sym, was included -by ModSym's definition module. +by ModSyms definition module. *) PROCEDURE IsIncludedByDefinition (ModSym, Sym: CARDINAL) : BOOLEAN ; diff --git a/gcc/m2/gm2-gcc/m2expr.def b/gcc/m2/gm2-gcc/m2expr.def index e9f48b813c71..a9f5f37280c2 100644 --- a/gcc/m2/gm2-gcc/m2expr.def +++ b/gcc/m2/gm2-gcc/m2expr.def @@ -45,7 +45,7 @@ PROCEDURE init (location: location_t) ; (* CSTIntToString - return an integer string using base 10 and no padding. -The string returned will have been malloc'd. +The string returned will have been mallocd. *) PROCEDURE CSTIntToString (t: tree) : CharStar ; diff --git a/gcc/m2/gm2-libiberty/pexecute.def b/gcc/m2/gm2-libiberty/pexecute.def index 30a41e1a4b21..49af52ccd1de 100644 --- a/gcc/m2/gm2-libiberty/pexecute.def +++ b/gcc/m2/gm2-libiberty/pexecute.def @@ -31,16 +31,16 @@ EXPORT UNQUALIFIED pexecute ; THIS_PNAME is name of the calling program (i.e. argv[0]). TEMP_BASE is the path name, sans suffix, of a temporary file to use - if needed. This is currently only needed for MSDOS ports that don't use - GO32 (do any still exist?). Ports that don't need it can pass NULL. + if needed. This is currently only needed for MSDOS ports that dont use + GO32 (do any still exist?). Ports that dont need it can pass NULL. (FLAGS & PEXECUTE_SEARCH) is non-zero if $PATH should be searched - (??? It's not clear that GCC passes this flag correctly). + (??? Its not clear that GCC passes this flag correctly). (FLAGS & PEXECUTE_FIRST) is nonzero for the first process in chain. (FLAGS & PEXECUTE_FIRST) is nonzero for the last process in chain. FIRST_LAST could be simplified to only mark the last of a chain of processes but that requires the caller to always mark the last one (and not give up - early if some error occurs). It's more robust to require the caller to + early if some error occurs). Its more robust to require the caller to mark both ends of the chain. The result is the pid on systems like Unix where we fork/exec and on
[gcc r15-9389] Doc: Delete misleading sentence from -frounding-math docs [PR105548]
https://gcc.gnu.org/g:93f6ea830348a5a733ecde863cddae80d84bdda0 commit r15-9389-g93f6ea830348a5a733ecde863cddae80d84bdda0 Author: Sandra Loosemore Date: Fri Apr 11 21:16:41 2025 + Doc: Delete misleading sentence from -frounding-math docs [PR105548] gcc/ChangeLog PR middle-end/105548 * doc/invoke.texi (Optimize Options): Delete misleading sentence about conversions. Diff: --- gcc/doc/invoke.texi | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index ffde9df85fd3..b9dc3fc7ccdf 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -15505,9 +15505,8 @@ default state for @code{FENV_ACCESS}. @opindex frounding-math @item -frounding-math Disable transformations and optimizations that assume default floating-point -rounding behavior. This is round-to-zero for all floating point -to integer conversions, and round-to-nearest for all other arithmetic -truncations. This option should be specified for programs that change +rounding behavior (round-to-nearest). +This option should be specified for programs that change the FP rounding mode dynamically, or that may be executed with a non-default rounding mode. This option disables constant folding of floating-point expressions at compile time (which may be affected by
[gcc r15-9390] Doc: Correct documentation for -fstrong-eval-order [PR106618]
https://gcc.gnu.org/g:498933e54dc4669276951d27d3b1bcdc0d4bacb4 commit r15-9390-g498933e54dc4669276951d27d3b1bcdc0d4bacb4 Author: Sandra Loosemore Date: Fri Apr 11 22:18:45 2025 + Doc: Correct documentation for -fstrong-eval-order [PR106618] gcc/ChangeLog PR c++/106618 * doc/invoke.texi (Option Summary): Remove -fargs-in-order, add -fstrong-eval-order. (C++ Dialect Options): Explicitly document that -fstrong-eval-order takes an optional argument and what the choices are. Generalize references to C++17. Diff: --- gcc/doc/invoke.texi | 17 - 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index b9dc3fc7ccdf..4be80a7f7f9a 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -211,8 +211,7 @@ in the following sections. @item C++ Language Options @xref{C++ Dialect Options,,Options Controlling C++ Dialect}. @gccoptlist{-fabi-version=@var{n} -fno-access-control --faligned-new=@var{n} -fargs-in-order=@var{n} --fno-assume-sane-operators-new-delete +-faligned-new=@var{n} -fno-assume-sane-operators-new-delete -fchar8_t -fcheck-new -fconcepts -fconstexpr-depth=@var{n} -fconstexpr-cache-depth=@var{n} -fconstexpr-loop-limit=@var{n} -fconstexpr-ops-limit=@var{n} @@ -235,6 +234,7 @@ in the following sections. -fno-optional-diags -fno-pretty-templates -frange-for-ext-temps -fno-rtti -fsized-deallocation +-fstrong-eval-order@r{[}=@var{kind}@r{]} -ftemplate-backtrace-limit=@var{n} -ftemplate-depth=@var{n} -fno-threadsafe-statics -fuse-cxa-atexit @@ -3581,12 +3581,19 @@ type. @opindex fstrong-eval-order @item -fstrong-eval-order +@itemx -fstrong-eval-order=@var{kind} Evaluate member access, array subscripting, and shift expressions in left-to-right order, and evaluate assignment in right-to-left order, -as adopted for C++17. Enabled by default with @option{-std=c++17}. +as adopted for C++17. @option{-fstrong-eval-order} is equivalent to +@option{-fstrong-eval-order=all}, +and is enabled by default with @option{-std=c++17} or later. + @option{-fstrong-eval-order=some} enables just the ordering of member -access and shift expressions, and is the default without -@option{-std=c++17}. +access and shift expressions, and is the default for C++ dialects prior to +C++17. + +@option{-fstrong-eval-order=none} is equivalent to +@option{-fno-strong-eval-order}. @opindex ftemplate-backtrace-limit @item -ftemplate-backtrace-limit=@var{n}
[gcc r13-9517] df: Treat partial defs as uses in df_simulate_defs [PR116564]
https://gcc.gnu.org/g:7c6bd95b1811d797f43983dbbeb4ad478bdb5c9e commit r13-9517-g7c6bd95b1811d797f43983dbbeb4ad478bdb5c9e Author: Alex Coplan Date: Mon Mar 10 16:44:15 2025 + df: Treat partial defs as uses in df_simulate_defs [PR116564] The PR shows us spinning in dce.cc:fast_dce at the start of combine. This spinning appears to be because of a disagreement between the fast_dce code and the code in df-problems.cc:df_lr_bb_local_compute. Specifically, they disagree on the treatment of partial defs. For the testcase in the PR, we have the following insn in bb 3: (insn 10 8 13 3 (clobber (subreg:V1DF (reg/v:V2x1DF 104 [ __val ]) 8)) -1 (nil)) which gives rise to a DF def with DF_REF_FLAGS = 0x8b0, i.e. DF_REF_PARTIAL | DF_REF_READ_WRITE | DF_REF_MUST_CLOBBER | DF_REF_SUBREG. Eliding the large block comment for readability, the code in df_lr_bb_local_compute does the following (for each insn): FOR_EACH_INSN_INFO_DEF (def, insn_info) { unsigned int dregno = DF_REF_REGNO (def); bitmap_set_bit (&bb_info->def, dregno); if (DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)) bitmap_set_bit (&bb_info->use, dregno); else bitmap_clear_bit (&bb_info->use, dregno); } i.e. it models partial defs as a RMW operation; thus for the def arising from i10 above, it records a use of r104; hence it ends up in the live-in set for bb 3. However, as it stands, the code in dce.cc:fast_dce (and its callee dce_process_block) has no such provision for DF_REF_PARTIAL defs. It does not treat these as a RMW and does not compute r104 above as being live-in to bb 3. At the end of dce_process_block we compute the following "did something happen" condition used to decide termination of the analysis: block_changed = !bitmap_equal_p (local_live, DF_LR_IN (bb)); if (block_changed) bitmap_copy (DF_LR_IN (bb), local_live); BITMAP_FREE (local_live); return block_changed; because of the disagreement between df_lr_local_compute and the local analysis done by fast_dce, we invariably have r104 in DF_LR_IN, but not in local_live. Hence we always return true here, call df_analyze_problem (which re-computes DF_LR_IN according to df_lr_bb_local_compute, re-adding r104), and so the analysis never terminates. This patch therefore adjusts df_simulate_defs (called from dce_process_block) to match the behaviour of df_lr_bb_local_compute in this respect, namely we make it model partial defs as RMW operations by setting the relevant register live. This fixes the spinning in fast_dce for this testcase. gcc/ChangeLog: PR rtl-optimization/116564 * df-problems.cc (df_simulate_defs): For partial defs, mark the register live (treat it as a RMW operation). gcc/testsuite/ChangeLog: PR rtl-optimization/116564 * gcc.target/aarch64/torture/pr116564.c: New test. (cherry picked from commit 758e617bcf224dc9d4a7e26dd858d43c1e63b916) Diff: --- gcc/df-problems.cc | 8 +--- gcc/testsuite/gcc.target/aarch64/torture/pr116564.c | 11 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/gcc/df-problems.cc b/gcc/df-problems.cc index d2cfaf7f50f6..334ecc585646 100644 --- a/gcc/df-problems.cc +++ b/gcc/df-problems.cc @@ -3855,9 +3855,11 @@ df_simulate_defs (rtx_insn *insn, bitmap live) { unsigned int dregno = DF_REF_REGNO (def); - /* If the def is to only part of the reg, it does -not kill the other defs that reach here. */ - if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL))) + /* If the def is to only part of the reg, model it as a RMW operation +by marking it live. It only kills the reg if it is a complete def. */ + if (DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)) + bitmap_set_bit (live, dregno); + else bitmap_clear_bit (live, dregno); } } diff --git a/gcc/testsuite/gcc.target/aarch64/torture/pr116564.c b/gcc/testsuite/gcc.target/aarch64/torture/pr116564.c new file mode 100644 index ..d471e097294c --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/torture/pr116564.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ +#include +void test() +{ + for (int L = 0; L < 4; ++L) { +float64_t ResData[1 * 2]; +float64x1x2_t Src1; +vst2_f64(ResData, Src1); + } +}
[gcc r13-9504] [PATCH v2] RISC-V: Fixbug for slli + addw + zext.w into sh[123]add + zext.w
https://gcc.gnu.org/g:372415181e4c6ab5bd1e32d60e7c2c96824e0cc8 commit r13-9504-g372415181e4c6ab5bd1e32d60e7c2c96824e0cc8 Author: Jin Ma Date: Wed Apr 2 13:37:07 2025 -0600 [PATCH v2] RISC-V: Fixbug for slli + addw + zext.w into sh[123]add + zext.w Assuming we have the following variables: unsigned long long a0, a1; unsigned int a2; For the expression: a0 = (a0 << 50) >> 49; // slli a0, a0, 50 + srli a0, a0, 49 a2 = a1 + a0; // addw a2, a1, a0 + slli a2, a2, 32 + srli a2, a2, 32 In the optimization process of ZBA (combine pass), it would be optimized to: a2 = a0 << 1 + a1; // sh1add a2, a0, a1 + zext.w a2, a2 This is clearly incorrect, as it overlooks the fact that a0=a0&0x7ffe, meaning that the bits a0[32:14] are set to zero. gcc/ChangeLog: * config/riscv/bitmanip.md: The optimization can only be applied if the high bit of operands[3] is set to 1. gcc/testsuite/ChangeLog: * gcc.target/riscv/zba-shNadd-09.c: New test. * gcc.target/riscv/zba-shNadd-10.c: New test. (cherry picked from commit dd6ebc0a3473a830115995bdcaf8f797ebd085a3) Diff: --- gcc/config/riscv/bitmanip.md | 4 +++- gcc/testsuite/gcc.target/riscv/zba-shNadd-09.c | 12 gcc/testsuite/gcc.target/riscv/zba-shNadd-10.c | 21 + 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index 7aa591689ba8..92f4261ba1a3 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -80,7 +80,9 @@ (match_operand:DI 3 "consecutive_bits_operand")) 0) (subreg:SI (match_operand:DI 4 "register_operand") 0] "TARGET_64BIT && TARGET_ZBA - && riscv_shamt_matches_mask_p (INTVAL (operands[2]), INTVAL (operands[3]))" + && riscv_shamt_matches_mask_p (INTVAL (operands[2]), INTVAL (operands[3])) + /* Ensure the mask includes all the bits in SImode. */ + && ((INTVAL (operands[3]) & (HOST_WIDE_INT_1U << 31)) != 0)" [(set (match_dup 0) (plus:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 4))) (set (match_dup 0) (zero_extend:DI (subreg:SI (match_dup 0) 0)))]) diff --git a/gcc/testsuite/gcc.target/riscv/zba-shNadd-09.c b/gcc/testsuite/gcc.target/riscv/zba-shNadd-09.c new file mode 100644 index ..303f3cbb8630 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zba-shNadd-09.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zba -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */ + +long long sub (unsigned long long a, unsigned long long b) +{ + b = (b << 50) >> 49; + unsigned int x = a + b; + return x; +} + +/* { dg-final { scan-assembler-not {\msh1add} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/zba-shNadd-10.c b/gcc/testsuite/gcc.target/riscv/zba-shNadd-10.c new file mode 100644 index ..883cce271ca1 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zba-shNadd-10.c @@ -0,0 +1,21 @@ +/* { dg-do run { target { rv64 } } } */ +/* { dg-options "-march=rv64gc_zba -mabi=lp64d -O2" } */ + +struct { + unsigned a : 14; + unsigned b : 3; +} c; + +unsigned long long d; +void e (unsigned long long *f, long p2) { *f = p2; } +signed g; +long i; + +int main () { + c.b = 4; + i = -(-c.a - (3023282U + c.a + g)); + e (&d, i); + if (d != 3023282) +__builtin_abort (); + __builtin_exit (0); +}
[gcc r15-9392] cobol: Eliminate many getenv() calls. [PR119694]
https://gcc.gnu.org/g:711c10383f494b316c5919aa0141f6fa609578b4 commit r15-9392-g711c10383f494b316c5919aa0141f6fa609578b4 Author: Bob Dubner Date: Fri Apr 11 16:00:42 2025 -0400 cobol: Eliminate many getenv() calls. [PR119694] Many debugging calls to getenv() are eliminated. The debugging calls that remain use gcobol_getenv(...) ). Environment variables available to the user are mostly prefixed "GCOBOL_". gcc/cobol PR cobol/119694 * cbldiag.h: Eliminate getenv() calls. * cdf.y: Likewise. * cobol1.cc: Likewise. * except.cc: Likewise. * genapi.cc: Likewise. * lexio.cc: Likewise. * parse.y: Likewise. * scan_ante.h: Likewise. * show_parse.h: Likewise. * symbols.cc: Likewise. * symfind.cc: Likewise. * util.cc: Likewise. gcc/testsuite PR cobol/119694 * cobol.dg/group2/ACCEPT_DATE___DAY_and_intrinsic_functions__2_.cob: GCOBOL_CURRENT_DATE. * cobol.dg/group2/ACCEPT_FROM_TIME___DATE___DAY___DAY-OF-WEEK__2_.cob: Likewise * cobol.dg/group2/FUNCTION_DATE___TIME_OMNIBUS.cob: Likewise libgcobol PR cobol/119694 * gfileio.cc: Eliminate getenv() calls. * libgcobol.cc: Likewise. Diff: --- gcc/cobol/cbldiag.h| 8 +- gcc/cobol/cdf.y| 2 +- gcc/cobol/cobol1.cc| 2 +- gcc/cobol/except.cc| 4 +- gcc/cobol/genapi.cc| 52 +- gcc/cobol/lexio.cc | 6 +- gcc/cobol/parse.y | 136 gcc/cobol/scan_ante.h | 3 - gcc/cobol/show_parse.h | 3 - gcc/cobol/symbols.cc | 177 + gcc/cobol/symfind.cc | 27 gcc/cobol/util.cc | 35 +--- ...CEPT_DATE___DAY_and_intrinsic_functions__2_.cob | 2 +- ...PT_FROM_TIME___DATE___DAY___DAY-OF-WEEK__2_.cob | 2 +- .../group2/FUNCTION_DATE___TIME_OMNIBUS.cob| 2 +- libgcobol/gfileio.cc | 31 libgcobol/libgcobol.cc | 50 +- 17 files changed, 31 insertions(+), 511 deletions(-) diff --git a/gcc/cobol/cbldiag.h b/gcc/cobol/cbldiag.h index ed754f1203e4..d7ee98f6f25d 100644 --- a/gcc/cobol/cbldiag.h +++ b/gcc/cobol/cbldiag.h @@ -33,6 +33,12 @@ #else #define _CBLDIAG_H +#if 0 +#define gcobol_getenv(x) getenv(x) +#else +#define gcobol_getenv(x) ((char *)nullptr) +#endif + const char * cobol_filename(); /* @@ -101,7 +107,7 @@ template static void location_dump( const char func[], int line, const char tag[], const LOC& loc) { extern int yy_flex_debug; - if( yy_flex_debug && getenv("update_location") ) + if( yy_flex_debug && gcobol_getenv("update_location") ) fprintf(stderr, "%s:%d: %s location (%d,%d) to (%d,%d)\n", func, line, tag, loc.first_line, loc.first_column, loc.last_line, loc.last_column); diff --git a/gcc/cobol/cdf.y b/gcc/cobol/cdf.y index 6392f89d3b13..e06ccf371e9d 100644 --- a/gcc/cobol/cdf.y +++ b/gcc/cobol/cdf.y @@ -226,7 +226,7 @@ apply_cdf_turn( exception_turns_t& turns ) { turns.location, elem.first, files); } - if( getenv("SHOW_PARSE") ) enabled_exceptions.dump(); + if( getenv("GCOBOL_SHOW") ) enabled_exceptions.dump(); return true; } %} diff --git a/gcc/cobol/cobol1.cc b/gcc/cobol/cobol1.cc index 1e690ff4ba54..98d15a8d1eda 100644 --- a/gcc/cobol/cobol1.cc +++ b/gcc/cobol/cobol1.cc @@ -294,7 +294,7 @@ cobol_langhook_init_options_struct (struct gcc_options *opts) { cobol_set_debugging( false, false, false ); - copybook_directory_add( getenv("GCOB_COPYBOOK") ); + copybook_directory_add( getenv("GCOBOL_COPYBOOK") ); } static unsigned int diff --git a/gcc/cobol/except.cc b/gcc/cobol/except.cc index 1485a337ab93..7a6a92225607 100644 --- a/gcc/cobol/except.cc +++ b/gcc/cobol/except.cc @@ -312,11 +312,11 @@ file_status_t current_file_handled_status(); void declarative_runtime_match( cbl_field_t *declaratives, cbl_label_t *lave ) { - if( getenv("SHOW_PARSE") ) + if( getenv("GCOBOL_SHOW") ) { fprintf(stderr, "( %d ) %s: \n", cobol_location().first_line, __func__); } - if( getenv("TRACE1") ) + if( getenv("GCOBOL_TRACE") ) { gg_printf(">>( %d )(%s) declaratives:%s lave:%s\n", build_int_cst_type(INT, cobol_location().first_line), diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index fdf76aad7b14..622387f01a5f 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -75,7 +75,7 @@ static in
[gcc(refs/users/aoliva/heads/testme)] [riscv] vec_dup immediate constants in pred_broadcast expand [PR118182]
https://gcc.gnu.org/g:be268a2c399deb73225d56a2cca20d7f48a0b1ca commit be268a2c399deb73225d56a2cca20d7f48a0b1ca Author: Alexandre Oliva Date: Sat Apr 12 02:43:15 2025 -0300 [riscv] vec_dup immediate constants in pred_broadcast expand [PR118182] pr118182-2.c fails on gcc-14 because it lacks the late_combine passes, particularly the one that runs after register allocation. Even in the trunk, the predicate broadcast for the add reduction is expanded and register-allocated as _zvfh, taking up an unneeded scalar register to hold the constant to be vec_duplicated. It is the late combine pass after register allocation that substitutes this unneeded scalar register into the vec_duplicate, resolving to the _zero or _imm insns. It's easy enough and more efficient to expand pred_broadcast to the insns that take the already-duplicated vector constant, when the operands satisfy the predicates of the _zero or _imm insns. I'm leaving alone the code in the expander that refrains from forcing constants into registers, in the unlikely case it serves any remaining purpose, but I *think* its point was to expand to _zero or _imm; it didn't because those insn patterns don't have vec_duplicate. for gcc/ChangeLog PR target/118182 * config/riscv/vector.md (@pred_broadcast): Expand to _zero and _imm variants without vec_duplicate. Diff: --- gcc/config/riscv/vector.md | 22 -- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/gcc/config/riscv/vector.md b/gcc/config/riscv/vector.md index 51eb64fb1226..3ab4d76e6c6a 100644 --- a/gcc/config/riscv/vector.md +++ b/gcc/config/riscv/vector.md @@ -2136,18 +2136,34 @@ (match_operand 7 "const_int_operand") (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) - (vec_duplicate:V_VLS - (match_operand: 3 "direct_broadcast_operand")) + ;; (vec_duplicate:V_VLS ;; wrapper activated by wrap_vec_dup below. + (match_operand: 3 "direct_broadcast_operand") ;; ) (match_operand:V_VLS 2 "vector_merge_operand")))] "TARGET_VECTOR" { /* Transform vmv.v.x/vfmv.v.f (avl = 1) into vmv.s.x since vmv.s.x/vfmv.s.f has better chances to do vsetvl fusion in vsetvl pass. */ + bool wrap_vec_dup = true; + rtx vec_cst = NULL_RTX; if (riscv_vector::splat_to_scalar_move_p (operands)) { operands[1] = riscv_vector::gen_scalar_move_mask (mode); operands[3] = force_reg (mode, operands[3]); } + else if (immediate_operand (operands[3], mode) + && (vec_cst = gen_const_vec_duplicate (mode, operands[3])) + && (/* -> pred_broadcast_zero */ + (vector_least_significant_set_mask_operand (operands[1], + mode) + && vector_const_0_operand (vec_cst, mode)) + || (/* pred_broadcast_imm */ + vector_all_trues_mask_operand (operands[1], mode) + && vector_const_int_or_double_0_operand (vec_cst, + mode +{ + operands[3] = vec_cst; + wrap_vec_dup = false; +} /* Handle vmv.s.x instruction (Wb1 mask) which has memory scalar. */ else if (satisfies_constraint_Wdm (operands[3])) { @@ -2191,6 +2207,8 @@ ; else operands[3] = force_reg (mode, operands[3]); + if (wrap_vec_dup) +operands[3] = gen_rtx_VEC_DUPLICATE (mode, operands[3]); }) (define_insn_and_split "*pred_broadcast"