[gcc r15-9873] Fix compilation of concatenation with illegal character constant

2025-06-28 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:06a26f4d643a5d045d893cd443425b13bd3d1b4b

commit r15-9873-g06a26f4d643a5d045d893cd443425b13bd3d1b4b
Author: Eric Botcazou 
Date:   Sat Jun 28 17:42:26 2025 +0200

Fix compilation of concatenation with illegal character constant

This fixes an error recovery issue, whereby the compilation of a string
concatenation with an illegal character constant hangs.

gcc/ada/
PR ada/120854
* sem_eval.adb (Get_String_Val): Be prepared for an integer literal
after a serious error is detected, and raise PE on other nodes.
gcc/testsuite/
* gnat.dg/concat6.adb: New test.

Diff:
---
 gcc/ada/sem_eval.adb  | 11 +--
 gcc/testsuite/gnat.dg/concat6.adb |  9 +
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb
index b7dfe01f2973..668f5f6010c2 100644
--- a/gcc/ada/sem_eval.adb
+++ b/gcc/ada/sem_eval.adb
@@ -5290,9 +5290,16 @@ package body Sem_Eval is
begin
   if Nkind (N) in N_String_Literal | N_Character_Literal then
  return N;
-  else
- pragma Assert (Is_Entity_Name (N));
+  elsif Is_Entity_Name (N) then
  return Get_String_Val (Constant_Value (Entity (N)));
+  elsif Nkind (N) = N_Integer_Literal then
+ pragma Assert (Serious_Errors_Detected /= 0);
+ return
+   Make_Character_Literal (Sloc (N),
+ Chars  => Error_Name,
+ Char_Literal_Value => Intval (N));
+  else
+ raise Program_Error;
   end if;
end Get_String_Val;
 
diff --git a/gcc/testsuite/gnat.dg/concat6.adb 
b/gcc/testsuite/gnat.dg/concat6.adb
new file mode 100644
index ..015be56bcb2b
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/concat6.adb
@@ -0,0 +1,9 @@
+-- { dg-do compile }
+
+with Ada.Text_IO; use Ada.Text_IO;
+
+procedure Concat6 is
+  C : constant character := 16#00#; -- { dg-error "expected type|found type" }
+begin
+  Put_Line ("Test " & C);
+end;


[gcc r16-1761] Fix compilation of concatenation with illegal character constant

2025-06-28 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:0788add46a172b7b1c565fafdef80979be3dc2a6

commit r16-1761-g0788add46a172b7b1c565fafdef80979be3dc2a6
Author: Eric Botcazou 
Date:   Sat Jun 28 17:42:26 2025 +0200

Fix compilation of concatenation with illegal character constant

This fixes an error recovery issue, whereby the compilation of a string
concatenation with an illegal character constant hangs.

gcc/ada/
PR ada/120854
* sem_eval.adb (Get_String_Val): Be prepared for an integer literal
after a serious error is detected, and raise PE on other nodes.
gcc/testsuite/
* gnat.dg/concat6.adb: New test.

Diff:
---
 gcc/ada/sem_eval.adb  | 11 +--
 gcc/testsuite/gnat.dg/concat6.adb |  9 +
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb
index fcab3e79d332..2d64d845ae24 100644
--- a/gcc/ada/sem_eval.adb
+++ b/gcc/ada/sem_eval.adb
@@ -5287,9 +5287,16 @@ package body Sem_Eval is
begin
   if Nkind (N) in N_String_Literal | N_Character_Literal then
  return N;
-  else
- pragma Assert (Is_Entity_Name (N));
+  elsif Is_Entity_Name (N) then
  return Get_String_Val (Constant_Value (Entity (N)));
+  elsif Nkind (N) = N_Integer_Literal then
+ pragma Assert (Serious_Errors_Detected /= 0);
+ return
+   Make_Character_Literal (Sloc (N),
+ Chars  => Error_Name,
+ Char_Literal_Value => Intval (N));
+  else
+ raise Program_Error;
   end if;
end Get_String_Val;
 
diff --git a/gcc/testsuite/gnat.dg/concat6.adb 
b/gcc/testsuite/gnat.dg/concat6.adb
new file mode 100644
index ..015be56bcb2b
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/concat6.adb
@@ -0,0 +1,9 @@
+-- { dg-do compile }
+
+with Ada.Text_IO; use Ada.Text_IO;
+
+procedure Concat6 is
+  C : constant character := 16#00#; -- { dg-error "expected type|found type" }
+begin
+  Put_Line ("Test " & C);
+end;


[gcc r16-1758] AVR: target/120856 - Deny R24:DI in avr_hard_regno_mode_ok with Reload.

2025-06-28 Thread Georg-Johann Lay via Gcc-cvs
https://gcc.gnu.org/g:13390e1b65f499ba33b7b5ff76bd9936e81b74e4

commit r16-1758-g13390e1b65f499ba33b7b5ff76bd9936e81b74e4
Author: Georg-Johann Lay 
Date:   Sat Jun 28 16:22:50 2025 +0200

AVR: target/120856 - Deny R24:DI in avr_hard_regno_mode_ok with Reload.

This fixes an ICE with -mno-lra when split2 tries to split the following
zero_extendsidi2 insn:

   (set (reg:DI 24)
(zero_extend:DI (reg:SI **)))

The ICE is because avr_hard_regno_mode_ok allows R24:DI but disallows
R28:SI when Reload is used.  R28:SI is a result of zero_extendsidi2.

This ICE only occurs with Reload (which will die before very long),
but it occurs when building libgcc.

gcc/
PR target/120856
* config/avr/avr.cc (avr_hard_regno_mode_ok) [-mno-lra]: Deny
hard regs >= 4 bytes that overlap Y.

Diff:
---
 gcc/config/avr/avr.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index f651692536b1..c469297d6d09 100644
--- a/gcc/config/avr/avr.cc
+++ b/gcc/config/avr/avr.cc
@@ -14148,7 +14148,7 @@ avr_hard_regno_mode_ok (unsigned int regno, 
machine_mode mode)
address registers is extreme stress test for reload.  */
 
   if (GET_MODE_SIZE (mode) >= 4
-  && regno >= REG_X
+  && regno + GET_MODE_SIZE (mode) >= REG_30
   // This problem only concerned the old reload.
   && ! avropt_lra_p)
 return false;


[gcc r16-1760] c++/modules: Make bitfield storage unit detection more robust

2025-06-28 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:f20f6c796499d097d301104fb2abe49fb77ce492

commit r16-1760-gf20f6c796499d097d301104fb2abe49fb77ce492
Author: Nathaniel Shead 
Date:   Fri Jun 27 18:56:25 2025 +1000

c++/modules: Make bitfield storage unit detection more robust

Modules streaming needs to handle these differently from other unnamed
FIELD_DECLs that are streamed for internal RECORD_DECLs, and there
doesn't seem to be a good way to detect this case otherwise.

This matters only to allow for compiler-generated type definitions that
build FIELD_DECLs with no name, as otherwise they get confused.
Currently the only such types left I hadn't earlier fixed by giving
names to are contextless, for which we have an early check to mark their
fields as MK_unique anyway, but there may be other cases in the future.

gcc/cp/ChangeLog:

* module.cc (trees_out::walking_bit_field_unit): New flag.
(trees_out::trees_out): Initialize it.
(trees_out::core_vals): Set it.
(trees_out::get_merge_kind): Use it, move previous ad-hoc check
into assertion.

Signed-off-by: Nathaniel Shead 

Diff:
---
 gcc/cp/module.cc | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 846e532c4380..c8e79f33af41 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -3097,6 +3097,9 @@ private:
   unsigned section;
   bool writing_local_entities; /* Whether we might walk into a TU-local
   entity we need to emit placeholders for.  */
+  bool walking_bit_field_unit;  /* Whether we're walking the underlying
+  storage for a bit field.  There's no other
+  great way to detect this.  */
 #if CHECKING_P
   int importedness;/* Checker that imports not occurring
   inappropriately.  +ve imports ok,
@@ -3263,7 +3266,7 @@ trees_out::trees_out (allocator *mem, module_state 
*state, depset::hash &deps,
  unsigned section)
   :parent (mem), state (state), tree_map (500),
dep_hash (&deps), ref_num (0), section (section),
-   writing_local_entities (false)
+   writing_local_entities (false), walking_bit_field_unit (false)
 {
 #if CHECKING_P
   importedness = 0;
@@ -6512,7 +6515,10 @@ trees_out::core_vals (tree t)
 case FIELD_DECL:
   WT (t->field_decl.offset);
   WT (t->field_decl.bit_field_type);
-  WT (t->field_decl.qualifier); /* bitfield unit.  */
+  {
+   auto ovr = make_temp_override (walking_bit_field_unit, true);
+   WT (t->field_decl.qualifier); /* bitfield unit.  */
+  }
   WT (t->field_decl.bit_offset);
   WT (t->field_decl.fcontext);
   WT (t->decl_common.initial);
@@ -11272,15 +11278,16 @@ trees_out::get_merge_kind (tree decl, depset *dep)
  return MK_named;
}
 
- if (!DECL_NAME (decl)
- && !RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))
- && !DECL_BIT_FIELD_REPRESENTATIVE (decl))
+ if (walking_bit_field_unit)
{
  /* The underlying storage unit for a bitfield.  We do not
 need to dedup it, because it's only reachable through
 the bitfields it represents.  And those are deduped.  */
  // FIXME: Is that assertion correct -- do we ever fish it
  // out and put it in an expr?
+ gcc_checking_assert (!DECL_NAME (decl)
+  && !RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))
+  && !DECL_BIT_FIELD_REPRESENTATIVE (decl));
  gcc_checking_assert ((TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
? TREE_CODE (TREE_TYPE (TREE_TYPE (decl)))
: TREE_CODE (TREE_TYPE (decl)))


[gcc r16-1759] c++/modules: Ensure type of partial spec VAR_DECL is consistent with its template [PR120644]

2025-06-28 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:98fd493db6216cff11142c9dc477a3ff8e4269fa

commit r16-1759-g98fd493db6216cff11142c9dc477a3ff8e4269fa
Author: Nathaniel Shead 
Date:   Mon Jun 23 22:24:22 2025 +1000

c++/modules: Ensure type of partial spec VAR_DECL is consistent with its 
template [PR120644]

We were erroring because the TEMPLATE_DECL of the existing partial
specialisation has an undeduced return type, but the imported
declaration did not.

The root cause is similar to what was fixed in r13-2744-g4fac53d6522189,
where modules streaming code assumes that a TEMPLATE_DECL and its
DECL_TEMPLATE_RESULT will always have the same TREE_TYPE.  That commit
fixed the issue by ensuring that when the type of a variable is deduced
the TEMPLATE_DECL is updated as well, but missed handling partial
specialisations.  This patch ensures that the same adjustment is made
there as well.

PR c++/120644

gcc/cp/ChangeLog:

* decl.cc (cp_finish_decl): Also propagate type to partial
templates.
* module.cc (trees_out::decl_value): Add assertion that the
TREE_TYPE of a streamed template decl matches its inner.
(trees_in::is_matching_decl): Clarify function return type
deduction should only occur for non-TEMPLATE_DECL.
* pt.cc (template_for_substitution): Handle partial specs.

gcc/testsuite/ChangeLog:

* g++.dg/modules/auto-7.h: New test.
* g++.dg/modules/auto-7_a.H: New test.
* g++.dg/modules/auto-7_b.C: New test.

Signed-off-by: Nathaniel Shead 
Reviewed-by: Jason Merrill 
Reviewed-by: Patrick Palka 

Diff:
---
 gcc/cp/decl.cc  | 10 ++
 gcc/cp/module.cc|  7 ++-
 gcc/cp/pt.cc|  4 
 gcc/testsuite/g++.dg/modules/auto-7.h   | 12 
 gcc/testsuite/g++.dg/modules/auto-7_a.H |  5 +
 gcc/testsuite/g++.dg/modules/auto-7_b.C |  5 +
 6 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 4fe97ffbf8f9..83c8e283b56a 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -8923,10 +8923,12 @@ cp_finish_decl (tree decl, tree init, bool 
init_const_expr_p,
   cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
 
   /* Update the type of the corresponding TEMPLATE_DECL to match.  */
-  if (DECL_LANG_SPECIFIC (decl)
- && DECL_TEMPLATE_INFO (decl)
- && DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (decl)) == decl)
-   TREE_TYPE (DECL_TI_TEMPLATE (decl)) = type;
+  if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
+   {
+ tree tmpl = template_for_substitution (decl);
+ if (DECL_TEMPLATE_RESULT (tmpl) == decl)
+   TREE_TYPE (tmpl) = type;
+   }
 }
 
   if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 42a1b83e1643..846e532c4380 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -8213,6 +8213,10 @@ trees_out::decl_value (tree decl, depset *dep)
   inner = DECL_TEMPLATE_RESULT (decl);
   inner_tag = insert (inner, WK_value);
 
+  /* On stream-in we assume that a template and its result will
+have the same type.  */
+  gcc_checking_assert (TREE_TYPE (decl) == TREE_TYPE (inner));
+
   if (streaming_p ())
{
  int code = TREE_CODE (inner);
@@ -12325,7 +12329,8 @@ trees_in::is_matching_decl (tree existing, tree decl, 
bool is_typedef)
{
  dump (dumper::MERGE)
&& dump ("Propagating deduced return type to %N", existing);
- FNDECL_USED_AUTO (e_inner) = true;
+ gcc_checking_assert (existing == e_inner);
+ FNDECL_USED_AUTO (existing) = true;
  DECL_SAVED_AUTO_RETURN_TYPE (existing) = TREE_TYPE (e_type);
  TREE_TYPE (existing) = change_return_type (TREE_TYPE (d_type), 
e_type);
}
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index c7a0066a11ac..3362a6f8f9ca 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -27537,6 +27537,10 @@ tree
 template_for_substitution (tree decl)
 {
   tree tmpl = DECL_TI_TEMPLATE (decl);
+  if (VAR_P (decl))
+if (tree partial = most_specialized_partial_spec (decl, tf_none))
+  if (partial != error_mark_node)
+   tmpl = TI_TEMPLATE (partial);
 
   /* Set TMPL to the template whose DECL_TEMPLATE_RESULT is the pattern
  for the instantiation.  This is not always the most general
diff --git a/gcc/testsuite/g++.dg/modules/auto-7.h 
b/gcc/testsuite/g++.dg/modules/auto-7.h
new file mode 100644
index ..324b60cfa0ae
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/auto-7.h
@@ -0,0 +1,12 @@
+// PR c++/120644
+
+enum class E { E0, E1 };
+
+template 
+constexpr auto fmt_kind = E::E0;
+
+template 
+class opt{};
+
+template 
+constexpr auto fmt_kind> = E::E1;
diff --git a/gcc/testsuite/g++.dg/

[gcc r15-9872] Ada: Fix assertion failure on problematic container aggregate

2025-06-28 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:80c55b15f8d6e6b1f10c193b60e19194a871070d

commit r15-9872-g80c55b15f8d6e6b1f10c193b60e19194a871070d
Author: Eric Botcazou 
Date:   Tue Jun 17 18:55:39 2025 +0200

Ada: Fix assertion failure on problematic container aggregate

This is an assertion failure on code using a container aggregate in the
primitives referenced by the Aggregate aspect, which cannot work.

gcc/ada/
PR ada/120665
* sem_aggr.adb (Resolve_Container_Aggregate): Use robust guards.

gcc/testsuite/
* gnat.dg/specs/aggr8.ads: New test.

Diff:
---
 gcc/ada/sem_aggr.adb  | 10 ++
 gcc/testsuite/gnat.dg/specs/aggr8.ads | 14 ++
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index a7ec772823f6..5c330eb75c1b 100644
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -4052,8 +4052,8 @@ package body Sem_Aggr is
 
   if Present (Add_Unnamed_Subp)
 and then No (New_Indexed_Subp)
-and then Present (Etype (Add_Unnamed_Subp))
-and then Etype (Add_Unnamed_Subp) /= Any_Type
+and then Present (Entity (Add_Unnamed_Subp))
+and then Entity (Add_Unnamed_Subp) /= Any_Id
   then
  declare
 Elmt_Type : constant Entity_Id :=
@@ -4099,7 +4099,8 @@ package body Sem_Aggr is
  end;
 
   elsif Present (Add_Named_Subp)
-and then Etype (Add_Named_Subp) /= Any_Type
+and then Present (Entity (Add_Named_Subp))
+and then Entity (Add_Named_Subp) /= Any_Id
   then
  declare
 --  Retrieves types of container, key, and element from the
@@ -4153,7 +4154,8 @@ package body Sem_Aggr is
  end;
 
   elsif Present (Assign_Indexed_Subp)
-and then Etype (Assign_Indexed_Subp) /= Any_Type
+and then Present (Entity (Assign_Indexed_Subp))
+and then Entity (Assign_Indexed_Subp) /= Any_Id
   then
  --  Indexed Aggregate. Positional or indexed component
  --  can be present, but not both. Choices must be static
diff --git a/gcc/testsuite/gnat.dg/specs/aggr8.ads 
b/gcc/testsuite/gnat.dg/specs/aggr8.ads
new file mode 100644
index ..3847c4e4e9f9
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/specs/aggr8.ads
@@ -0,0 +1,14 @@
+-- PR ada/120665
+-- { dg-do compile }
+-- { dg-options "-gnat2022" }
+
+package Aggr8 is
+
+  type T is null record
+with Aggregate => (Empty => Empty, Add_Named => Add_Named);
+
+  function Empty return T is ([]);  -- { dg-warning "empty|infinite" }
+
+  procedure Add_Named (this : in out T; k : Integer; v : Integer) is null;
+
+end Aggr8;


[gcc r16-1757] Relax the testcase check for Solaris [PR120818]

2025-06-28 Thread Lili Cui via Gcc-cvs
https://gcc.gnu.org/g:e7fb2459b00cde4fb14062076df29320efafdb98

commit r16-1757-ge7fb2459b00cde4fb14062076df29320efafdb98
Author: Lili Cui 
Date:   Sat Jun 28 06:19:19 2025 -0700

Relax the testcase check for Solaris [PR120818]

gcc/testsuite/ChangeLog:

PR target/120818
* g++.target/i386/shrink_wrap_separate.C: Relax the check.

Diff:
---
 gcc/testsuite/g++.target/i386/shrink_wrap_separate.C | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/testsuite/g++.target/i386/shrink_wrap_separate.C 
b/gcc/testsuite/g++.target/i386/shrink_wrap_separate.C
index 294dccde5d31..b924fd02ca94 100644
--- a/gcc/testsuite/g++.target/i386/shrink_wrap_separate.C
+++ b/gcc/testsuite/g++.target/i386/shrink_wrap_separate.C
@@ -21,5 +21,4 @@ bool k() {
   b *n;
  return h(l->g, n);
 }
-/* { dg-final { scan-rtl-dump "The components we wrap separately are \\\[sep 3 
4\\\]" "pro_and_epilogue" { target { ia32 } } } } */
-/* { dg-final { scan-rtl-dump "The components we wrap separately are \\\[sep 
40 41 42 43\\\]" "pro_and_epilogue" { target { ! ia32 } } } } */
+/* { dg-final { scan-rtl-dump "The components we wrap separately are" 
"pro_and_epilogue" } } */


[gcc r16-1762] Add "void debug (tree)"

2025-06-28 Thread H.J. Lu via Gcc-cvs
https://gcc.gnu.org/g:5e5de088f99319aa755ef2af3def30a4ccd5765a

commit r16-1762-g5e5de088f99319aa755ef2af3def30a4ccd5765a
Author: H.J. Lu 
Date:   Sat Jun 28 07:32:01 2025 +0800

Add "void debug (tree)"

Add "void debug (tree)" to support:

(gdb) call debug (expr)
 
unit-size 
user align:256 warn_if_not_align:0 symtab:0 alias-set -1 
canonical-type 0x7fffe99cebd0
fields 
XF x.c:2:15
size 
unit-size 
align:128 warn_if_not_align:0 offset_align 128 
decl_not_flexarray: 1
offset 
bit-offset  context 
 chain >>
used read BLK x.c:7:6 size  unit-size 

align:256 warn_if_not_align:0 context  
arg-type >
(gdb)

PR debug/120849
* print-tree.cc (debug): New.
* print-tree.h (debug): Likewise.

Signed-off-by: H.J. Lu 

Diff:
---
 gcc/print-tree.cc | 6 ++
 gcc/print-tree.h  | 1 +
 2 files changed, 7 insertions(+)

diff --git a/gcc/print-tree.cc b/gcc/print-tree.cc
index 63b1f94a1d76..6ec96f0ba171 100644
--- a/gcc/print-tree.cc
+++ b/gcc/print-tree.cc
@@ -1148,6 +1148,12 @@ debug_tree (tree node)
   putc ('\n', stderr);
 }
 
+DEBUG_FUNCTION void
+debug (tree node)
+{
+  debug_tree (node);
+}
+
 DEBUG_FUNCTION void
 debug_raw (const tree_node &ref)
 {
diff --git a/gcc/print-tree.h b/gcc/print-tree.h
index fb729ccddd88..5c613ddb799d 100644
--- a/gcc/print-tree.h
+++ b/gcc/print-tree.h
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #define GCC_PRINT_TREE_H
 
 extern void debug_tree (tree);
+extern void debug (tree);
 extern void debug_raw (const tree_node &ref);
 extern void debug_raw (const tree_node *ptr);
 extern void debug (const tree_node &ref);