[gcc r15-9400] c++: improve constexpr prvalue folding [PR116416]

2025-04-12 Thread Patrick Palka via Gcc-cvs
https://gcc.gnu.org/g:e7bccec33beece4a46bc1b20ed375e803e97aa88

commit r15-9400-ge7bccec33beece4a46bc1b20ed375e803e97aa88
Author: Patrick Palka 
Date:   Sat Apr 12 14:06:56 2025 -0400

c++: improve constexpr prvalue folding [PR116416]

This patch improves upon r15-6052-g12de1942a0a673 by performing prvalue
folding with mce_false rather than mce_unknown when it's safe to do so
(i.e. ff_mce_false is set), so that we can also fold temporary initializers
that call is_constant_evaluated etc.

In passing I noticed constexpr-prvalue1.C could more precisely verify the
optimization happened by inspecting what the front end spits out instead
of inspecting the optimized assembly -- that there's no constructor call
doesn't necessarily imply the constructor has been completely folded away,
only that its body has been inlined.

PR c++/116416

gcc/cp/ChangeLog:

* constexpr.cc (maybe_constant_init_1): Generalize type of
of manifestly_const_eval parameter from bool to mce_value.
(maybe_constant_init): Define 3-parameter version taking a
manifestly_const_eval instead of bool parameter.
(cxx_constant_init): Adjust.
* cp-gimplify.cc (cp_fold_r) : Pass mce_false
to maybe_constant_init during prvalue folding if ff_mce_false is
set.
* cp-tree.h (maybe_constant_init): Declare new overload.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/constexpr-prvalue1.C: Adjust to instead inspect
the 'original' dump.
* g++.dg/cpp1y/constexpr-prvalue1a.C: New test.

Reviewed-by: Jason Merrill 

Diff:
---
 gcc/cp/constexpr.cc  | 16 
 gcc/cp/cp-gimplify.cc|  4 ++-
 gcc/cp/cp-tree.h |  1 +
 gcc/testsuite/g++.dg/cpp1y/constexpr-prvalue1.C  | 12 +
 gcc/testsuite/g++.dg/cpp1y/constexpr-prvalue1a.C | 33 
 5 files changed, 55 insertions(+), 11 deletions(-)

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 497f64f3ceaa..0242425370f4 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -9679,7 +9679,7 @@ fold_non_dependent_init (tree t,
 
 static tree
 maybe_constant_init_1 (tree t, tree decl, bool allow_non_constant,
-  bool manifestly_const_eval)
+  mce_value manifestly_const_eval)
 {
   if (!t)
 return t;
@@ -9709,13 +9709,13 @@ maybe_constant_init_1 (tree t, tree decl, bool 
allow_non_constant,
   bool is_static = (decl && DECL_P (decl)
&& (TREE_STATIC (decl) || DECL_EXTERNAL (decl)));
   if (is_static)
-   manifestly_const_eval = true;
+   manifestly_const_eval = mce_true;
 
-  if (cp_unevaluated_operand && !manifestly_const_eval)
+  if (cp_unevaluated_operand && manifestly_const_eval != mce_true)
return fold_to_constant (t);
 
   t = cxx_eval_outermost_constant_expr (t, allow_non_constant, !is_static,
-   mce_value (manifestly_const_eval),
+   manifestly_const_eval,
false, decl);
 }
   if (TREE_CODE (t) == TARGET_EXPR)
@@ -9731,6 +9731,12 @@ maybe_constant_init_1 (tree t, tree decl, bool 
allow_non_constant,
 
 tree
 maybe_constant_init (tree t, tree decl, bool manifestly_const_eval)
+{
+  return maybe_constant_init_1 (t, decl, true, mce_value 
(manifestly_const_eval));
+}
+
+tree
+maybe_constant_init (tree t, tree decl, mce_value manifestly_const_eval)
 {
   return maybe_constant_init_1 (t, decl, true, manifestly_const_eval);
 }
@@ -9740,7 +9746,7 @@ maybe_constant_init (tree t, tree decl, bool 
manifestly_const_eval)
 tree
 cxx_constant_init (tree t, tree decl)
 {
-  return maybe_constant_init_1 (t, decl, false, true);
+  return maybe_constant_init_1 (t, decl, false, mce_true);
 }
 
 #if 0
diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
index f5625ab0daad..d2423fd1848a 100644
--- a/gcc/cp/cp-gimplify.cc
+++ b/gcc/cp/cp-gimplify.cc
@@ -1483,7 +1483,9 @@ cp_fold_r (tree *stmt_p, int *walk_subtrees, void *data_)
  *walk_subtrees = 0;
  if (!flag_no_inline)
{
- tree folded = maybe_constant_init (init, TARGET_EXPR_SLOT (stmt));
+ tree folded = maybe_constant_init (init, TARGET_EXPR_SLOT (stmt),
+(data->flags & ff_mce_false
+ ? mce_false : mce_unknown));
  if (folded != init && TREE_CONSTANT (folded))
init = folded;
}
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 927f51b116b3..55f986e25c14 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -8837,6 +8837,7 @@ extern void cxx_constant_dtor (tree, 
tree);
 extern tree

[gcc r15-9403] d: Add option to include imported modules in the compilation [PR109023]

2025-04-12 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:9a7b6668f8f79be8fa73982b8b0bde33c1d8c61f

commit r15-9403-g9a7b6668f8f79be8fa73982b8b0bde33c1d8c61f
Author: Iain Buclaw 
Date:   Sat Apr 12 11:13:50 2025 +0200

d: Add option to include imported modules in the compilation [PR109023]

Adds the ability to include imported modules in the compilation, as if
they were given on the command line.  When this option is enabled, all
imported modules are compiled except those that are part of libphobos.

PR d/109023

gcc/d/ChangeLog:

* d-compiler.cc: Include dmd/errors.h.
(Compiler::onImport): Implement.
* d-lang.cc (d_handle_option): Handle -finclude-imports.
(d_parse_file): Run semantic on included imports.
* gdc.texi: Document -finclude-imports.
* lang.opt: Add finclude-imports.
* lang.opt.urls: Regenerate.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/imports/pr109023.d: New test.
* gdc.dg/torture/pr109023.d: New test.

Diff:
---
 gcc/d/d-compiler.cc | 37 +++--
 gcc/d/d-lang.cc | 19 +
 gcc/d/gdc.texi  |  6 
 gcc/d/lang.opt  |  4 +++
 gcc/d/lang.opt.urls |  3 ++
 gcc/testsuite/gdc.dg/torture/imports/pr109023.d |  3 ++
 gcc/testsuite/gdc.dg/torture/pr109023.d |  6 
 7 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/gcc/d/d-compiler.cc b/gcc/d/d-compiler.cc
index 160539d08ae0..e18f5d33e6aa 100644
--- a/gcc/d/d-compiler.cc
+++ b/gcc/d/d-compiler.cc
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 
 #include "dmd/compiler.h"
+#include "dmd/errors.h"
 #include "dmd/expression.h"
 #include "dmd/identifier.h"
 #include "dmd/module.h"
@@ -164,7 +165,39 @@ Compiler::onParseModule (Module *m)
driver intends on compiling the import.  */
 
 bool
-Compiler::onImport (Module *)
+Compiler::onImport (Module *m)
 {
-  return false;
+  if (!includeImports)
+return false;
+
+  if (m->filetype != FileType::d && m->filetype != FileType::c)
+return false;
+
+  /* All imports modules are included except those in the runtime library.  */
+  ModuleDeclaration *md = m->md;
+  if (md && md->id)
+{
+  if (md->packages.length >= 1)
+   {
+ if (!strcmp (md->packages.ptr[0]->toChars (), "core")
+ || !strcmp (md->packages.ptr[0]->toChars (), "std")
+ || !strcmp (md->packages.ptr[0]->toChars (), "gcc")
+ || !strcmp (md->packages.ptr[0]->toChars (), "etc"))
+   return false;
+   }
+  else if (!strcmp (md->id->toChars (), "object"))
+   return false;
+}
+  else if (m->ident)
+{
+  if (!strcmp (m->ident->toChars (), "object"))
+   return false;
+}
+
+  /* This import will be compiled.  */
+  if (global.params.v.verbose)
+message ("compileimport (%s)", m->srcfile.toChars ());
+
+  compiledImports.push (m);
+  return true;
 }
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 0dab76bbfbd5..ec2ea59938c4 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -523,6 +523,10 @@ d_handle_option (size_t scode, const char *arg, 
HOST_WIDE_INT value,
   global.params.ignoreUnsupportedPragmas = value;
   break;
 
+case OPT_finclude_imports:
+  includeImports = true;
+  break;
+
 case OPT_finvariants:
   global.params.useInvariants = value ? CHECKENABLEon : CHECKENABLEoff;
   break;
@@ -1309,6 +1313,21 @@ d_parse_file (void)
   dmd::semantic3 (m, NULL);
 }
 
+  if (includeImports)
+{
+  for (size_t i = 0; i < compiledImports.length; i++)
+   {
+ Module *m = compiledImports[i];
+ gcc_assert (m->isRoot ());
+
+ if (global.params.v.verbose)
+   message ("semantic3 %s", m->toChars ());
+
+ dmd::semantic3 (m, NULL);
+ modules.push (m);
+   }
+}
+
   Module::runDeferredSemantic3 ();
 
   /* Check again, incase semantic3 pass loaded any more modules.  */
diff --git a/gcc/d/gdc.texi b/gcc/d/gdc.texi
index 2cb0c4a62676..3a8bea01050f 100644
--- a/gcc/d/gdc.texi
+++ b/gcc/d/gdc.texi
@@ -277,6 +277,12 @@ Sets @code{__traits(getTargetInfo, "cppStd")} to 
@code{202002}.
 Sets @code{__traits(getTargetInfo, "cppStd")} to @code{202302}.
 @end table
 
+@opindex finclude-imports
+@item -finclude-imports
+Include imported modules in the compilation, as if they were given on the
+command line.  When this option is enabled, all imported modules are compiled
+except those that are part of libphobos.
+
 @opindex finvariants
 @opindex fno-invariants
 @item -fno-invariants
diff --git a/gcc/d/lang.opt b/gcc/d/lang.opt
index 50c6f2f4da4d..298ff5843ef2 100644
--- a/gcc/d/lang.opt
+++ b/gcc/d/lang.opt
@@ -327,6 +327,10 @@ fignore-unknown-pragmas
 D
 Ignore unsupported pragmas.
 
+finc

[gcc r15-9402] d: Fix -fonly= argument only matches when including full path [PR119758]

2025-04-12 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:8a03d014ec096b3e8c9941a6bf724d3daaeeb289

commit r15-9402-g8a03d014ec096b3e8c9941a6bf724d3daaeeb289
Author: Iain Buclaw 
Date:   Sat Apr 12 09:40:24 2025 +0200

d: Fix -fonly= argument only matches when including full path [PR119758]

Using `strcmp' to match the `-fonly=' argument with the input source
file made the feature inflexible to use.  By mistake, the driver was
also found to omit all other modules on the command line as well, which
differed from the documentation on the flag:

Tell the compiler to parse and run semantic analysis on all modules
on the command line, but only generate code for the given argument.

New tests added to check the feature, which didn't exist before.

PR d/119758

gcc/d/ChangeLog:

* d-lang.cc (d_parse_file): Use endswith in test for -fonly= 
argument.
* d-spec.cc (lang_specific_driver): Rework -fonly= and pass all 
input
files to the front-end compiler when the option is seen.

gcc/testsuite/ChangeLog:

* gdc.dg/driver_fonly1.d: New test.
* gdc.dg/driver_fonly2.d: New test.
* gdc.dg/driver_fonly3.d: New test.
* gdc.dg/imports/fonly.d: New test.

Diff:
---
 gcc/d/d-lang.cc  |  6 ++---
 gcc/d/d-spec.cc  | 50 +++-
 gcc/testsuite/gdc.dg/driver_fonly1.d |  2 ++
 gcc/testsuite/gdc.dg/driver_fonly2.d |  8 ++
 gcc/testsuite/gdc.dg/driver_fonly3.d |  8 ++
 gcc/testsuite/gdc.dg/imports/fonly.d |  3 +++
 6 files changed, 51 insertions(+), 26 deletions(-)

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index b3786be3c905..0dab76bbfbd5 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -1085,9 +1085,9 @@ d_parse_file (void)
   /* Buffer for contents of .ddoc files.  */
   OutBuffer ddocbuf;
 
-  /* In this mode, the first file name is supposed to be a duplicate
- of one of the input files.  */
-  if (d_option.fonly && strcmp (d_option.fonly, main_input_filename) != 0)
+  /* In this mode, the main input file is supposed to be the same as the one
+ given by -fonly=.  */
+  if (d_option.fonly && !endswith (main_input_filename, d_option.fonly))
 error ("%<-fonly=%> argument is different from first input file name");
 
   for (size_t i = 0; i < num_in_fnames; i++)
diff --git a/gcc/d/d-spec.cc b/gcc/d/d-spec.cc
index 7f4a779ab72d..c78804812e3f 100644
--- a/gcc/d/d-spec.cc
+++ b/gcc/d/d-spec.cc
@@ -104,8 +104,8 @@ lang_specific_driver (cl_decoded_option 
**in_decoded_options,
   /* The total number of arguments with the new stuff.  */
   unsigned int num_args = 1;
 
-  /* "-fonly" if it appears on the command line.  */
-  const char *only_source_option = 0;
+  /* "-fonly=" if it appears on the command line.  */
+  const char *only_source_arg = 0;
 
   /* Whether the -o option was used.  */
   bool saw_opt_o = false;
@@ -280,13 +280,13 @@ lang_specific_driver (cl_decoded_option 
**in_decoded_options,
 
case OPT_fonly_:
  args[i] |= SKIPOPT;
- only_source_option = decoded_options[i].orig_option_with_args_text;
+ only_source_arg = arg;
 
  if (arg != NULL)
{
- const char *suffix = strrchr (only_source_option, '.');
+ const char *suffix = strrchr (only_source_arg, '.');
  if (suffix == NULL || strcmp (suffix, ".d") != 0)
-   only_source_option = concat (only_source_option, ".d", NULL);
+   only_source_arg = concat (only_source_arg, ".d", NULL);
}
  break;
 
@@ -335,48 +335,52 @@ lang_specific_driver (cl_decoded_option 
**in_decoded_options,
 + (phobos_library != PHOBOS_NOLINK) * 4 + 2;
   new_decoded_options = XNEWVEC (cl_decoded_option, num_args);
 
-  i = 0;
   j = 0;
 
   /* Copy the 0th argument, i.e., the name of the program itself.  */
-  new_decoded_options[j++] = decoded_options[i++];
+  new_decoded_options[j++] = decoded_options[0];
 
   /* NOTE: We start at 1 now, not 0.  */
-  while (i < argc)
+  for (i = 1; i < argc; i++)
 {
   if (args[i] & SKIPOPT)
-   {
- ++i;
- continue;
-   }
-
-  new_decoded_options[j] = decoded_options[i];
+   continue;
 
   if (!saw_libcxx && (args[i] & WITHLIBCXX))
{
- --j;
  saw_libcxx = &decoded_options[i];
+ continue;
}
 
-  if (args[i] & DSOURCE)
+  if (only_source_arg && (args[i] & DSOURCE))
{
- if (only_source_option)
-   --j;
+ if (!endswith (decoded_options[i].arg, only_source_arg))
+   continue;
}
 
-  i++;
+  new_decoded_options[j] = decoded_options[i];
   j++;
 }
 
-  if (only_source_option)
+  if (only_source_arg)
 {
-  const char *only_source_arg = only_source_option + 7;
+  /* Generate -fonly= option, then copy D input sources that were initially
+ski

[gcc(refs/users/ibuclaw/heads/importc)] d: Implement preprocessor for importC

2025-04-12 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:f60bb700835b8548f6f402297388589462e22f8f

commit f60bb700835b8548f6f402297388589462e22f8f
Author: Iain Buclaw 
Date:   Tue May 24 23:03:23 2022 +0200

d: Implement preprocessor for importC

gcc/ChangeLog:

* config/darwin-d.cc (darwin_register_objc_includes): New function.
(darwin_register_frameworks): New function.

gcc/d/ChangeLog:

* Make-lang.in (D_OBJS): Add d/d-preprocess.o.
* d-builtins.cc (covariant_with_builtin_type_p): Match va_list
parameters converted from array to pointer.
* d-lang.cc (d_init_options): Initialize global.preprocess and 
importC
preprocessor.
(d_handle_option): Call d_cpp_handle_option.
* d-tree.h (struct OutBuffer): Add opaque declaration.
(d_cpp_init_options): Add prototype.
(d_cpp_handle_option): Add prototype.
(d_cpp_preprocess): Add prototype.
* lang-specs.h: Forward -D and -U to compiler proper.
* lang.opt: Add -D, -U, -dirafter, -imacros, -include, and -iquote.
* d-preprocess.cc: New file.

Diff:
---
 gcc/config/darwin-d.cc |  35 +++
 gcc/d/Make-lang.in |   1 +
 gcc/d/d-builtins.cc|  12 +-
 gcc/d/d-lang.cc|  15 +-
 gcc/d/d-preprocess.cc  | 755 +
 gcc/d/d-tree.h |   7 +
 gcc/d/lang-specs.h |   2 +-
 gcc/d/lang.opt |  24 ++
 8 files changed, 848 insertions(+), 3 deletions(-)

diff --git a/gcc/config/darwin-d.cc b/gcc/config/darwin-d.cc
index e23a6cd12708..0afb3d281136 100644
--- a/gcc/config/darwin-d.cc
+++ b/gcc/config/darwin-d.cc
@@ -74,3 +74,38 @@ darwin_d_register_target_info (void)
 #define TARGET_D_MINFO_SECTION_END "*section$end$__DATA$__minfodata"
 
 struct gcc_targetdm targetdm = TARGETDM_INITIALIZER;
+
+/* Provide stubs for the hooks defined by darwin.h
+ TARGET_EXTRA_PRE_INCLUDES, TARGET_EXTRA_INCLUDES
+
+   As both, gcc and gdc link in incpath.o, we cannot conditionally undefine 
said
+   hooks if D is build.  However, we can define do-nothing stubs of said hooks
+   as we are not interested in objc include files in D.
+
+   The hooks original purpose (see also darwin-c.cc):
+* darwin_register_objc_includes
+  Register the GNU objective-C runtime include path if STDINC.
+
+* darwin_register_frameworks
+  Register all the system framework paths if STDINC is true and setup
+  the missing_header callback for subframework searching if any
+  frameworks had been registered.  */
+
+/* Prototypes for functions below to avoid a lengthy list of includes
+   to achieve the same.  */
+void darwin_register_objc_includes (const char *, const char *, int);
+void darwin_register_frameworks (const char *, const char *, int);
+
+void
+darwin_register_objc_includes (const char *sysroot ATTRIBUTE_UNUSED,
+  const char *iprefix ATTRIBUTE_UNUSED,
+  int stdinc ATTRIBUTE_UNUSED)
+{
+}
+
+void
+darwin_register_frameworks (const char *sysroot ATTRIBUTE_UNUSED,
+   const char *iprefix ATTRIBUTE_UNUSED,
+   int stdinc ATTRIBUTE_UNUSED)
+{
+}
diff --git a/gcc/d/Make-lang.in b/gcc/d/Make-lang.in
index 2d444c999530..0292f6e4ccf2 100644
--- a/gcc/d/Make-lang.in
+++ b/gcc/d/Make-lang.in
@@ -225,6 +225,7 @@ D_OBJS = \
d/d-lang.o \
d/d-longdouble.o \
d/d-port.o \
+   d/d-preprocess.o \
d/d-target.o \
d/decl.o \
d/expr.o \
diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index 9c146459d574..1ed0f0577236 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -758,7 +758,17 @@ covariant_with_builtin_type_p (Type *t1, Type *t2)
  || fparam1->isLazy () != fparam2->isLazy ())
return false;
 
-  if (!matches_builtin_type (fparam1->type, fparam2->type))
+  /* va_list array parameters are implicitly converted to pointers.  */
+  Type *fptype1 = fparam1->type;
+  Type *fptype2 = fparam2->type;
+
+  if (valist_array_p (fptype1))
+   fptype1 = dmd::pointerTo (fptype1->nextOf ());
+
+  if (valist_array_p (fptype2))
+   fptype2 = dmd::pointerTo (fptype2->nextOf ());
+
+  if (!matches_builtin_type (fptype1, fptype2))
return false;
 }
 
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index ec2ea59938c4..b88748d547e6 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -285,7 +285,8 @@ deps_write (Module *module, obstack *buffer)
the option handlers.  */
 
 static void
-d_init_options (unsigned int, cl_decoded_option *decoded_options)
+d_init_options (unsigned int decoded_options_count,
+   cl_decoded_option *decoded_options)
 {
   /* Initialize the D runtime.  */
   rt_init ();
@@ -300,6 +301,8 @@ d_init_options (unsigned int, cl_decoded_option 
*decoded_options)
   /* Default extern(C++) mangling to C++17.  */
   global.params.cp

[gcc] Created branch 'ibuclaw/heads/importc' in namespace 'refs/users'

2025-04-12 Thread Iain Buclaw via Gcc-cvs
The branch 'ibuclaw/heads/importc' was created in namespace 'refs/users' 
pointing to:

 f60bb700835b... d: Implement preprocessor for importC


[gcc(refs/users/ibuclaw/heads/gdcflags)] Makefile.tpl: Implement per-stage GDCFLAGS [PR116975]

2025-04-12 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:714e6e3450715b98a2c35b317f99b20916e7de49

commit 714e6e3450715b98a2c35b317f99b20916e7de49
Author: Iain Buclaw 
Date:   Mon Mar 3 22:38:26 2025 +0100

Makefile.tpl: Implement per-stage GDCFLAGS [PR116975]

Allows the GDCFLAGS for each bootstrap stage of building gdc to be
overriden, as is the case with CXXFLAGS for other front-ends.

PR d/116975

ChangeLog:

* Makefile.in: Regenerate.
* Makefile.tpl (STAGE[+id+]_GDCFLAGS): New.
(STAGE2_GDCFLAGS): Add -fno-checking.
(STAGE3_GDCFLAGS): Add -fchecking=1.
(BASE_FLAGS_TO_PASS): Pass STAGE[+id+]_GDCFLAGS down.
(configure-stage[+id+]-[+prefix+][+module+]): Set GDCFLAGS for all 
gcc
module stages.
(all-stage[+id+]-[+prefix+][+module+]): Likewise.

Diff:
---
 Makefile.in  | 51 +++
 Makefile.tpl | 15 +--
 2 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 87880c62ad20..f2c632c06b38 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -619,6 +619,26 @@ STAGE1_CONFIGURE_FLAGS = $(STAGE1_CHECKING) \
  --disable-build-format-warnings
 
 @if target-libphobos-bootstrap
+# Defaults for each stage if we're bootstrapping D.
+
+STAGE1_GDCFLAGS = $(GDCFLAGS)
+
+STAGE2_GDCFLAGS = $(GDCFLAGS)
+
+STAGE3_GDCFLAGS = $(GDCFLAGS)
+
+STAGE4_GDCFLAGS = $(GDCFLAGS)
+
+STAGEprofile_GDCFLAGS = $(GDCFLAGS)
+
+STAGEtrain_GDCFLAGS = $(GDCFLAGS)
+
+STAGEfeedback_GDCFLAGS = $(GDCFLAGS)
+
+STAGEautoprofile_GDCFLAGS = $(GDCFLAGS)
+
+STAGEautofeedback_GDCFLAGS = $(GDCFLAGS)
+
 STAGE1_CONFIGURE_FLAGS += --with-libphobos-druntime-only
 STAGE2_CONFIGURE_FLAGS += --with-libphobos-druntime-only
 @endif target-libphobos-bootstrap
@@ -632,6 +652,10 @@ STAGE2_CFLAGS += -fno-checking
 STAGE2_TFLAGS += -fno-checking
 STAGE3_CFLAGS += -fchecking=1
 STAGE3_TFLAGS += -fchecking=1
+@if target-libphobos-bootstrap
+STAGE2_GDCFLAGS += -fno-checking
+STAGE3_GDCFLAGS += -fchecking=1
+@endif target-libphobos-bootstrap
 
 STAGEprofile_CFLAGS = $(STAGE2_CFLAGS) -fprofile-generate
 STAGEprofile_TFLAGS = $(STAGE2_TFLAGS)
@@ -921,38 +945,47 @@ BASE_FLAGS_TO_PASS = \
"LEAN=$(LEAN)" \
"STAGE1_CFLAGS=$(STAGE1_CFLAGS)" \
"STAGE1_CXXFLAGS=$(STAGE1_CXXFLAGS)" \
+   "STAGE1_GDCFLAGS=$(STAGE1_GDCFLAGS)" \
"STAGE1_GENERATOR_CFLAGS=$(STAGE1_GENERATOR_CFLAGS)" \
"STAGE1_TFLAGS=$(STAGE1_TFLAGS)" \
"STAGE2_CFLAGS=$(STAGE2_CFLAGS)" \
"STAGE2_CXXFLAGS=$(STAGE2_CXXFLAGS)" \
+   "STAGE2_GDCFLAGS=$(STAGE2_GDCFLAGS)" \
"STAGE2_GENERATOR_CFLAGS=$(STAGE2_GENERATOR_CFLAGS)" \
"STAGE2_TFLAGS=$(STAGE2_TFLAGS)" \
"STAGE3_CFLAGS=$(STAGE3_CFLAGS)" \
"STAGE3_CXXFLAGS=$(STAGE3_CXXFLAGS)" \
+   "STAGE3_GDCFLAGS=$(STAGE3_GDCFLAGS)" \
"STAGE3_GENERATOR_CFLAGS=$(STAGE3_GENERATOR_CFLAGS)" \
"STAGE3_TFLAGS=$(STAGE3_TFLAGS)" \
"STAGE4_CFLAGS=$(STAGE4_CFLAGS)" \
"STAGE4_CXXFLAGS=$(STAGE4_CXXFLAGS)" \
+   "STAGE4_GDCFLAGS=$(STAGE4_GDCFLAGS)" \
"STAGE4_GENERATOR_CFLAGS=$(STAGE4_GENERATOR_CFLAGS)" \
"STAGE4_TFLAGS=$(STAGE4_TFLAGS)" \
"STAGEprofile_CFLAGS=$(STAGEprofile_CFLAGS)" \
"STAGEprofile_CXXFLAGS=$(STAGEprofile_CXXFLAGS)" \
+   "STAGEprofile_GDCFLAGS=$(STAGEprofile_GDCFLAGS)" \
"STAGEprofile_GENERATOR_CFLAGS=$(STAGEprofile_GENERATOR_CFLAGS)" \
"STAGEprofile_TFLAGS=$(STAGEprofile_TFLAGS)" \
"STAGEtrain_CFLAGS=$(STAGEtrain_CFLAGS)" \
"STAGEtrain_CXXFLAGS=$(STAGEtrain_CXXFLAGS)" \
+   "STAGEtrain_GDCFLAGS=$(STAGEtrain_GDCFLAGS)" \
"STAGEtrain_GENERATOR_CFLAGS=$(STAGEtrain_GENERATOR_CFLAGS)" \
"STAGEtrain_TFLAGS=$(STAGEtrain_TFLAGS)" \
"STAGEfeedback_CFLAGS=$(STAGEfeedback_CFLAGS)" \
"STAGEfeedback_CXXFLAGS=$(STAGEfeedback_CXXFLAGS)" \
+   "STAGEfeedback_GDCFLAGS=$(STAGEfeedback_GDCFLAGS)" \
"STAGEfeedback_GENERATOR_CFLAGS=$(STAGEfeedback_GENERATOR_CFLAGS)" \
"STAGEfeedback_TFLAGS=$(STAGEfeedback_TFLAGS)" \
"STAGEautoprofile_CFLAGS=$(STAGEautoprofile_CFLAGS)" \
"STAGEautoprofile_CXXFLAGS=$(STAGEautoprofile_CXXFLAGS)" \
+   "STAGEautoprofile_GDCFLAGS=$(STAGEautoprofile_GDCFLAGS)" \

"STAGEautoprofile_GENERATOR_CFLAGS=$(STAGEautoprofile_GENERATOR_CFLAGS)" \
"STAGEautoprofile_TFLAGS=$(STAGEautoprofile_TFLAGS)" \
"STAGEautofeedback_CFLAGS=$(STAGEautofeedback_CFLAGS)" \
"STAGEautofeedback_CXXFLAGS=$(STAGEautofeedback_CXXFLAGS)" \
+   "STAGEautofeedback_GDCFLAGS=$(STAGEautofeedback_GDCFLAGS)" \

"STAGEautofeedback_GENERATOR_CFLAGS=$(STAGEautofeedback_GENERATOR_CFLAGS)" \
"STAGEautofeedback_TFLAGS=$(STAGEautofeedback_TFLAGS)" \
$(CXX_FOR_TARGET_FLAG_TO_PASS) \
@@ -12133,6 +12166,7 @@ configure-stage1-gcc:
$(HOST_EXPORTS) \
CFLAGS="$(STAGE1_CFLAGS)"; expo

[gcc] Created branch 'ibuclaw/heads/gdcflags' in namespace 'refs/users'

2025-04-12 Thread Iain Buclaw via Gcc-cvs
The branch 'ibuclaw/heads/gdcflags' was created in namespace 'refs/users' 
pointing to:

 714e6e345071... Makefile.tpl: Implement per-stage GDCFLAGS [PR116975]


[gcc(refs/users/ibuclaw/heads/gdc)] d: testsuite: Update documentation about subdirectories of gdc.dg

2025-04-12 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:9b711cfef2270e74fa81aec4b0bce509ded800f6

commit 9b711cfef2270e74fa81aec4b0bce509ded800f6
Author: Iain Buclaw 
Date:   Fri Jan 31 10:16:50 2025 +0100

d: testsuite: Update documentation about subdirectories of gdc.dg

gcc/testsuite/ChangeLog:

* gdc.test/README.gcc: Update.
* gdc.dg/README: New file.

Diff:
---
 gcc/testsuite/gdc.dg/README   | 20 
 gcc/testsuite/gdc.test/README.gcc |  1 +
 2 files changed, 21 insertions(+)

diff --git a/gcc/testsuite/gdc.dg/README b/gcc/testsuite/gdc.dg/README
new file mode 100644
index ..55ccc3efa318
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/README
@@ -0,0 +1,20 @@
+The tests in testsuite/gdc.dg are for checking options, code generation and PRs
+specific to the D front-end.
+
+Subdirectories:
+
+analyzerTests for AddressSanitizer support.
+asanTests for analyzer support.
+debug   Tests for debugging options.
+extern-c++  Tests for ABI compatibility with C++.
+gcovTests for GCOV (code coverage) support.
+lto Tests for Link Time Optimization.
+torture Tests for code generation at all optimization levels.
+ubsan   Tests for UndefinedBehaviorSanitizer support.
+
+
+Copyright (C) 2025 Free Software Foundation, Inc.
+
+Copying and distribution of this file, with or without modification,
+are permitted in any medium without royalty provided the copyright
+notice and this notice are preserved.
diff --git a/gcc/testsuite/gdc.test/README.gcc 
b/gcc/testsuite/gdc.test/README.gcc
index 984da5e3a571..de191f703eb9 100644
--- a/gcc/testsuite/gdc.test/README.gcc
+++ b/gcc/testsuite/gdc.test/README.gcc
@@ -9,6 +9,7 @@ The following directories are part of DMD:
   compilable/
   fail_compilation/
   runnable/
+  runnable_cxx/
 
 All changes to dmd should go through the upstream repository first,
 then merged back to GCC.


[gcc r15-9396] tailc, expand: Small incremental tweak to tail call dump [PR119718]

2025-04-12 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:7e91bba6d53899689b00bd0c995b35f6586fcacd

commit r15-9396-g7e91bba6d53899689b00bd0c995b35f6586fcacd
Author: Jakub Jelinek 
Date:   Sat Apr 12 13:12:56 2025 +0200

tailc, expand: Small incremental tweak to tail call dump [PR119718]

Here is an optional incremental tweak to the previous patch.
Instead of

./xgcc -B ./ -S -O2 -fdump-{tree-tailc,rtl-expand}-details pr119718.c ; 
grep -B1 '^\(;; \)\?Cannot tail-call:' pr119718.c.*
pr119718.c.222t.tailc-_7 = bar (0);
pr119718.c.222t.tailc:Cannot tail-call: call invocation refers to locals
--
pr119718.c.270r.expand-;; foo (1, 2, 3, 4, 5, 6, 7) [tail call]
pr119718.c.270r.expand:;; Cannot tail-call: callee required more stack 
slots than the caller

this dumps

./xgcc -B ./ -S -O2 -fdump-{tree-tailc,rtl-expand}-details pr119718.c ; 
grep '^\(;; \)\?Cannot tail-call:' pr119718.c.*
pr119718.c.222t.tailc:Cannot tail-call: call invocation refers to locals: 
_7 = bar (0);
pr119718.c.270r.expand:;; Cannot tail-call: callee required more stack 
slots than the caller: foo (1, 2, 3, 4, 5, 6, 7) [tail call]

2025-04-12  Jakub Jelinek  

PR tree-optimization/119718
* tree-tailcall.cc (maybe_error_musttail): Dump the GIMPLE at the
end of the Cannot tail-call line rather than on the line before it.
* calls.cc (maybe_complain_about_tail_call): Dump the GENERIC
at the end of the ;; Cannot tail-call line rather than on the
line before it.

Diff:
---
 gcc/calls.cc | 4 ++--
 gcc/tree-tailcall.cc | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/calls.cc b/gcc/calls.cc
index dac953745993..372fab317f6f 100644
--- a/gcc/calls.cc
+++ b/gcc/calls.cc
@@ -1282,9 +1282,9 @@ maybe_complain_about_tail_call (tree call_expr, const 
char *reason)
   && dump_file
   && (dump_flags & TDF_DETAILS))
 {
-  fprintf (dump_file, ";; ");
+  fprintf (dump_file, ";; Cannot tail-call: %s: ", reason);
   print_generic_expr (dump_file, call_expr, TDF_SLIM);
-  fprintf (dump_file, "\n;; Cannot tail-call: %s\n", reason);
+  fprintf (dump_file, "\n");
 }
 }
 
diff --git a/gcc/tree-tailcall.cc b/gcc/tree-tailcall.cc
index 5949e0822a4e..d5c4c7bf2671 100644
--- a/gcc/tree-tailcall.cc
+++ b/gcc/tree-tailcall.cc
@@ -494,8 +494,8 @@ maybe_error_musttail (gcall *call, const char *err, bool 
diag_musttail)
 }
   if (dump_file && (dump_flags & TDF_DETAILS))
 {
+  fprintf (dump_file, "Cannot tail-call: %s: ", err);
   print_gimple_stmt (dump_file, call, 0, TDF_SLIM);
-  fprintf (dump_file, "Cannot tail-call: %s\n", err);
 }
 }


[gcc r15-9395] tailc, expand: Tail call -fdump-{tree-tailc, expand-details} changes [PR119718]

2025-04-12 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:0562e17bd04b65aebff4721db05631b9f34af146

commit r15-9395-g0562e17bd04b65aebff4721db05631b9f34af146
Author: Jakub Jelinek 
Date:   Sat Apr 12 13:11:59 2025 +0200

tailc, expand: Tail call -fdump-{tree-tailc,expand-details} changes 
[PR119718]

The following patch makes some adjustments so that users can analyze what
calls weren't tail called even without using musttail attribute (though I'm
still not convinced it should be a warning, because we don't distinguish
between calls in return call (...); statements vs. calls that just happened
to end up in tail positions because something has been optimized away etc.

E.g. for
int foo (int, int, int, int, int, int, int);
int bar (int);
void qux (int *);

int
baz (int x)
{
  if (x)
return foo (1, 2, 3, 4, 5, 6, 7);
  else
{
  int y;
  qux (&y);
  return bar (x);
}
}
./xgcc -B ./ -S -O2 -fdump-{tree-tailc,rtl-expand}-details pr119718.c ; 
grep -B1 '^\(;; \)\?Cannot tail-call:' pr119718.c.*
pr119718.c.222t.tailc-_7 = bar (0);
pr119718.c.222t.tailc:Cannot tail-call: call invocation refers to locals
--
pr119718.c.270r.expand-;; foo (1, 2, 3, 4, 5, 6, 7) [tail call]
pr119718.c.270r.expand:;; Cannot tail-call: callee required more stack 
slots than the caller

The changes are:
1) in tailc pass use wording more consistent with the musttail error wording
2) do it only in *-details dump
3) add similar diagnostics on the expand side, but this time only for the
   CALL_EXPR_TAILCALL calls, if something wasn't marked that way, it is up
   to tailc pass to emit message about it, if it was and it still can't be
   tail called, let it tell users about that; in this case I need
   to use the ;; prefix because it will appear in the middle of
   the IL dump and ;; is what is used for such purposes in other spots
4) I've tried to improve formatting of the maybe_error_musttail and
   maybe_complain_about_tail_call calls

2025-04-12  Jakub Jelinek  

PR tree-optimization/119718
* tree-tailcall.cc (maybe_error_musttail): Only dump into dump_file
if dump_flags & TDF_DETAILS.  Use "Cannot tail-call: " prefix 
instead
of "Cannot convert: ".
(find_tail_calls, tree_optimize_tail_calls_1): Formatting fixes
for maybe_error_musttail calls.
* calls.cc (maybe_complain_about_tail_call): Emit also a message
into dump_file when dump_flags & TDF_DETAILS for CALL_EXPR_TAILCALL
calls.
(initialize_argument_information): Formatting fix for
maybe_complain_about_tail_call calls.
(can_implement_as_sibling_call_p, expand_call): Likewise.

Diff:
---
 gcc/calls.cc | 62 
 gcc/tree-tailcall.cc | 54 +++--
 2 files changed, 56 insertions(+), 60 deletions(-)

diff --git a/gcc/calls.cc b/gcc/calls.cc
index b3dccd85ec8e..dac953745993 100644
--- a/gcc/calls.cc
+++ b/gcc/calls.cc
@@ -1273,11 +1273,19 @@ void
 maybe_complain_about_tail_call (tree call_expr, const char *reason)
 {
   gcc_assert (TREE_CODE (call_expr) == CALL_EXPR);
-  if (!CALL_EXPR_MUST_TAIL_CALL (call_expr))
-return;
-
-  error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason);
-  CALL_EXPR_MUST_TAIL_CALL (call_expr) = 0;
+  if (CALL_EXPR_MUST_TAIL_CALL (call_expr))
+{
+  error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason);
+  CALL_EXPR_MUST_TAIL_CALL (call_expr) = 0;
+}
+  if (CALL_EXPR_TAILCALL (call_expr)
+  && dump_file
+  && (dump_flags & TDF_DETAILS))
+{
+  fprintf (dump_file, ";; ");
+  print_generic_expr (dump_file, call_expr, TDF_SLIM);
+  fprintf (dump_file, "\n;; Cannot tail-call: %s\n", reason);
+}
 }
 
 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
@@ -1447,10 +1455,10 @@ initialize_argument_information (int num_actuals 
ATTRIBUTE_UNUSED,
  if (!call_from_thunk_p && DECL_P (base) && !TREE_STATIC (base))
{
  *may_tailcall = false;
- maybe_complain_about_tail_call (exp,
- _("a callee-copied argument 
is"
-   " stored in the current"
-   " function's frame"));
+ maybe_complain_about_tail_call (exp, _("a callee-copied "
+"argument is stored "
+"in the current "
+"function's frame"));
}
 
  args[i].tree_value = build_fold_addr_expr_loc (loc,
@@ -2534,10 +2542,9 @@ can_imp

[gcc r15-9397] bitintlower: Fix up handling of SSA_NAME copies in coalescing [PR119722]

2025-04-12 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:3f9dfb94eab1ab1bbf9a2b5e20d1f61e36516063

commit r15-9397-g3f9dfb94eab1ab1bbf9a2b5e20d1f61e36516063
Author: Jakub Jelinek 
Date:   Sat Apr 12 13:13:53 2025 +0200

bitintlower: Fix up handling of SSA_NAME copies in coalescing [PR119722]

The following patch is miscompiled, because during the limited
SSA name coalescing the bitintlower pass does we incorrectly don't
register a conflict.
This is on
   [local count: 1073741824]:
  # b_17 = PHI 
  g.4_13 = g;
  _14 = g.4_13 >> 50;
  _15 = (unsigned int) _14;
  _21 = b_17;
  _16 = (unsigned int) _21;
  s_22 = _15 + _16;
  return s_22;
basic block where in the map->bitint bitmap we track 14, 17 and 19.
The build_bitint_stmt_ssa_conflicts "hook" has special code where
it tracks uses at the final statements of mergeable operations, so
e.g. the
  _16 = (unsigned int) _21;
statement is considered to be use of b_17 because _21 is not in
map->bitmap (or large_huge.m_names), i.e. is mergeable.
The problem is that build_ssa_conflict_graph has special code to handle
SSA_NAME copies and _21 = b_17; is gimple_assign_copy_p.  In such cases
it calls live_track_clear_var on the rhs1.  The problem is that
on the above bb, after we note in the _16 = (unsigned int) _21;
stmt we need b_17 the generic code makes us forget that because
of the copy statement, and then build_bitint_stmt_ssa_conflicts
ignores it completely (because _21 is large/huge bitint and is
not in map->bitint, so assumed to be handled by a later stmt in the
bb, for backwards walk like this before this one).
As the b_17 use is ignored, the coalescing thinks it can put
all of b_17, b_19 and _14 into the same partition, which is wrong,
while we can and should coalesce b_17 and b_19, _14 needs to be a different
temporary because b_17 is set before and used after _14 has been written.

The following patch fixes it by handling gimple_assign_copy_p in two
separate spots, move the generic coalesce handling of it after
build_ssa_conflict_graph (where build_ssa_conflict_graph handling
doesn't fall through to that, it does continue after the call) and
inside of build_ssa_conflict_graph it performs it too, but only if
the lhs is not mergeable large/huge bitint.

2025-04-12  Jakub Jelinek  

PR tree-optimization/119722
* gimple-lower-bitint.h (build_bitint_stmt_ssa_conflicts): Add
CLEAR argument.
* gimple-lower-bitint.cc (build_bitint_stmt_ssa_conflicts): Add
CLEAR argument.  Call clear on gimple_assign_copy_p rhs1 if lhs
is large/huge bitint unless lhs is not in names.
* tree-ssa-coalesce.cc (build_ssa_conflict_graph): Adjust
build_bitint_stmt_ssa_conflicts caller.  Move gimple_assign_copy_p
handling to after the build_bitint_stmt_ssa_conflicts call.

* gcc.dg/torture/bitint-77.c: New test.

Diff:
---
 gcc/gimple-lower-bitint.cc   | 22 +-
 gcc/gimple-lower-bitint.h|  1 +
 gcc/testsuite/gcc.dg/torture/bitint-77.c | 26 ++
 gcc/tree-ssa-coalesce.cc | 22 --
 4 files changed, 60 insertions(+), 11 deletions(-)

diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index 342581667ae9..c52a6577935d 100644
--- a/gcc/gimple-lower-bitint.cc
+++ b/gcc/gimple-lower-bitint.cc
@@ -5919,7 +5919,8 @@ build_bitint_stmt_ssa_conflicts (gimple *stmt, live_track 
*live,
 ssa_conflicts *graph, bitmap names,
 void (*def) (live_track *, tree,
  ssa_conflicts *),
-void (*use) (live_track *, tree))
+void (*use) (live_track *, tree),
+void (*clear) (live_track *, tree))
 {
   bool muldiv_p = false;
   tree lhs = NULL_TREE;
@@ -5936,6 +5937,25 @@ build_bitint_stmt_ssa_conflicts (gimple *stmt, 
live_track *live,
{
  if (!bitmap_bit_p (names, SSA_NAME_VERSION (lhs)))
return;
+
+ /* A copy between 2 partitions does not introduce an interference
+by itself.  If they did, you would never be able to coalesce
+two things which are copied.  If the two variables really do
+conflict, they will conflict elsewhere in the program.
+
+This is handled by simply removing the SRC of the copy from
+the live list, and processing the stmt normally.
+
+Don't do this if lhs is not in names though, in such cases
+it is actually used at some point later in the basic
+block.  */
+ if (gimple_assign_copy_p (stmt))
+   {
+ 

[gcc r15-9398] driver: Fix up -freport-bug for ASLR [PR119727]

2025-04-12 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:8b2ceb421f045ee8b39d7941f39f1e9a67217583

commit r15-9398-g8b2ceb421f045ee8b39d7941f39f1e9a67217583
Author: Jakub Jelinek 
Date:   Sat Apr 12 13:15:13 2025 +0200

driver: Fix up -freport-bug for ASLR [PR119727]

With --enable-host-pie -freport-bug almost never prepares preprocessed
source and instead emits
The bug is not reproducible, so it is likely a hardware or OS problem.
message even for bogus which are 100% reproducible.
The way -freport-bug works is that it reruns it 3 times, capturing stdout
and stderr from each and then tries to compare the outputs in between
different runs.
The libbacktrace emitted hexadecimal addresses at the start of the lines
can differ between runs due to ASLR, either of the PIE executable, or
even if not PIE if there is some frame with e.g. libc function (say
crash in strlen/memcpy etc.).

The following patch fixes it by ignoring such differences at the start of
the lines.

2025-04-12  Jakub Jelinek  

PR driver/119727
* gcc.cc (files_equal_p): Rewritten using fopen/fgets/fclose instead
of open/fstat/read/close.  At the start of lines, ignore lowercase
hexadecimal addresses followed by space.

Diff:
---
 gcc/gcc.cc | 73 --
 1 file changed, 38 insertions(+), 35 deletions(-)

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index aac33e91a9a0..9064671b86cf 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -7744,55 +7744,58 @@ print_configuration (FILE *file)
 
 #define RETRY_ICE_ATTEMPTS 3
 
-/* Returns true if FILE1 and FILE2 contain equivalent data, 0 otherwise.  */
+/* Returns true if FILE1 and FILE2 contain equivalent data, 0 otherwise.
+   If lines start with 0x followed by 1-16 lowercase hexadecimal digits
+   followed by a space, ignore anything before that space.  These are
+   typically function addresses from libbacktrace and those can differ
+   due to ASLR.  */
 
 static bool
 files_equal_p (char *file1, char *file2)
 {
-  struct stat st1, st2;
-  off_t n, len;
-  int fd1, fd2;
-  const int bufsize = 8192;
-  char *buf = XNEWVEC (char, bufsize);
+  FILE *f1 = fopen (file1, "rb");
+  FILE *f2 = fopen (file2, "rb");
+  char line1[256], line2[256];
 
-  fd1 = open (file1, O_RDONLY);
-  fd2 = open (file2, O_RDONLY);
-
-  if (fd1 < 0 || fd2 < 0)
-goto error;
-
-  if (fstat (fd1, &st1) < 0 || fstat (fd2, &st2) < 0)
-goto error;
-
-  if (st1.st_size != st2.st_size)
-goto error;
-
-  for (n = st1.st_size; n; n -= len)
+  bool line_start = true;
+  while (fgets (line1, sizeof (line1), f1))
 {
-  len = n;
-  if ((int) len > bufsize / 2)
-   len = bufsize / 2;
-
-  if (read (fd1, buf, len) != (int) len
- || read (fd2, buf + bufsize / 2, len) != (int) len)
+  if (!fgets (line2, sizeof (line2), f2))
+   goto error;
+  char *p1 = line1, *p2 = line2;
+  if (line_start
+ && line1[0] == '0'
+ && line1[1] == 'x'
+ && line2[0] == '0'
+ && line2[1] == 'x')
{
- goto error;
+ int i, j;
+ for (i = 0; i < 16; ++i)
+   if (!ISXDIGIT (line1[2 + i]) || ISUPPER (line1[2 + i]))
+ break;
+ for (j = 0; j < 16; ++j)
+   if (!ISXDIGIT (line2[2 + j]) || ISUPPER (line2[2 + j]))
+ break;
+ if (i && line1[2 + i] == ' ' && j && line2[2 + j] == ' ')
+   {
+ p1 = line1 + i + 3;
+ p2 = line2 + j + 3;
+   }
}
-
-  if (memcmp (buf, buf + bufsize / 2, len) != 0)
+  if (strcmp (p1, p2) != 0)
goto error;
+  line_start = strchr (line1, '\n') != NULL;
 }
+  if (fgets (line2, sizeof (line2), f2))
+goto error;
 
-  free (buf);
-  close (fd1);
-  close (fd2);
-
+  fclose (f1);
+  fclose (f2);
   return 1;
 
 error:
-  free (buf);
-  close (fd1);
-  close (fd2);
+  fclose (f1);
+  fclose (f2);
   return 0;
 }


[gcc r15-9393] Fortran: Add code gen for do, concurrent's LOCAL/LOCAL_INIT: Fix 'static_assert' [PR101602]

2025-04-12 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:f417af3f9f94538c2600e78e6c60b61c29fdbf99

commit r15-9393-gf417af3f9f94538c2600e78e6c60b61c29fdbf99
Author: Thomas Schwinge 
Date:   Sat Apr 12 10:53:14 2025 +0200

Fortran: Add code gen for do,concurrent's LOCAL/LOCAL_INIT: Fix 
'static_assert' [PR101602]

Fix-up for commit 2d7e1d6e40a13a5f160b584336795b80f193ec3b
"Fortran: Add code gen for do,concurrent's LOCAL/LOCAL_INIT [PR101602]":

../../source-gcc/gcc/fortran/trans-stmt.cc: In function ‘void 
gfc_trans_concurrent_locality_spec(bool, stmtblock_t*, 
std::vector*, gfc_expr_list**)’:
../../source-gcc/gcc/fortran/trans-stmt.cc:5157:59: error: expected ‘,’ 
before ‘)’ token
   static_assert (LOCALITY_LOCAL_INIT - LOCALITY_LOCAL == 1);
   ^
../../source-gcc/gcc/fortran/trans-stmt.cc:5157:59: error: expected 
string-literal before ‘)’ token
make[2]: *** [Makefile:1210: fortran/trans-stmt.o] Error 1

PR fortran/101602
gcc/fortran/
* trans-stmt.cc (gfc_trans_concurrent_locality_spec): Fix
'static_assert'.

Diff:
---
 gcc/fortran/trans-stmt.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc
index 94ecde096d58..37f8acaea3f6 100644
--- a/gcc/fortran/trans-stmt.cc
+++ b/gcc/fortran/trans-stmt.cc
@@ -5154,7 +5154,7 @@ gfc_trans_concurrent_locality_spec (bool after_body, 
stmtblock_t *body,
   gfc_start_saved_local_decls ();
 
   cnt = 0;
-  static_assert (LOCALITY_LOCAL_INIT - LOCALITY_LOCAL == 1);
+  static_assert (LOCALITY_LOCAL_INIT - LOCALITY_LOCAL == 1, "locality_type");
   for (int type = LOCALITY_LOCAL;
type <= LOCALITY_LOCAL_INIT; type++)
 for (el = locality_list[type]; el; el = el->next)


[gcc r15-9401] testsuite: unxfail ira-shrinkwrap-prep-[12].c for x86_64 [PR117706]

2025-04-12 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:359b6128ade70f80cc850fdc8e3e90837ba1ff70

commit r15-9401-g359b6128ade70f80cc850fdc8e3e90837ba1ff70
Author: Andrew Pinski 
Date:   Sat Apr 12 12:26:26 2025 -0700

testsuite: unxfail ira-shrinkwrap-prep-[12].c for x86_64 [PR117706]

When late combine was enabled for x86_64 (r15-1735-ge62ea4fb8ffcab),
these 2 testcases start to xpass in a similar fashion as when late
combine was added and the testcase was updated for aarch64 not to
xfail them there.

Pushed as obvious after a test to make sure the testcase no longer xpass.

PR testsuite/117706
gcc/testsuite/ChangeLog:

* gcc.dg/ira-shrinkwrap-prep-1.c: Unxfail for i?68-*-* and 
x86_64-*-*.
* gcc.dg/ira-shrinkwrap-prep-2.c: Likewise.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-1.c | 2 +-
 gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-2.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-1.c 
b/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-1.c
index 8c150972f952..2be31fa296dd 100644
--- a/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-1.c
+++ b/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-1.c
@@ -25,5 +25,5 @@ bar (long a)
 }
 
 /* { dg-final { scan-rtl-dump "Will split live ranges of parameters" "ira" } } 
*/
-/* { dg-final { scan-rtl-dump "Split live-range of register" "ira" { xfail { ! 
aarch64*-*-* } } } } */
+/* { dg-final { scan-rtl-dump "Split live-range of register" "ira" { xfail { ! 
{ aarch64*-*-* i?86-*-* x86_64-*-* } } } } } */
 /* { dg-final { scan-rtl-dump "Performing shrink-wrapping" "pro_and_epilogue" 
} } */
diff --git a/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-2.c 
b/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-2.c
index 0690e036eaa2..61ee4c6dfb92 100644
--- a/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-2.c
+++ b/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-2.c
@@ -30,6 +30,6 @@ bar (long a)
 }
 
 /* { dg-final { scan-rtl-dump "Will split live ranges of parameters" "ira" } } 
*/
-/* { dg-final { scan-rtl-dump "Split live-range of register" "ira" { xfail { ! 
aarch64*-*-* } } } } */
+/* { dg-final { scan-rtl-dump "Split live-range of register" "ira" { xfail { ! 
{ aarch64*-*-* i?86-*-* x86_64-*-* } } } } } */
 /* XFAIL due to PR70681.  */ 
 /* { dg-final { scan-rtl-dump "Performing shrink-wrapping" "pro_and_epilogue" 
{ xfail arm*-*-* powerpc*-*-* } } } */


[gcc r15-9404] d: Fix importC cannot find input file __importc_builtins.d [PR119761]

2025-04-12 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:424c6c88038ef13364e6e7e74e2389923d95396e

commit r15-9404-g424c6c88038ef13364e6e7e74e2389923d95396e
Author: Iain Buclaw 
Date:   Sun Apr 13 00:48:45 2025 +0200

d: Fix importC cannot find input file __importc_builtins.d [PR119761]

Synchronizes the D runtime library with upstream druntime 09ed02ce56,
and fixes a rename of the importC module missed in the r15-6559 merge.

PR d/119761

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 09ed02ce56.
* libdruntime/Makefile.am (DRUNTIME_DISOURCES): Rename __builtins.di
to __importc_builtins.di.
* libdruntime/Makefile.in: Regenerate.
* libdruntime/__builtins.di: Move to...
* libdruntime/__importc_builtins.di: ...here.

gcc/testsuite/ChangeLog:

* gdc.dg/import-c/import-c.exp: New test.
* gdc.dg/import-c/pr119761.d: New test.
* gdc.dg/import-c/pr119761c.c: New test.

Diff:
---
 gcc/testsuite/gdc.dg/import-c/import-c.exp | 29 ++
 gcc/testsuite/gdc.dg/import-c/pr119761.d   |  2 ++
 gcc/testsuite/gdc.dg/import-c/pr119761c.c  |  4 +++
 libphobos/libdruntime/MERGE|  2 +-
 libphobos/libdruntime/Makefile.am  |  2 +-
 libphobos/libdruntime/Makefile.in  |  2 +-
 .../{__builtins.di => __importc_builtins.di}   | 10 ++--
 7 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gdc.dg/import-c/import-c.exp 
b/gcc/testsuite/gdc.dg/import-c/import-c.exp
new file mode 100644
index ..53d1478d071b
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/import-c/import-c.exp
@@ -0,0 +1,29 @@
+#   Copyright (C) 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# .
+
+# Load support procs.
+load_lib gdc-dg.exp
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+gdc-dg-runtest [lsort \
+   [glob -nocomplain $srcdir/$subdir/*.d ] ] "" \
+   "-I $srcdir/$subdir -finclude-imports"
+
+# All done.
+dg-finish
diff --git a/gcc/testsuite/gdc.dg/import-c/pr119761.d 
b/gcc/testsuite/gdc.dg/import-c/pr119761.d
new file mode 100644
index ..20eff314a83d
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/import-c/pr119761.d
@@ -0,0 +1,2 @@
+// { dg-do compile }
+import pr119761c;
diff --git a/gcc/testsuite/gdc.dg/import-c/pr119761c.c 
b/gcc/testsuite/gdc.dg/import-c/pr119761c.c
new file mode 100644
index ..522f1bf9bf84
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/import-c/pr119761c.c
@@ -0,0 +1,4 @@
+int f119761(const char *, ...)
+{
+  return 0;
+}
diff --git a/libphobos/libdruntime/MERGE b/libphobos/libdruntime/MERGE
index 00c85187b6de..840f8dd4f9d9 100644
--- a/libphobos/libdruntime/MERGE
+++ b/libphobos/libdruntime/MERGE
@@ -1,4 +1,4 @@
-c6863be7206eef3c393726363a480baf0a0c6530
+09ed02ce56ea5bf3e59f21ee0390cd85eb8bfaa7
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/libphobos/libdruntime/Makefile.am 
b/libphobos/libdruntime/Makefile.am
index 9adb5034b088..4098310888fe 100644
--- a/libphobos/libdruntime/Makefile.am
+++ b/libphobos/libdruntime/Makefile.am
@@ -445,4 +445,4 @@ DRUNTIME_DSOURCES_WINDOWS = core/sys/windows/accctrl.d \
core/sys/windows/winuser.d core/sys/windows/winver.d \
core/sys/windows/wtsapi32.d core/sys/windows/wtypes.d
 
-DRUNTIME_DISOURCES = __builtins.di __main.di
+DRUNTIME_DISOURCES = __importc_builtins.di __main.di
diff --git a/libphobos/libdruntime/Makefile.in 
b/libphobos/libdruntime/Makefile.in
index 8f8072c6dc9e..1c0fa546dbbf 100644
--- a/libphobos/libdruntime/Makefile.in
+++ b/libphobos/libdruntime/Makefile.in
@@ -1126,7 +1126,7 @@ DRUNTIME_DSOURCES_WINDOWS = core/sys/windows/accctrl.d \
core/sys/windows/winuser.d core/sys/windows/winver.d \
core/sys/windows/wtsapi32.d core/sys/windows/wtypes.d
 
-DRUNTIME_DISOURCES = __builtins.di __main.di
+DRUNTIME_DISOURCES = __importc_builtins.di __main.di
 all: all-am
 
 .SUFFIXES:
diff --git a/libphobos/libdruntime/__builtins.di 
b/libphobos/libdruntime/__importc_builtins.di
similarity index 93%
rename from libphobos/libdruntime/__builtins.di
rename to libphobos/libdruntime/__importc_builtins.di
index b4fef091b5f4..9493962e4689 100644
--- a/libphobo

[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction ICEs ISO_Fortran_binding_10

2025-04-12 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:f06001181094a5e060a5c7d6858a5114cf4d0950

commit f06001181094a5e060a5c7d6858a5114cf4d0950
Author: Mikael Morin 
Date:   Thu Apr 10 11:53:42 2025 +0200

Correction ICEs ISO_Fortran_binding_10

Diff:
---
 gcc/fortran/trans-array.cc  | 49 +++--
 gcc/fortran/trans-descriptor.cc |  5 ++---
 gcc/fortran/trans-types.cc  |  3 ++-
 gcc/fortran/trans.cc| 16 ++
 4 files changed, 58 insertions(+), 15 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 4c8136ba6a1d..00e262f7d02e 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -2094,6 +2094,15 @@ gfc_constant_array_constructor_p (gfc_constructor_base 
base)
 }
 
 
+static void
+append_constructor (vec *v, tree t)
+{
+  unsigned len = vec_safe_length (v);
+  tree idx = build_int_cst (gfc_array_index_type, len);
+  CONSTRUCTOR_APPEND_ELT (v, idx, t);
+}
+
+
 /* Given EXPR, the constant array constructor specified by an EXPR_ARRAY,
and the tree type of it's elements, TYPE, return a static constant
variable that is compile-time initialized.  */
@@ -2122,8 +2131,7 @@ gfc_build_constant_array_constructor (gfc_expr * expr, 
tree type)
   else if (POINTER_TYPE_P (type))
se.expr = gfc_build_addr_expr (gfc_get_pchar_type (c->expr->ts.kind),
   se.expr);
-  CONSTRUCTOR_APPEND_ELT (v, build_int_cst (gfc_array_index_type, nelem),
-  se.expr);
+  append_constructor (v, se.expr);
   c = gfc_constructor_next (c);
   nelem++;
 }
@@ -2160,6 +2168,43 @@ gfc_build_constant_array_constructor (gfc_expr * expr, 
tree type)
   gfc_free_expr (as.upper[i]);
 }
 
+  if (expr->shape && expr->rank > 1)
+{
+  vec *vsrc = v;
+
+  for (int r = 0; r < expr->rank - 1; r++)
+   {
+ vec *vdest = nullptr;
+ unsigned sidx = 0;
+
+ tree type = tmptype;
+ for (int j = expr->rank - 1; j > r; j--)
+   {
+ gcc_assert (GFC_ARRAY_TYPE_P (type)); 
+ type = TREE_TYPE (type);
+   }
+
+ int len = (int) mpz_get_si (expr->shape[r]);
+
+ while (sidx != vec_safe_length (vsrc))
+   {
+ vec *vtmp = nullptr;
+
+ for (int i = 0; i < len; i++)
+   {
+ append_constructor (vtmp, (*vsrc)[sidx].value);
+ sidx++;
+   }
+
+ append_constructor (vdest, build_constructor (type, vtmp));
+   }
+
+ vsrc = vdest;
+   }
+
+  v = vsrc;
+}
+
   init = build_constructor (tmptype, v);
 
   TREE_CONSTANT (init) = 1;
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 66a1019207ad..f9cc1ae20066 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -166,9 +166,8 @@ gfc_get_cfi_dim_sm (tree desc, tree idx)
 #define OFFSET_FIELD 1
 #define DTYPE_FIELD 2
 #define SPAN_FIELD 3
-#define ALIGN_FIELD 4
-#define DIMENSION_FIELD 5
-#define CAF_TOKEN_FIELD 6
+#define DIMENSION_FIELD 4
+#define CAF_TOKEN_FIELD 5
 
 #define SPACING_SUBFIELD 0
 #define LBOUND_SUBFIELD 1
diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index 69021347d9fa..f559b2bd384f 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -2192,7 +2192,8 @@ gfc_get_array_type_bounds (tree etype, int dimen, int 
codimen, tree * lbound,
   if (packed == 0)
 {
   stride = gfc_index_one_node;
-  spacing = TYPE_SIZE_UNIT (etype);
+  spacing = fold_convert_loc (input_location, gfc_array_index_type,
+ TYPE_SIZE_UNIT (etype));
 }
   else
 {
diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc
index 152e19f536ac..c77bd72b3fb2 100644
--- a/gcc/fortran/trans.cc
+++ b/gcc/fortran/trans.cc
@@ -423,15 +423,11 @@ gfc_build_array_ref (tree type, tree base, tree index, 
bool non_negative_offset,
 
   if (non_negative_offset)
 {
-  tree align = build_int_cst (gfc_array_index_type,
- TYPE_ALIGN_UNIT (type));
-  tree elt_unit_cnt = fold_build2_loc (input_location, EXACT_DIV_EXPR,
-  gfc_array_index_type, spacing,
-  align);
-  tree min_val = fold_build1_loc (input_location, NEGATE_EXPR,
- gfc_array_index_type, offset);
+  tree min_val = offset ? fold_build1_loc (input_location, NEGATE_EXPR,
+  gfc_array_index_type, offset)
+   : NULL_TREE;
   return build4_loc (input_location, ARRAY_REF, type, base, index,
-min_val, elt_unit_cnt);
+min_val, spacing);
 }
   /* Otherwise use pointer arithmetic.  */
   else
@@ -455,6 +451,8 @@ gfc_build_array_ref (tree type, tree base, tree 

[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Sauvegarde compil' OK

2025-04-12 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:bbffd5e2f96f55874352161d29b93f9065b80845

commit bbffd5e2f96f55874352161d29b93f9065b80845
Author: Mikael Morin 
Date:   Tue Apr 8 10:21:36 2025 +0200

Sauvegarde compil' OK

Diff:
---
 gcc/fortran/trans-array.cc  | 309 
 gcc/fortran/trans-decl.cc   | 196 +++-
 gcc/fortran/trans-descriptor.cc | 157 +---
 gcc/fortran/trans-descriptor.h  |   6 +-
 gcc/fortran/trans-expr.cc   |   9 +-
 gcc/fortran/trans-intrinsic.cc  |  20 +--
 gcc/fortran/trans-io.cc |   8 +-
 gcc/fortran/trans-openmp.cc |  25 +--
 gcc/fortran/trans-types.cc  | 174 ++
 gcc/fortran/trans.cc|  85 +
 gcc/fortran/trans.h |  25 ++-
 libgfortran/caf/single.c|   2 -
 libgfortran/generated/reshape_c10.c |   5 +-
 libgfortran/generated/reshape_c16.c |   5 +-
 libgfortran/generated/reshape_c17.c |   5 +-
 libgfortran/generated/reshape_c4.c  |   5 +-
 libgfortran/generated/reshape_c8.c  |   5 +-
 libgfortran/generated/reshape_i16.c |   5 +-
 libgfortran/generated/reshape_i4.c  |   5 +-
 libgfortran/generated/reshape_i8.c  |   5 +-
 libgfortran/generated/reshape_r10.c |   5 +-
 libgfortran/generated/reshape_r16.c |   5 +-
 libgfortran/generated/reshape_r17.c |   5 +-
 libgfortran/generated/reshape_r4.c  |   5 +-
 libgfortran/generated/reshape_r8.c  |   5 +-
 libgfortran/intrinsics/cshift0.c|   1 -
 libgfortran/intrinsics/eoshift0.c   |   1 -
 libgfortran/intrinsics/eoshift2.c   |   3 +-
 libgfortran/intrinsics/move_alloc.c |   1 -
 libgfortran/intrinsics/pack_generic.c   |   2 -
 libgfortran/intrinsics/spread_generic.c |   7 +-
 libgfortran/intrinsics/unpack_generic.c |   2 +-
 libgfortran/libgfortran.h   |  11 +-
 libgfortran/m4/reshape.m4   |   3 +-
 34 files changed, 467 insertions(+), 645 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index fa7afc938e58..4c8136ba6a1d 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -964,10 +964,6 @@ gfc_trans_create_temp_array (stmtblock_t * pre, 
stmtblock_t * post, gfc_ss * ss,
   if (class_expr == NULL_TREE && GFC_CLASS_TYPE_P (eltype))
 class_expr = get_class_info_from_ss (pre, ss, &eltype, &fcn_ss);
 
-  bool array_access = class_expr == NULL_TREE
- && eltype != NULL_TREE
- && !GFC_CLASS_TYPE_P (eltype);
-
   /* If the dynamic type is not available, use the declared type.  */
   if (eltype && GFC_CLASS_TYPE_P (eltype))
 eltype = gfc_get_element_type (TREE_TYPE (TYPE_FIELDS (eltype)));
@@ -1148,10 +1144,8 @@ gfc_trans_create_temp_array (stmtblock_t * pre, 
stmtblock_t * post, gfc_ss * ss,
 }
 
   info->descriptor = desc;
-  info->array_access = array_access;
-  size = fold_build2_loc (input_location, EXACT_DIV_EXPR, gfc_array_index_type,
- elemsize, build_int_cst (gfc_array_index_type,
-  TYPE_ALIGN_UNIT (eltype)));
+  size = elemsize;
+  nelem = gfc_index_one_node;
 
   /*
  Fill in the bounds and stride.  This is a packed array, so:
@@ -1217,9 +1211,14 @@ gfc_trans_create_temp_array (stmtblock_t * pre, 
stmtblock_t * post, gfc_ss * ss,
or_expr = fold_build2_loc (input_location, TRUTH_OR_EXPR,
   logical_type_node, or_expr, cond);
 
+ extent = gfc_evaluate_now (extent, pre);
+
  size = fold_build2_loc (input_location, MULT_EXPR,
  gfc_array_index_type, size, extent);
  size = gfc_evaluate_now (size, pre);
+
+ nelem = fold_build2_loc (input_location, MULT_EXPR,
+  gfc_array_index_type, nelem, extent);
}
 }
 
@@ -1228,27 +1227,24 @@ gfc_trans_create_temp_array (stmtblock_t * pre, 
stmtblock_t * post, gfc_ss * ss,
   /* Get the size of the array.  */
   if (size && !callee_alloc)
 {
+  or_expr = gfc_evaluate_now (or_expr, pre);
+
   /* If or_expr is true, then the extent in at least one
 dimension is zero and the size is set to zero.  */
   size = fold_build3_loc (input_location, COND_EXPR, gfc_array_index_type,
  or_expr, gfc_index_zero_node, size);
 
-  nelem = size;
-  size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
- size, elemsize);
+  nelem = fold_build3_loc (input_location, COND_EXPR, gfc_array_index_type,
+  or_expr, gfc_index_zero_node, nelem);
 }
   else
-{
-  nelem = size;
-  size = NULL_TREE;
-}
+size = NULL_TREE;
 
   tree data_ptr = gfc_trans_allocate_array_storage (pre, post, info, size,

[gcc/mikael/heads/refactor_descriptor_v05] (14 commits) Correction ICE aliasing_complex_pointer

2025-04-12 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/refactor_descriptor_v05' was updated to point to:

 f8c2b7ef2a61... Correction ICE aliasing_complex_pointer

It previously pointed to:

 a1657ba13a58... Sauvegarde correction régressions.

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  a1657ba... Sauvegarde correction régressions.
  d63b964... Correction régression y compris PR100094
  c0d838c... Correction ICE aliasing_dummy_4.f90
  137fe54... Correction actual_array_constructor_1.f90
  55ab3ee... Correction régressions, y compris aliasing_dummy_1.f90
  3a34dc4... Sauvegarde spacing compilation OK
  907d363... Sauvegarde modifs.


Summary of changes (added commits):
---

  f8c2b7e... Correction ICE aliasing_complex_pointer
  fe7cd1f... Correction ICE ISO_Fortran_binding_5
  a5512e8... Correction ICE PR100906
  451be56... Correction ICE 20231103-1
  115f180... Correction ICE PR94022
  d07d1d3... Correction ICE PR95196
  dc7afa2... Correction ICE PR93308
  d6c3656... Correction ICE PR49268.f90
  837eb01... Correction ICEs PR95331
  3df7f50... Correction ICEs ISO_Fortran_binding_17
  f060011... Correction ICEs ISO_Fortran_binding_10
  3d665eb... Sauvegarde compil' OK
  bbffd5e... Sauvegarde compil' OK
  ab01d68... Sauvegarde modifs.


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction ICE PR100906

2025-04-12 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:a5512e82805a5f4dcfa4dd2a4a02ce871f07e688

commit a5512e82805a5f4dcfa4dd2a4a02ce871f07e688
Author: Mikael Morin 
Date:   Fri Apr 11 16:39:13 2025 +0200

Correction ICE PR100906

Diff:
---
 gcc/fortran/trans-decl.cc | 26 +++---
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index e1028f8da357..39886b66ec09 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -4401,7 +4401,7 @@ gfc_trans_assign_aux_var (gfc_symbol * sym, 
gfc_wrapped_block * block)
 }
 
 static void
-gfc_trans_vla_one_sizepos (tree *tp, stmtblock_t *body)
+gfc_trans_vla_one_sizepos (tree *tp, tree root_decl, stmtblock_t *body)
 {
   tree t = *tp, var, val;
 
@@ -4410,6 +4410,9 @@ gfc_trans_vla_one_sizepos (tree *tp, stmtblock_t *body)
   if (TREE_CONSTANT (t) || DECL_P (t))
 return;
 
+  if (contains_placeholder_p (t))
+t = substitute_placeholder_in_expr (t, root_decl);
+
   if (TREE_CODE (t) == SAVE_EXPR)
 {
   if (SAVE_EXPR_RESOLVED_P (t))
@@ -4431,7 +4434,7 @@ gfc_trans_vla_one_sizepos (tree *tp, stmtblock_t *body)
 }
 
 static void
-gfc_trans_vla_type_sizes_1 (tree type, stmtblock_t *body)
+gfc_trans_vla_type_sizes_1 (tree type, tree root_decl, stmtblock_t *body)
 {
   tree t;
 
@@ -4442,8 +4445,8 @@ gfc_trans_vla_type_sizes_1 (tree type, stmtblock_t *body)
 
   if (TREE_CODE (type) == INTEGER_TYPE)
 {
-  gfc_trans_vla_one_sizepos (&TYPE_MIN_VALUE (type), body);
-  gfc_trans_vla_one_sizepos (&TYPE_MAX_VALUE (type), body);
+  gfc_trans_vla_one_sizepos (&TYPE_MIN_VALUE (type), root_decl, body);
+  gfc_trans_vla_one_sizepos (&TYPE_MAX_VALUE (type), root_decl, body);
 
   for (t = TYPE_NEXT_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
{
@@ -4453,10 +4456,10 @@ gfc_trans_vla_type_sizes_1 (tree type, stmtblock_t 
*body)
 }
   else if (TREE_CODE (type) == ARRAY_TYPE)
 {
-  gfc_trans_vla_type_sizes_1 (TREE_TYPE (type), body);
-  gfc_trans_vla_type_sizes_1 (TYPE_DOMAIN (type), body);
-  gfc_trans_vla_one_sizepos (&TYPE_SIZE (type), body);
-  gfc_trans_vla_one_sizepos (&TYPE_SIZE_UNIT (type), body);
+  gfc_trans_vla_type_sizes_1 (TREE_TYPE (type), root_decl, body);
+  gfc_trans_vla_type_sizes_1 (TYPE_DOMAIN (type), root_decl, body);
+  gfc_trans_vla_one_sizepos (&TYPE_SIZE (type), root_decl, body);
+  gfc_trans_vla_one_sizepos (&TYPE_SIZE_UNIT (type), root_decl, body);
 
   for (t = TYPE_NEXT_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
{
@@ -4479,7 +4482,8 @@ gfc_trans_vla_type_sizes_1 (tree type, stmtblock_t *body)
 void
 gfc_trans_vla_type_sizes (gfc_symbol *sym, stmtblock_t *body)
 {
-  tree type = TREE_TYPE (sym->backend_decl);
+  tree root_decl = sym->backend_decl;
+  tree type = TREE_TYPE (root_decl);
 
   if (TREE_CODE (type) == FUNCTION_TYPE
   && (sym->attr.function || sym->attr.result || sym->attr.entry))
@@ -4500,10 +4504,10 @@ gfc_trans_vla_type_sizes (gfc_symbol *sym, stmtblock_t 
*body)
   while (POINTER_TYPE_P (etype))
etype = TREE_TYPE (etype);
 
-  gfc_trans_vla_type_sizes_1 (etype, body);
+  gfc_trans_vla_type_sizes_1 (etype, root_decl, body);
 }
 
-  gfc_trans_vla_type_sizes_1 (type, body);
+  gfc_trans_vla_type_sizes_1 (type, root_decl, body);
 }


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction ICE PR94022

2025-04-12 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:115f180f14c62dd4a22b4a5d2086a593a9826ed0

commit 115f180f14c62dd4a22b4a5d2086a593a9826ed0
Author: Mikael Morin 
Date:   Fri Apr 11 14:07:45 2025 +0200

Correction ICE PR94022

Diff:
---
 gcc/fortran/trans-array.cc  |  2 +-
 gcc/fortran/trans-descriptor.cc | 17 +
 gcc/fortran/trans-types.cc  | 16 ++--
 3 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 3e36a1dd15b9..9f17a6d8eac7 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -6889,7 +6889,7 @@ gfc_get_dataptr_offset (stmtblock_t *block, tree parm, 
tree desc,
 {
   array = build_array_ref (desc, array, gfc_index_zero_node,
   non_negative_strides, gfc_index_zero_node,
-  NULL_TREE, nullptr);
+  gfc_conv_array_spacing (desc, i), nullptr);
 }
   tmp = array;
 
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 4bbc05be7a4e..88062e3b8b3a 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -980,10 +980,19 @@ gfc_build_desc_array_type (tree desc_type, tree etype, 
int dimen, tree * lbound,
  upper = gfc_descriptor::get_ubound (root, dim);
}
 
-  tree idx_type = build_range_type (gfc_array_index_type, lower, upper);
-
-  type = build_array_type (type, idx_type);
-  layout_type (type);
+  tree index_type = build_range_type (gfc_array_index_type, lower, upper);
+
+  tree elt_type = type;
+  type = make_node (ARRAY_TYPE);
+  TREE_TYPE (type) = elt_type;
+  TYPE_DOMAIN (type) = index_type;
+  TYPE_ADDR_SPACE (type) = TYPE_ADDR_SPACE (elt_type);
+
+  /* Set TYPE_STRUCTURAL_EQUALITY_P.  */
+  if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
+ || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
+ || in_lto_p)
+   SET_TYPE_STRUCTURAL_EQUALITY (type);
 }
 
   return type;
diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index 4661ff92fa8d..5e647d2965e5 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -1855,7 +1855,11 @@ build_nested_array_types (tree etype, tree 
lbound[GFC_MAX_DIMENSIONS],
 
   for (int i = 0; i < rank; i++)
 {
-  tree idx_type = build_range_type (gfc_array_index_type, lbound[i], 
ubound[i]);
+  tree idx_type;
+  if (lbound[i])
+   idx_type = build_range_type (gfc_array_index_type, lbound[i], 
ubound[i]);
+  else
+   idx_type = gfc_array_index_type;
   type = build_array_type (type, idx_type);
   layout_type (type);
 }
@@ -2197,14 +2201,14 @@ gfc_get_array_type_bounds (tree etype, int dimen, int 
codimen, tree * lbound,
   tree spacing;
   if (packed == 0)
 {
-  stride = gfc_index_one_node;
-  spacing = fold_convert_loc (input_location, gfc_array_index_type,
- TYPE_SIZE_UNIT (etype));
+  stride = NULL_TREE;
+  spacing = NULL_TREE;
 }
   else
 {
-  stride = NULL_TREE;
-  spacing = NULL_TREE;
+  stride = gfc_index_one_node;
+  spacing = fold_convert_loc (input_location, gfc_array_index_type,
+ TYPE_SIZE_UNIT (etype));
 }
   for (n = 0; n < dimen + codimen; n++)
 {


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction ICE PR49268.f90

2025-04-12 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:d6c365618bd052485815b2695eaa25e2ca1672af

commit d6c365618bd052485815b2695eaa25e2ca1672af
Author: Mikael Morin 
Date:   Fri Apr 11 10:40:32 2025 +0200

Correction ICE PR49268.f90

Diff:
---
 gcc/fortran/trans-decl.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 378e5c164505..bf96da9f98c0 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -1070,7 +1070,7 @@ update_type_bounds (tree type, tree 
lbound[GFC_MAX_DIMENSIONS],
 }
   if (current_ubound != NULL_TREE)
 {
-  GFC_TYPE_ARRAY_UBOUND (type, dim) = current_ubound;
+  GFC_TYPE_ARRAY_UBOUND (root_type, dim) = current_ubound;
   if (current_ubound
  && VAR_P (current_ubound)
  && DECL_ARTIFICIAL (current_ubound)
@@ -1085,7 +1085,7 @@ update_type_bounds (tree type, tree 
lbound[GFC_MAX_DIMENSIONS],
   tree current_spacing = spacing[dim];
   if (current_spacing != NULL_TREE)
 {
-  GFC_TYPE_ARRAY_SPACING (type, dim) = current_spacing;
+  GFC_TYPE_ARRAY_SPACING (root_type, dim) = current_spacing;
   if (current_spacing
  && VAR_P (current_spacing)
  && DECL_ARTIFICIAL (current_spacing)


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction ICEs PR95331

2025-04-12 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:837eb01ed7035de0cc44aa66c956492554db614b

commit 837eb01ed7035de0cc44aa66c956492554db614b
Author: Mikael Morin 
Date:   Fri Apr 11 10:32:11 2025 +0200

Correction ICEs PR95331

Diff:
---
 gcc/fortran/trans-array.cc  | 125 +++-
 gcc/fortran/trans-array.h   |   2 +-
 gcc/fortran/trans-descriptor.cc |   6 +-
 gcc/fortran/trans-expr.cc   |   2 +-
 gcc/fortran/trans-types.cc  |  10 +++-
 gcc/fortran/trans.cc|  26 -
 6 files changed, 97 insertions(+), 74 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 5014c1aa8731..c846b2c2a1ef 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -3092,7 +3092,8 @@ gfc_conv_array_spacing (tree descriptor, int dim)
 
   /* For descriptorless arrays use the array size.  */
   tmp = GFC_TYPE_ARRAY_SPACING (type, dim);
-  if (tmp != NULL_TREE)
+  if (tmp != NULL_TREE
+  && !contains_placeholder_p (tmp))
 return tmp;
 
   tmp = gfc_conv_descriptor_spacing_get (descriptor, gfc_rank_cst[dim]);
@@ -3111,7 +3112,8 @@ gfc_conv_array_lbound (tree descriptor, int dim)
   type = TREE_TYPE (descriptor);
 
   tmp = GFC_TYPE_ARRAY_LBOUND (type, dim);
-  if (tmp != NULL_TREE)
+  if (tmp != NULL_TREE
+  && !contains_placeholder_p (tmp))
 return tmp;
 
   tmp = gfc_conv_descriptor_lbound_get (descriptor, gfc_rank_cst[dim]);
@@ -3130,7 +3132,8 @@ gfc_conv_array_ubound (tree descriptor, int dim)
   type = TREE_TYPE (descriptor);
 
   tmp = GFC_TYPE_ARRAY_UBOUND (type, dim);
-  if (tmp != NULL_TREE)
+  if (tmp != NULL_TREE
+  && !contains_placeholder_p (tmp))
 return tmp;
 
   /* This should only ever happen when passing an assumed shape array
@@ -3477,15 +3480,37 @@ non_negative_strides_array_p (tree expr)
 
 
 static tree
-build_array_ref (tree desc, tree offset)
+build_array_ref (tree descriptor, tree array, tree index,
+bool non_negative_stride, tree lbound, tree spacing,
+const vec * array_type_domains)
 {
-  tree tmp;
+  tree elt_type = NULL_TREE;
+  if (!array_type_domains || array_type_domains->is_empty ())
+elt_type = TREE_TYPE (TREE_TYPE (array));
+  else
+{
+  tree desc_type = TREE_TYPE (descriptor);
+  tree core_type = TREE_TYPE (GFC_TYPE_ARRAY_DATAPTR_TYPE (desc_type));
 
-  tmp = gfc_conv_array_data (desc);
-  tmp = build_fold_indirect_ref_loc (input_location, tmp);
+  unsigned j;
+  tree *dom_p;
+  FOR_EACH_VEC_ELT (*array_type_domains, j, dom_p)
+   {
+ gcc_assert (GFC_ARRAY_TYPE_P (core_type)
+ && TYPE_DOMAIN (core_type) == *dom_p);
+ core_type = TREE_TYPE (core_type);
+   }
 
-  tmp = gfc_build_array_ref (tmp, offset, non_negative_strides_array_p (desc));
-  return tmp;
+  core_type = TREE_TYPE (core_type);
+
+  tree elt_type = core_type;
+
+  FOR_EACH_VEC_ELT_REVERSE (*array_type_domains, j, dom_p)
+   elt_type = build_array_type (elt_type, *dom_p);
+}
+
+  return gfc_build_array_ref (elt_type, array, index, non_negative_stride,
+ lbound, spacing);
 }
 
 
@@ -3797,39 +3822,14 @@ add_array_index (stmtblock_t *pblock, gfc_loopinfo 
*loop, gfc_ss *ss,
 
   tree index = fold_convert_loc (input_location, gfc_array_index_type, tmp);
 
-  tree elt_type = NULL_TREE;
-  if (!array_type_domains || array_type_domains->is_empty ())
-elt_type = TREE_TYPE (array);
-  else
-{
-  tree desc_type = TREE_TYPE (info->descriptor);
-  tree core_type = TREE_TYPE (GFC_TYPE_ARRAY_DATAPTR_TYPE (desc_type));
-
-  unsigned j;
-  tree *dom_p;
-  FOR_EACH_VEC_ELT (*array_type_domains, j, dom_p)
-   {
- gcc_assert (GFC_ARRAY_TYPE_P (core_type)
- && TYPE_DOMAIN (core_type) == *dom_p);
- core_type = TREE_TYPE (core_type);
-   }
-
-  core_type = TREE_TYPE (core_type);
-
-  tree elt_type = core_type;
-
-  FOR_EACH_VEC_ELT_REVERSE (*array_type_domains, j, dom_p)
-   elt_type = build_array_type (elt_type, *dom_p);
-}
-
   gfc_ss_type ss_type = ss->info->type;
   bool non_negative_stride = ss_type == GFC_SS_FUNCTION
 || ss_type == GFC_SS_CONSTRUCTOR
 || ss_type == GFC_SS_INTRINSIC
 || non_negative_strides_array_p (info->descriptor);
-  return gfc_build_array_ref (elt_type, array, index,
- non_negative_stride, info->lbound[array_dim],
- info->spacing[array_dim]);
+  return build_array_ref (info->descriptor, array, index, non_negative_stride,
+ info->lbound[array_dim], info->spacing[array_dim],
+ array_type_domains);
 }
 
 
@@ -3896,7 +3896,7 @@ gfc_trans_preloop_setup (gfc_loopinfo * loop, int dim, 
int flag,
  gcc_assert (0 == ploop->order[0]);
 
  info->spacing0 = gfc_conv_array_spacing (info->de

[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction ICE PR93308

2025-04-12 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:dc7afa2131a2ffaf46e6b2267be2a0e9f06c4719

commit dc7afa2131a2ffaf46e6b2267be2a0e9f06c4719
Author: Mikael Morin 
Date:   Fri Apr 11 12:27:53 2025 +0200

Correction ICE PR93308

Diff:
---
 gcc/fortran/trans-array.cc | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index c846b2c2a1ef..c8c8ab4b028e 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -6007,6 +6007,7 @@ gfc_conv_array_initializer (tree type, gfc_expr * expr)
 {
   gfc_constructor *c;
   tree tmp;
+  tree min_index = NULL_TREE;
   gfc_se se;
   tree index, range;
   vec *v = NULL;
@@ -6043,6 +6044,9 @@ gfc_conv_array_initializer (tree type, gfc_expr * expr)
   break;
 
 case EXPR_ARRAY:
+  if (TYPE_DOMAIN (type))
+   min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
+
   /* Create a vector of all the elements.  */
   for (c = gfc_constructor_first (expr->value.constructor);
   c && c->expr; c = gfc_constructor_next (c))
@@ -6062,6 +6066,9 @@ gfc_conv_array_initializer (tree type, gfc_expr * expr)
 index = gfc_conv_mpz_to_tree (c->offset, gfc_index_integer_kind);
   else
 index = NULL_TREE;
+ if (index && min_index)
+   index = fold_build2_loc (input_location, PLUS_EXPR,
+TREE_TYPE (index), index, min_index);
 
  if (mpz_cmp_si (c->repeat, 1) > 0)
{


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction ICEs ISO_Fortran_binding_17

2025-04-12 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:3df7f5006e28abd5abe00e242b010355e107beec

commit 3df7f5006e28abd5abe00e242b010355e107beec
Author: Mikael Morin 
Date:   Thu Apr 10 14:49:06 2025 +0200

Correction ICEs ISO_Fortran_binding_17

Diff:
---
 gcc/fortran/trans-array.cc  | 15 ++-
 gcc/fortran/trans-descriptor.cc |  4 ++--
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 00e262f7d02e..5014c1aa8731 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -3501,7 +3501,6 @@ conv_array_index (gfc_se * se, gfc_ss * ss, int dim, int 
i,
   tree index;
   tree descriptor;
   tree data;
-  tree offset;
 
   info = &ss->info->data.array;
 
@@ -3531,9 +3530,6 @@ conv_array_index (gfc_se * se, gfc_ss * ss, int dim, int 
i,
  gcc_assert (info->subscript[dim]
  && info->subscript[dim]->info->type == GFC_SS_VECTOR);
 
- offset = fold_build1_loc (input_location, NEGATE_EXPR,
-   gfc_array_index_type, se->loop->from[i]);
-
  descriptor = info->subscript[dim]->info->data.array.descriptor; 
  index = fold_convert_loc (input_location, gfc_array_index_type,
se->loop->loopvar[i]);
@@ -3541,7 +3537,8 @@ conv_array_index (gfc_se * se, gfc_ss * ss, int dim, int 
i,
  /* Read the vector to get an index into info->descriptor.  */
  data = build_fold_indirect_ref_loc (input_location, 
  gfc_conv_array_data (descriptor));
- index = gfc_build_array_ref (data, index, false, offset,
+ index = gfc_build_array_ref (data, index, false,
+  gfc_conv_array_lbound (descriptor, 0),
   gfc_conv_array_spacing (descriptor, 0));
  index = gfc_evaluate_now (index, &se->pre);
  index = fold_convert (gfc_array_index_type, index);
@@ -3612,7 +3609,8 @@ gfc_conv_scalarized_array_ref (gfc_se * se, gfc_array_ref 
* ar,
   bool non_negative_stride = tmp_array
 || non_negative_strides_array_p (info->descriptor);
   se->expr = gfc_build_array_ref (base, index, non_negative_stride,
- info->offset, info->spacing[ss->dim[0]]);
+ info->lbound[ss->dim[0]],
+ info->spacing[ss->dim[0]]);
 }
 
 
@@ -3694,8 +3692,8 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, 
gfc_expr *expr,
   && ar->as->type != AS_DEFERRED)
 decl = sym->backend_decl;
 
-  tree array = gfc_conv_array_data (decl);
-  array = build_fold_indirect_ref_loc (input_location, array);
+  tree ptr = gfc_conv_array_data (decl);
+  tree array = build_fold_indirect_ref_loc (input_location, ptr);
 
   /* Calculate the offsets from all the dimensions.  Make sure to associate
  the final offset so that we form a chain of loop invariant summands.  */
@@ -3766,7 +3764,6 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, 
gfc_expr *expr,
 
   tree spacing = gfc_conv_array_spacing (decl, n);
 
-  gcc_assert (GFC_ARRAY_TYPE_P (TREE_TYPE (array)));
   tmp = gfc_build_array_ref (array, indexse.expr,
 non_negative_strides_array_p (decl),
 lbound, spacing);
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index f9cc1ae20066..699f29cd6137 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -965,7 +965,7 @@ gfc_build_desc_array_type (tree desc_type, tree etype, int 
dimen, tree * lbound,
   for (int i = 0; i < dimen; i++)
 {
   tree lower = lbound[i];
-  if (!INTEGER_CST_P (lower))
+  if (!lower)
{
  tree root = build0 (PLACEHOLDER_EXPR, desc_type);
  tree dim = build_int_cst (integer_type_node, i);
@@ -973,7 +973,7 @@ gfc_build_desc_array_type (tree desc_type, tree etype, int 
dimen, tree * lbound,
}
 
   tree upper = ubound[i];
-  if (!INTEGER_CST_P (lower))
+  if (!upper)
{
  tree root = build0 (PLACEHOLDER_EXPR, desc_type);
  tree dim = build_int_cst (integer_type_node, i);


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction ICE 20231103-1

2025-04-12 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:451be569e4fdc18e6155a54f53a16f7b3f587cdb

commit 451be569e4fdc18e6155a54f53a16f7b3f587cdb
Author: Mikael Morin 
Date:   Fri Apr 11 16:02:38 2025 +0200

Correction ICE 20231103-1

Diff:
---
 gcc/fortran/trans-decl.cc | 20 
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index bf96da9f98c0..e1028f8da357 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -1046,11 +1046,23 @@ update_type_bounds (tree type, tree 
lbound[GFC_MAX_DIMENSIONS],
   || current_ubound != NULL_TREE
   || elt_type != TREE_TYPE (type))
 {
-  tree new_type = build_variant_type_copy (type);
+  tree new_type = build_distinct_type_copy (type);
   TREE_TYPE (new_type) = elt_type;
-  TYPE_DOMAIN (new_type) = build_variant_type_copy (TYPE_DOMAIN (type));
-  TYPE_MIN_VALUE (TYPE_DOMAIN (new_type)) = current_lbound;
-  TYPE_MAX_VALUE (TYPE_DOMAIN (new_type)) = current_ubound;
+  TYPE_DOMAIN (new_type) = build_distinct_type_copy (TYPE_DOMAIN (type));
+
+  tree new_lbound = current_lbound;
+  if (new_lbound == NULL_TREE)
+   new_lbound = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
+  TYPE_MIN_VALUE (TYPE_DOMAIN (new_type)) = new_lbound;
+
+  tree new_ubound = current_ubound;
+  if (new_ubound == NULL_TREE)
+   new_ubound = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
+  TYPE_MAX_VALUE (TYPE_DOMAIN (new_type)) = new_ubound;
+
+  layout_type (TYPE_DOMAIN (new_type));
+  layout_type (new_type);
+
   type = new_type;
 }


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction ICE PR95196

2025-04-12 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:d07d1d30699fe5070de3ce0155817509b23da850

commit d07d1d30699fe5070de3ce0155817509b23da850
Author: Mikael Morin 
Date:   Fri Apr 11 12:46:21 2025 +0200

Correction ICE PR95196

Diff:
---
 gcc/fortran/trans-array.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index c8c8ab4b028e..3e36a1dd15b9 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -2180,7 +2180,7 @@ gfc_build_constant_array_constructor (gfc_expr * expr, 
tree type)
  tree type = tmptype;
  for (int j = expr->rank - 1; j > r; j--)
{
- gcc_assert (GFC_ARRAY_TYPE_P (type)); 
+ gcc_assert (TREE_CODE (type) == ARRAY_TYPE); 
  type = TREE_TYPE (type);
}


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction ICE aliasing_complex_pointer

2025-04-12 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:f8c2b7ef2a61e48a8be35caec9aa9e6ba3b3741b

commit f8c2b7ef2a61e48a8be35caec9aa9e6ba3b3741b
Author: Mikael Morin 
Date:   Sat Apr 12 15:44:20 2025 +0200

Correction ICE aliasing_complex_pointer

Diff:
---
 gcc/fortran/trans-array.cc  | 25 +
 gcc/fortran/trans-descriptor.cc | 12 +---
 gcc/fortran/trans-types.cc  | 21 +
 gcc/fortran/trans-types.h   |  2 ++
 4 files changed, 37 insertions(+), 23 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 9f17a6d8eac7..fa84f007bee5 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1045,6 +1045,7 @@ gfc_trans_create_temp_array (stmtblock_t * pre, 
stmtblock_t * post, gfc_ss * ss,
  info->start[dim] = gfc_index_zero_node;
  info->end[dim] = gfc_index_zero_node;
  info->stride[dim] = gfc_index_one_node;
+ info->lbound[dim] = gfc_index_zero_node;
}
 }
 
@@ -1189,7 +1190,7 @@ gfc_trans_create_temp_array (stmtblock_t * pre, 
stmtblock_t * post, gfc_ss * ss,
 {
   for (n = 0; n < total_dim; n++)
{
- spacing[n] = size;
+ info->spacing[n] = spacing[n] = size;
 
  tree extent = to[n];
  if (!shift_bounds && !integer_zerop (from[n]))
@@ -3480,7 +3481,7 @@ non_negative_strides_array_p (tree expr)
 
 
 static tree
-build_array_ref (tree descriptor, tree array, tree index,
+build_array_ref (tree array, tree index,
 bool non_negative_stride, tree lbound, tree spacing,
 const vec * array_type_domains)
 {
@@ -3489,24 +3490,21 @@ build_array_ref (tree descriptor, tree array, tree 
index,
 elt_type = TREE_TYPE (TREE_TYPE (array));
   else
 {
-  tree desc_type = TREE_TYPE (descriptor);
-  tree core_type = TREE_TYPE (GFC_TYPE_ARRAY_DATAPTR_TYPE (desc_type));
+  tree core_type = TREE_TYPE (array);
 
   unsigned j;
   tree *dom_p;
   FOR_EACH_VEC_ELT (*array_type_domains, j, dom_p)
{
- gcc_assert (GFC_ARRAY_TYPE_P (core_type)
+ gcc_assert (TREE_CODE (core_type) == ARRAY_TYPE
  && TYPE_DOMAIN (core_type) == *dom_p);
  core_type = TREE_TYPE (core_type);
}
 
-  core_type = TREE_TYPE (core_type);
-
-  tree elt_type = core_type;
+  elt_type = TREE_TYPE (core_type);
 
   FOR_EACH_VEC_ELT_REVERSE (*array_type_domains, j, dom_p)
-   elt_type = build_array_type (elt_type, *dom_p);
+   elt_type = gfc_build_incomplete_array_type (elt_type, *dom_p);
 }
 
   return gfc_build_array_ref (elt_type, array, index, non_negative_stride,
@@ -3827,7 +3825,7 @@ add_array_index (stmtblock_t *pblock, gfc_loopinfo *loop, 
gfc_ss *ss,
 || ss_type == GFC_SS_CONSTRUCTOR
 || ss_type == GFC_SS_INTRINSIC
 || non_negative_strides_array_p (info->descriptor);
-  return build_array_ref (info->descriptor, array, index, non_negative_stride,
+  return build_array_ref (array, index, non_negative_stride,
  info->lbound[array_dim], info->spacing[array_dim],
  array_type_domains);
 }
@@ -4609,7 +4607,10 @@ done:
for (n = 0; n < GFC_MAX_DIMENSIONS; n++)
  if (info->subscript[n]
  && info->subscript[n]->info->type == GFC_SS_SCALAR)
-   conv_evaluate_lbound (&outer_loop->pre, ss, n);
+   {
+ conv_array_spacing (&outer_loop->pre, ss, n);
+ conv_evaluate_lbound (&outer_loop->pre, ss, n);
+   }
  break;
 
case GFC_SS_INTRINSIC:
@@ -6887,7 +6888,7 @@ gfc_get_dataptr_offset (stmtblock_t *block, tree parm, 
tree desc,
 
   for (int i = GFC_TYPE_ARRAY_RANK (TREE_TYPE (desc)) - 1; i >= 0; i--)
 {
-  array = build_array_ref (desc, array, gfc_index_zero_node,
+  array = build_array_ref (array, gfc_index_zero_node,
   non_negative_strides, gfc_index_zero_node,
   gfc_conv_array_spacing (desc, i), nullptr);
 }
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 88062e3b8b3a..190311675198 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -982,17 +982,7 @@ gfc_build_desc_array_type (tree desc_type, tree etype, int 
dimen, tree * lbound,
 
   tree index_type = build_range_type (gfc_array_index_type, lower, upper);
 
-  tree elt_type = type;
-  type = make_node (ARRAY_TYPE);
-  TREE_TYPE (type) = elt_type;
-  TYPE_DOMAIN (type) = index_type;
-  TYPE_ADDR_SPACE (type) = TYPE_ADDR_SPACE (elt_type);
-
-  /* Set TYPE_STRUCTURAL_EQUALITY_P.  */
-  if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
- || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
- || in_lto_p)
-   SET_TYPE_STRUCTURAL_EQUALITY (type);
+  type = gfc_build_

[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction ICE ISO_Fortran_binding_5

2025-04-12 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:fe7cd1f179eda2159f9309e37e8bf345b2ab

commit fe7cd1f179eda2159f9309e37e8bf345b2ab
Author: Mikael Morin 
Date:   Fri Apr 11 17:18:48 2025 +0200

Correction ICE ISO_Fortran_binding_5

Diff:
---
 gcc/fortran/trans-types.cc | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index 5e647d2965e5..b02215f6620d 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -1465,7 +1465,14 @@ gfc_get_element_type (tree type)
 
   /* For arrays, which are not scalar coarrays.  */
   if (TREE_CODE (element) == ARRAY_TYPE && !TYPE_STRING_FLAG (element))
-   element = TREE_TYPE (element);
+   {
+ int rank = GFC_TYPE_ARRAY_RANK (type);
+ for (int i = 0; i < rank; i++)
+   {
+ gcc_assert (TREE_CODE (element) == ARRAY_TYPE);
+ element = TREE_TYPE (element);
+   }
+   }
 }
 
   return element;


[gcc r15-9399] Doc: Explicitly document extensions implied by -march=x86_64 [PR97585]

2025-04-12 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:342f1663bfb0e662f12c035c922d72166be9dd22

commit r15-9399-g342f1663bfb0e662f12c035c922d72166be9dd22
Author: Sandra Loosemore 
Date:   Sat Apr 12 04:03:11 2025 +

Doc: Explicitly document extensions implied by -march=x86_64 [PR97585]

gcc/ChangeLog
PR target/97585
* doc/invoke.texi (x86 Options): Document list of extensions
supported by -march=x86_64, according to the declaration of
PTA_X86_64_BASELINE in config/i386/i386.h.

Diff:
---
 gcc/doc/invoke.texi | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 4be80a7f7f9a..fbaa29f49258 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -34838,7 +34838,8 @@ produces code optimized for the local machine under the 
constraints
 of the selected instruction set.
 
 @item x86-64
-A generic CPU with 64-bit extensions.
+A generic CPU with 64-bit extensions, MMX, SSE, SSE2, and FXSR instruction set
+support.
 
 @item x86-64-v2
 @itemx x86-64-v3


[gcc r15-9394] Ada: Natural/Positive not ignored in subprogram renaming

2025-04-12 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:ecef0d7c53d59a701bc09e2df8fbec5d4c61267a

commit r15-9394-gecef0d7c53d59a701bc09e2df8fbec5d4c61267a
Author: Eric Botcazou 
Date:   Sat Apr 12 11:35:44 2025 +0200

Ada: Natural/Positive not ignored in subprogram renaming

The language says that the profile of a subprogram renaming-as-declaration
must be mode conformant with that of the renamed subprogram, and that the
parameter subtypes are taken from the renamed subprogram.

GNAT implements the rule, except when Natural and Positive are involved,
which may lead to the wrong conclusion that it does not.

gcc/ada/
PR ada/119643
* sem_ch8.adb (Inherit_Renamed_Profile): Add guard against the
peculiarities of Natural and Positive.

gcc/testsuite/
* gnat.dg/renaming17.adb: New test.

Diff:
---
 gcc/ada/sem_ch8.adb  |  3 ++-
 gcc/testsuite/gnat.dg/renaming17.adb | 17 +
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
index d4ab44fee923..0a9ef419db78 100644
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -9314,11 +9314,12 @@ package body Sem_Ch8 is
 
 --  If the new type is a renaming of the old one, as is the case
 --  for actuals in instances, retain its name, to simplify later
---  disambiguation.
+--  disambiguation. Beware of Natural and Positive, see Cstand.
 
 if Nkind (Parent (New_T)) = N_Subtype_Declaration
   and then Is_Entity_Name (Subtype_Indication (Parent (New_T)))
   and then Entity (Subtype_Indication (Parent (New_T))) = Old_T
+  and then Scope (New_T) /= Standard_Standard
 then
null;
 else
diff --git a/gcc/testsuite/gnat.dg/renaming17.adb 
b/gcc/testsuite/gnat.dg/renaming17.adb
new file mode 100644
index ..d82643318b9f
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/renaming17.adb
@@ -0,0 +1,17 @@
+-- { dg-do run }
+
+procedure Renaming17 is
+
+  function Incr (V : Integer; I : Integer := 1) return Integer is
+(V + I);
+
+  function Incr_Ren (V : Integer; I : Positive := 1) return Positive
+renames Incr;
+
+  I : Integer;
+
+begin
+  I := Incr_Ren (-3);
+  I := Incr_Ren (-3, 2);
+  I := Incr_Ren (-3, 0);
+end;