[gcc r14-9459] i386[stv]: Handle REG_EH_REGION note
https://gcc.gnu.org/g:618e34d56cc38e9c3ae95a413228068e53ed76bb commit r14-9459-g618e34d56cc38e9c3ae95a413228068e53ed76bb Author: liuhongt Date: Wed Mar 13 10:40:01 2024 +0800 i386[stv]: Handle REG_EH_REGION note When we split (insn 37 36 38 10 (set (reg:DI 104 [ _18 ]) (mem:DI (reg/f:SI 98 [ CallNative_nclosure.0_1 ]) [6 MEM[(struct SQRefCounted *)CallNative_nclosure.0_1]._uiRef+0 S8 A32])) "test.C":22:42 84 {*movdi_internal} (expr_list:REG_EH_REGION (const_int -11 [0xfff5]) into (insn 104 36 37 10 (set (subreg:V2DI (reg:DI 124) 0) (vec_concat:V2DI (mem:DI (reg/f:SI 98 [ CallNative_nclosure.0_1 ]) [6 MEM[(struct SQRefCounted *)CallNative_nclosure.0_1]._uiRef+0 S8 A32]) (const_int 0 [0]))) "test.C":22:42 -1 (nil))) (insn 37 104 105 10 (set (subreg:V2DI (reg:DI 104 [ _18 ]) 0) (subreg:V2DI (reg:DI 124) 0)) "test.C":22:42 2024 {movv2di_internal} (expr_list:REG_EH_REGION (const_int -11 [0xfff5]) (nil))) we must copy the REG_EH_REGION note to the first insn and split the block after the newly added insn. The REG_EH_REGION on the second insn will be removed later since it no longer traps. gcc/ChangeLog: * config/i386/i386-features.cc (general_scalar_chain::convert_op): Handle REG_EH_REGION note. (convert_scalars_to_vector): Ditto. * config/i386/i386-features.h (class scalar_chain): New memeber control_flow_insns. gcc/testsuite/ChangeLog: * g++.target/i386/pr111822.C: New test. Diff: --- gcc/config/i386/i386-features.cc | 50 gcc/config/i386/i386-features.h | 1 + gcc/testsuite/g++.target/i386/pr111822.C | 45 3 files changed, 91 insertions(+), 5 deletions(-) diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc index 1de2a07ed75..c7d7a965901 100644 --- a/gcc/config/i386/i386-features.cc +++ b/gcc/config/i386/i386-features.cc @@ -998,20 +998,36 @@ general_scalar_chain::convert_op (rtx *op, rtx_insn *insn) } else if (MEM_P (*op)) { + rtx_insn* eh_insn, *movabs = NULL; rtx tmp = gen_reg_rtx (GET_MODE (*op)); - /* Handle movabs. */ + /* Emit MOVABS to load from a 64-bit absolute address to a GPR. */ if (!memory_operand (*op, GET_MODE (*op))) { rtx tmp2 = gen_reg_rtx (GET_MODE (*op)); + movabs = emit_insn_before (gen_rtx_SET (tmp2, *op), insn); - emit_insn_before (gen_rtx_SET (tmp2, *op), insn); *op = tmp2; } - emit_insn_before (gen_rtx_SET (gen_rtx_SUBREG (vmode, tmp, 0), -gen_gpr_to_xmm_move_src (vmode, *op)), - insn); + eh_insn + = emit_insn_before (gen_rtx_SET (gen_rtx_SUBREG (vmode, tmp, 0), +gen_gpr_to_xmm_move_src (vmode, *op)), + insn); + + if (cfun->can_throw_non_call_exceptions) + { + /* Handle REG_EH_REGION note. */ + rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX); + if (note) + { + if (movabs) + eh_insn = movabs; + control_flow_insns.safe_push (eh_insn); + add_reg_note (eh_insn, REG_EH_REGION, XEXP (note, 0)); + } + } + *op = gen_rtx_SUBREG (vmode, tmp, 0); if (dump_file) @@ -2494,6 +2510,7 @@ convert_scalars_to_vector (bool timode_p) { basic_block bb; int converted_insns = 0; + auto_vec control_flow_insns; bitmap_obstack_initialize (NULL); const machine_mode cand_mode[3] = { SImode, DImode, TImode }; @@ -2575,6 +2592,11 @@ convert_scalars_to_vector (bool timode_p) chain->chain_id); } + rtx_insn* iter_insn; + unsigned int ii; + FOR_EACH_VEC_ELT (chain->control_flow_insns, ii, iter_insn) + control_flow_insns.safe_push (iter_insn); + delete chain; } } @@ -2643,6 +2665,24 @@ convert_scalars_to_vector (bool timode_p) DECL_INCOMING_RTL (parm) = gen_rtx_SUBREG (TImode, r, 0); } } + + if (!control_flow_insns.is_empty ()) + { + free_dominance_info (CDI_DOMINATORS); + + unsigned int i; + rtx_insn* insn; + FOR_EACH_VEC_ELT (control_flow_insns, i, insn) + if (control_flow_insn_p (insn)) + { + /* Split the block after insn. There will be a fallthru + edge, which is OK so we keep it. We have to create + the exception edges ourselves. */ + bb = BLOCK_FOR_INSN (insn); + split_block (bb, insn); + rtl_make_eh_edge (NULL, bb, BB_END (bb)); + } +
[gcc r13-8438] i386[stv]: Handle REG_EH_REGION note
https://gcc.gnu.org/g:bdbcfbfcf591381f0faf95c881e3772b56d0a404 commit r13-8438-gbdbcfbfcf591381f0faf95c881e3772b56d0a404 Author: liuhongt Date: Wed Mar 13 10:40:01 2024 +0800 i386[stv]: Handle REG_EH_REGION note When we split (insn 37 36 38 10 (set (reg:DI 104 [ _18 ]) (mem:DI (reg/f:SI 98 [ CallNative_nclosure.0_1 ]) [6 MEM[(struct SQRefCounted *)CallNative_nclosure.0_1]._uiRef+0 S8 A32])) "test.C":22:42 84 {*movdi_internal} (expr_list:REG_EH_REGION (const_int -11 [0xfff5]) into (insn 104 36 37 10 (set (subreg:V2DI (reg:DI 124) 0) (vec_concat:V2DI (mem:DI (reg/f:SI 98 [ CallNative_nclosure.0_1 ]) [6 MEM[(struct SQRefCounted *)CallNative_nclosure.0_1]._uiRef+0 S8 A32]) (const_int 0 [0]))) "test.C":22:42 -1 (nil))) (insn 37 104 105 10 (set (subreg:V2DI (reg:DI 104 [ _18 ]) 0) (subreg:V2DI (reg:DI 124) 0)) "test.C":22:42 2024 {movv2di_internal} (expr_list:REG_EH_REGION (const_int -11 [0xfff5]) (nil))) we must copy the REG_EH_REGION note to the first insn and split the block after the newly added insn. The REG_EH_REGION on the second insn will be removed later since it no longer traps. gcc/ChangeLog: * config/i386/i386-features.cc (general_scalar_chain::convert_op): Handle REG_EH_REGION note. (convert_scalars_to_vector): Ditto. * config/i386/i386-features.h (class scalar_chain): New memeber control_flow_insns. gcc/testsuite/ChangeLog: * g++.target/i386/pr111822.C: New test. (cherry picked from commit 618e34d56cc38e9c3ae95a413228068e53ed76bb) Diff: --- gcc/config/i386/i386-features.cc | 50 gcc/config/i386/i386-features.h | 1 + gcc/testsuite/g++.target/i386/pr111822.C | 45 3 files changed, 91 insertions(+), 5 deletions(-) diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc index 74ee14a584a..ed3055b43f8 100644 --- a/gcc/config/i386/i386-features.cc +++ b/gcc/config/i386/i386-features.cc @@ -913,20 +913,36 @@ general_scalar_chain::convert_op (rtx *op, rtx_insn *insn) } else if (MEM_P (*op)) { + rtx_insn* eh_insn, *movabs = NULL; rtx tmp = gen_reg_rtx (GET_MODE (*op)); - /* Handle movabs. */ + /* Emit MOVABS to load from a 64-bit absolute address to a GPR. */ if (!memory_operand (*op, GET_MODE (*op))) { rtx tmp2 = gen_reg_rtx (GET_MODE (*op)); + movabs = emit_insn_before (gen_rtx_SET (tmp2, *op), insn); - emit_insn_before (gen_rtx_SET (tmp2, *op), insn); *op = tmp2; } - emit_insn_before (gen_rtx_SET (gen_rtx_SUBREG (vmode, tmp, 0), -gen_gpr_to_xmm_move_src (vmode, *op)), - insn); + eh_insn + = emit_insn_before (gen_rtx_SET (gen_rtx_SUBREG (vmode, tmp, 0), +gen_gpr_to_xmm_move_src (vmode, *op)), + insn); + + if (cfun->can_throw_non_call_exceptions) + { + /* Handle REG_EH_REGION note. */ + rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX); + if (note) + { + if (movabs) + eh_insn = movabs; + control_flow_insns.safe_push (eh_insn); + add_reg_note (eh_insn, REG_EH_REGION, XEXP (note, 0)); + } + } + *op = gen_rtx_SUBREG (vmode, tmp, 0); if (dump_file) @@ -2215,6 +2231,7 @@ convert_scalars_to_vector (bool timode_p) { basic_block bb; int converted_insns = 0; + auto_vec control_flow_insns; bitmap_obstack_initialize (NULL); const machine_mode cand_mode[3] = { SImode, DImode, TImode }; @@ -2296,6 +2313,11 @@ convert_scalars_to_vector (bool timode_p) chain->chain_id); } + rtx_insn* iter_insn; + unsigned int ii; + FOR_EACH_VEC_ELT (chain->control_flow_insns, ii, iter_insn) + control_flow_insns.safe_push (iter_insn); + delete chain; } } @@ -2364,6 +2386,24 @@ convert_scalars_to_vector (bool timode_p) DECL_INCOMING_RTL (parm) = gen_rtx_SUBREG (TImode, r, 0); } } + + if (!control_flow_insns.is_empty ()) + { + free_dominance_info (CDI_DOMINATORS); + + unsigned int i; + rtx_insn* insn; + FOR_EACH_VEC_ELT (control_flow_insns, i, insn) + if (control_flow_insn_p (insn)) + { + /* Split the block after insn. There will be a fallthru + edge, which is OK so we keep it. We have to create + the exception edges ourselves. */ + bb = BLOCK_FOR_INSN (insn); + split_block (bb, insn);
[gcc r12-10214] i386[stv]: Handle REG_EH_REGION note
https://gcc.gnu.org/g:a861f940efffae2782c559cd04df2d2740cd28bd commit r12-10214-ga861f940efffae2782c559cd04df2d2740cd28bd Author: liuhongt Date: Wed Mar 13 10:40:01 2024 +0800 i386[stv]: Handle REG_EH_REGION note When we split (insn 37 36 38 10 (set (reg:DI 104 [ _18 ]) (mem:DI (reg/f:SI 98 [ CallNative_nclosure.0_1 ]) [6 MEM[(struct SQRefCounted *)CallNative_nclosure.0_1]._uiRef+0 S8 A32])) "test.C":22:42 84 {*movdi_internal} (expr_list:REG_EH_REGION (const_int -11 [0xfff5]) into (insn 104 36 37 10 (set (subreg:V2DI (reg:DI 124) 0) (vec_concat:V2DI (mem:DI (reg/f:SI 98 [ CallNative_nclosure.0_1 ]) [6 MEM[(struct SQRefCounted *)CallNative_nclosure.0_1]._uiRef+0 S8 A32]) (const_int 0 [0]))) "test.C":22:42 -1 (nil))) (insn 37 104 105 10 (set (subreg:V2DI (reg:DI 104 [ _18 ]) 0) (subreg:V2DI (reg:DI 124) 0)) "test.C":22:42 2024 {movv2di_internal} (expr_list:REG_EH_REGION (const_int -11 [0xfff5]) (nil))) we must copy the REG_EH_REGION note to the first insn and split the block after the newly added insn. The REG_EH_REGION on the second insn will be removed later since it no longer traps. gcc/ChangeLog: * config/i386/i386-features.cc (general_scalar_chain::convert_op): Handle REG_EH_REGION note. (convert_scalars_to_vector): Ditto. * config/i386/i386-features.h (class scalar_chain): New memeber control_flow_insns. gcc/testsuite/ChangeLog: * g++.target/i386/pr111822.C: New test. (cherry picked from commit 618e34d56cc38e9c3ae95a413228068e53ed76bb) Diff: --- gcc/config/i386/i386-features.cc | 50 gcc/config/i386/i386-features.h | 1 + gcc/testsuite/g++.target/i386/pr111822.C | 45 3 files changed, 91 insertions(+), 5 deletions(-) diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc index 6a2444eb6b6..37f22ba3733 100644 --- a/gcc/config/i386/i386-features.cc +++ b/gcc/config/i386/i386-features.cc @@ -871,20 +871,36 @@ general_scalar_chain::convert_op (rtx *op, rtx_insn *insn) } else if (MEM_P (*op)) { + rtx_insn* eh_insn, *movabs = NULL; rtx tmp = gen_reg_rtx (GET_MODE (*op)); - /* Handle movabs. */ + /* Emit MOVABS to load from a 64-bit absolute address to a GPR. */ if (!memory_operand (*op, GET_MODE (*op))) { rtx tmp2 = gen_reg_rtx (GET_MODE (*op)); + movabs = emit_insn_before (gen_rtx_SET (tmp2, *op), insn); - emit_insn_before (gen_rtx_SET (tmp2, *op), insn); *op = tmp2; } - emit_insn_before (gen_rtx_SET (gen_rtx_SUBREG (vmode, tmp, 0), -gen_gpr_to_xmm_move_src (vmode, *op)), - insn); + eh_insn + = emit_insn_before (gen_rtx_SET (gen_rtx_SUBREG (vmode, tmp, 0), +gen_gpr_to_xmm_move_src (vmode, *op)), + insn); + + if (cfun->can_throw_non_call_exceptions) + { + /* Handle REG_EH_REGION note. */ + rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX); + if (note) + { + if (movabs) + eh_insn = movabs; + control_flow_insns.safe_push (eh_insn); + add_reg_note (eh_insn, REG_EH_REGION, XEXP (note, 0)); + } + } + *op = gen_rtx_SUBREG (vmode, tmp, 0); if (dump_file) @@ -1681,6 +1697,7 @@ convert_scalars_to_vector (bool timode_p) { basic_block bb; int converted_insns = 0; + auto_vec control_flow_insns; bitmap_obstack_initialize (NULL); const machine_mode cand_mode[3] = { SImode, DImode, TImode }; @@ -1759,6 +1776,11 @@ convert_scalars_to_vector (bool timode_p) fprintf (dump_file, "Chain #%d conversion is not profitable\n", chain->chain_id); + rtx_insn* iter_insn; + unsigned int ii; + FOR_EACH_VEC_ELT (chain->control_flow_insns, ii, iter_insn) + control_flow_insns.safe_push (iter_insn); + delete chain; } @@ -1826,6 +1848,24 @@ convert_scalars_to_vector (bool timode_p) DECL_INCOMING_RTL (parm) = gen_rtx_SUBREG (TImode, r, 0); } } + + if (!control_flow_insns.is_empty ()) + { + free_dominance_info (CDI_DOMINATORS); + + unsigned int i; + rtx_insn* insn; + FOR_EACH_VEC_ELT (control_flow_insns, i, insn) + if (control_flow_insn_p (insn)) + { + /* Split the block after insn. There will be a fallthru + edge, which is OK so we keep it. We have to create + the exception edges ourselves. */ + bb = BLOCK_FOR_INSN (ins
[gcc r14-9460] gimple-iterator: Some gsi_safe_insert_*before fixes
https://gcc.gnu.org/g:8f6e0814b4bfd0a399055e9214562aebfcd902ad commit r14-9460-g8f6e0814b4bfd0a399055e9214562aebfcd902ad Author: Jakub Jelinek Date: Thu Mar 14 09:57:13 2024 +0100 gimple-iterator: Some gsi_safe_insert_*before fixes When trying to use the gsi_safe_insert*before APIs in bitint lowering, I've discovered 3 issues and the following patch addresses those: 1) both split_block and split_edge update CDI_DOMINATORS if they are available, but because edge_before_returns_twice_call first splits and then adds an extra EDGE_ABNORMAL edge and then removes another one, the immediate dominators of both the new bb and the bb with returns_twice call need to change 2) the new EDGE_ABNORMAL edge had uninitialized probability; this patch copies the probability from the edge that is going to be removed and similarly copies other flags (EDGE_EXECUTABLE, EDGE_DFS_BACK, EDGE_IRREDUCIBLE_LOOP etc.) 3) if edge_before_returns_twice_call splits a block, then the bb with returns_twice call changes, so the gimple_stmt_iterator for it is no longer accurate, it points to the right statement, but gsi_bb and gsi_seq are no longer correct; the patch updates it 2024-03-14 Jakub Jelinek * gimple-iterator.cc (edge_before_returns_twice_call): Copy all flags and probability from ad_edge to e edge. If CDI_DOMINATORS are computed, recompute immediate dominator of other_edge->src and other_edge->dest. (gsi_safe_insert_before, gsi_safe_insert_seq_before): Update *iter for the returns_twice call case to the gsi_for_stmt (stmt) to deal with update it for bb splitting. Diff: --- gcc/gimple-iterator.cc | 13 + 1 file changed, 13 insertions(+) diff --git a/gcc/gimple-iterator.cc b/gcc/gimple-iterator.cc index 531c8aed824..ac6cb4aa414 100644 --- a/gcc/gimple-iterator.cc +++ b/gcc/gimple-iterator.cc @@ -997,7 +997,18 @@ edge_before_returns_twice_call (basic_block bb) add_phi_arg (new_phi, gimple_phi_arg_def_from_edge (phi, ad_edge), e, gimple_phi_arg_location_from_edge (phi, ad_edge)); } + e->flags = ad_edge->flags; + e->probability = ad_edge->probability; remove_edge (ad_edge); + if (dom_info_available_p (CDI_DOMINATORS)) + { + set_immediate_dominator (CDI_DOMINATORS, other_edge->src, + recompute_dominator (CDI_DOMINATORS, + other_edge->src)); + set_immediate_dominator (CDI_DOMINATORS, other_edge->dest, + recompute_dominator (CDI_DOMINATORS, + other_edge->dest)); + } } return other_edge; } @@ -1045,6 +1056,7 @@ gsi_safe_insert_before (gimple_stmt_iterator *iter, gimple *g) if (new_bb) e = single_succ_edge (new_bb); adjust_before_returns_twice_call (e, g); + *iter = gsi_for_stmt (stmt); } else gsi_insert_before (iter, g, GSI_SAME_STMT); @@ -1075,6 +1087,7 @@ gsi_safe_insert_seq_before (gimple_stmt_iterator *iter, gimple_seq seq) if (g == l) break; } + *iter = gsi_for_stmt (stmt); } else gsi_insert_seq_before (iter, seq, GSI_SAME_STMT);
[gcc r14-9461] IBM Z: Fix -munaligned-symbols
https://gcc.gnu.org/g:90a7da695284da49182446ba45fbcddb9eb7fc91 commit r14-9461-g90a7da695284da49182446ba45fbcddb9eb7fc91 Author: Andreas Krebbel Date: Thu Mar 14 09:54:31 2024 +0100 IBM Z: Fix -munaligned-symbols With this fix we make sure that only symbols with a natural alignment smaller than 2 are considered misaligned with -munaligned-symbols. Background is that -munaligned-symbols is only supposed to affect symbols whose natural alignment wouldn't be enough to fulfill our ABI requirement of having all symbols at even addresses. Because only these are the cases where we differ from other architectures. gcc/ChangeLog: * config/s390/s390.cc (s390_encode_section_info): Adjust the check for misaligned symbols. * config/s390/s390.opt: Improve documentation. gcc/testsuite/ChangeLog: * gcc.target/s390/aligned-1.c: Add weak and void variables incorporating the cases from unaligned-2.c. * gcc.target/s390/unaligned-1.c: Likewise. * gcc.target/s390/unaligned-2.c: Removed. Diff: --- gcc/config/s390/s390.cc | 15 +++- gcc/config/s390/s390.opt| 7 +- gcc/testsuite/gcc.target/s390/aligned-1.c | 101 --- gcc/testsuite/gcc.target/s390/unaligned-1.c | 103 +--- gcc/testsuite/gcc.target/s390/unaligned-2.c | 16 - 5 files changed, 201 insertions(+), 41 deletions(-) diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc index e63965578f1..372a2324403 100644 --- a/gcc/config/s390/s390.cc +++ b/gcc/config/s390/s390.cc @@ -13802,10 +13802,19 @@ s390_encode_section_info (tree decl, rtx rtl, int first) that can go wrong (i.e. no FUNC_DECLs). All symbols without an explicit alignment are assumed to be 2 byte aligned as mandated by our ABI. This behavior can be -overridden for external symbols with the -munaligned-symbols -switch. */ +overridden for external and weak symbols with the +-munaligned-symbols switch. +For all external symbols without explicit alignment +DECL_ALIGN is already trimmed down to 8, however for weak +symbols this does not happen. These cases are catched by the +type size check. */ + const_tree size = TYPE_SIZE (TREE_TYPE (decl)); + unsigned HOST_WIDE_INT size_num = (tree_fits_uhwi_p (size) +? tree_to_uhwi (size) : 0); if ((DECL_USER_ALIGN (decl) && DECL_ALIGN (decl) % 16) - || (s390_unaligned_symbols_p && !decl_binds_to_current_def_p (decl))) + || (s390_unaligned_symbols_p + && !decl_binds_to_current_def_p (decl) + && (DECL_USER_ALIGN (decl) ? DECL_ALIGN (decl) % 16 : size_num < 16))) SYMBOL_FLAG_SET_NOTALIGN2 (XEXP (rtl, 0)); else if (DECL_ALIGN (decl) % 32) SYMBOL_FLAG_SET_NOTALIGN4 (XEXP (rtl, 0)); diff --git a/gcc/config/s390/s390.opt b/gcc/config/s390/s390.opt index 901ae4beb01..a5b5aa95a12 100644 --- a/gcc/config/s390/s390.opt +++ b/gcc/config/s390/s390.opt @@ -332,7 +332,8 @@ Store all argument registers on the stack. munaligned-symbols Target Var(s390_unaligned_symbols_p) Init(0) -Assume external symbols to be potentially unaligned. By default all -symbols without explicit alignment are assumed to reside on a 2 byte -boundary as mandated by the IBM Z ABI. +Assume external symbols, whose natural alignment would be 1, to be +potentially unaligned. By default all symbols without explicit +alignment are assumed to reside on a 2 byte boundary as mandated by +the IBM Z ABI. diff --git a/gcc/testsuite/gcc.target/s390/aligned-1.c b/gcc/testsuite/gcc.target/s390/aligned-1.c index 2dc99cf66bd..3f5a2611ef1 100644 --- a/gcc/testsuite/gcc.target/s390/aligned-1.c +++ b/gcc/testsuite/gcc.target/s390/aligned-1.c @@ -1,20 +1,103 @@ -/* Even symbols without explicite alignment are assumed to reside on a +/* Even symbols without explicit alignment are assumed to reside on a 2 byte boundary, as mandated by the IBM Z ELF ABI, and therefore can be accessed using the larl instruction. */ /* { dg-do compile } */ /* { dg-options "-O3 -march=z900 -fno-section-anchors" } */ -extern unsigned char extern_implicitly_aligned; -extern unsigned char extern_explicitly_aligned __attribute__((aligned(2))); -unsigned char aligned; +extern unsigned char extern_char; +extern unsigned char extern_explicitly_aligned_char __attribute__((aligned(2))); +extern unsigned char extern_explicitly_unaligned_char __attribute__((aligned(1))); +extern unsigned char __attribute__((weak)) extern_weak_char; +extern unsigned char extern_explicitly_aligned_weak_char __attribute__((weak,aligned(2))); +extern unsigned char extern_explicitly_unaligned_weak_char __attribute__((weak,aligned(1))); -unsigned char +unsigned char normal_char; +unsigned char explici
[gcc r14-9462] OpenACC 2.7: front-end support for readonly modifier
https://gcc.gnu.org/g:ddf852dac2abaca317c10b8323f338123b0585c8 commit r14-9462-gddf852dac2abaca317c10b8323f338123b0585c8 Author: Chung-Lin Tang Date: Thu Mar 14 10:39:52 2024 + OpenACC 2.7: front-end support for readonly modifier This patch implements the front-end support for the 'readonly' modifier for the OpenACC 'copyin' clause and 'cache' directive. This currently only includes front-end parsing for C/C++/Fortran and setting of new bits OMP_CLAUSE_MAP_READONLY, OMP_CLAUSE__CACHE__READONLY. Further linking of these bits to points-to analysis and/or utilization of read-only memory in accelerator target are for later patches. gcc/c/ChangeLog: * c-parser.cc (c_parser_oacc_data_clause): Add parsing support for 'readonly' modifier, set OMP_CLAUSE_MAP_READONLY if readonly modifier found, update comments. (c_parser_oacc_cache): Add parsing support for 'readonly' modifier, set OMP_CLAUSE__CACHE__READONLY if readonly modifier found, update comments. gcc/cp/ChangeLog: * parser.cc (cp_parser_oacc_data_clause): Add parsing support for 'readonly' modifier, set OMP_CLAUSE_MAP_READONLY if readonly modifier found, update comments. (cp_parser_oacc_cache): Add parsing support for 'readonly' modifier, set OMP_CLAUSE__CACHE__READONLY if readonly modifier found, update comments. gcc/fortran/ChangeLog: * dump-parse-tree.cc (show_omp_namelist): Print "readonly," for OMP_LIST_MAP and OMP_LIST_CACHE if n->u.map.readonly is set. Adjust 'n->u.map_op' to 'n->u.map.op'. * gfortran.h (typedef struct gfc_omp_namelist): Adjust map_op as 'ENUM_BITFIELD (gfc_omp_map_op) op:8', add 'bool readonly' field, change to named struct field 'map'. * openmp.cc (gfc_match_omp_map_clause): Adjust 'n->u.map_op' to 'n->u.map.op'. (gfc_match_omp_clause_reduction): Likewise. (gfc_match_omp_clauses): Add readonly modifier parsing for OpenACC copyin clause, set 'n->u.map.op' and 'n->u.map.readonly' for parsed clause. Adjust 'n->u.map_op' to 'n->u.map.op'. (gfc_match_oacc_declare): Adjust 'n->u.map_op' to 'n->u.map.op'. (gfc_match_oacc_cache): Add readonly modifier parsing for OpenACC cache directive. (resolve_omp_clauses): Adjust 'n->u.map_op' to 'n->u.map.op'. * trans-decl.cc (add_clause): Adjust 'n->u.map_op' to 'n->u.map.op'. (finish_oacc_declare): Likewise. * trans-openmp.cc (gfc_trans_omp_clauses): Set OMP_CLAUSE_MAP_READONLY, OMP_CLAUSE__CACHE__READONLY to 1 when readonly is set. Adjust 'n->u.map_op' to 'n->u.map.op'. (gfc_add_clause_implicitly): Adjust 'n->u.map_op' to 'n->u.map.op'. gcc/ChangeLog: * tree.h (OMP_CLAUSE_MAP_READONLY): New macro. (OMP_CLAUSE__CACHE__READONLY): New macro. * tree-core.h (struct GTY(()) tree_base): Adjust comments for new uses of readonly_flag bit in OMP_CLAUSE_MAP_READONLY and OMP_CLAUSE__CACHE__READONLY. * tree-pretty-print.cc (dump_omp_clause): Add support for printing OMP_CLAUSE_MAP_READONLY and OMP_CLAUSE__CACHE__READONLY. gcc/testsuite/ChangeLog: * c-c++-common/goacc/readonly-1.c: New test. * gfortran.dg/goacc/readonly-1.f90: New test. Diff: --- gcc/c/c-parser.cc | 68 ++-- gcc/cp/parser.cc | 63 -- gcc/fortran/dump-parse-tree.cc | 5 +- gcc/fortran/gfortran.h | 6 +- gcc/fortran/openmp.cc | 87 - gcc/fortran/trans-decl.cc | 6 +- gcc/fortran/trans-openmp.cc| 47 -- gcc/testsuite/c-c++-common/goacc/readonly-1.c | 59 + gcc/testsuite/gfortran.dg/goacc/readonly-1.f90 | 89 ++ gcc/tree-core.h| 6 ++ gcc/tree-pretty-print.cc | 4 ++ gcc/tree.h | 8 +++ 12 files changed, 379 insertions(+), 69 deletions(-) diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 53e99aa29d9..00f8bf4376e 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -15627,7 +15627,11 @@ c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind, OpenACC 2.6: no_create ( variable-list ) attach ( variable-list ) - detach ( variable-list ) */ + detach ( variable-list ) + + OpenACC 2.7: + copyin (readonly : variable-list ) + */ static tree c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind, @
[gcc r14-9463] PR modula2/114333 set type comparison against a cardinal should cause an error
https://gcc.gnu.org/g:b7f70cfdb6f7ab369ecca14a99a0064d2a11ddd2 commit r14-9463-gb7f70cfdb6f7ab369ecca14a99a0064d2a11ddd2 Author: Gaius Mulley Date: Thu Mar 14 11:23:42 2024 + PR modula2/114333 set type comparison against a cardinal should cause an error The type checker M2Check.mod needs extending to detect if a set, array or record is in either operand at the end of the cascaded test list. gcc/m2/ChangeLog: PR modula2/114333 * gm2-compiler/M2Check.mod (checkUnbounded): New procedure function. (checkArrayTypeEquivalence): Extend checking to cover unbounded arrays, arrays and constants. (IsTyped): Simplified the expression and corrected a test for IsConstructor. (checkTypeKindViolation): New procedure function. (doCheckPair): Call checkTypeKindViolation. * gm2-compiler/M2GenGCC.mod (CodeStatement): Remove parameters to CodeEqu and CodeNotEqu. (PerformCodeIfEqu): New procedure. (CodeIfEqu): Rewrite. (PerformCodeIfNotEqu): New procedure. (CodeIfNotEqu): Rewrite. * gm2-compiler/M2Quads.mod (BuildRelOpFromBoolean): Correct comment. gcc/testsuite/ChangeLog: PR modula2/114333 * gm2/cse/pass/testcse54.mod: New test. * gm2/iso/run/pass/array9.mod: New test. * gm2/iso/run/pass/strcons3.mod: New test. * gm2/iso/run/pass/strcons4.mod: New test. * gm2/pim/fail/badset1.mod: New test. * gm2/pim/fail/badset2.mod: New test. * gm2/pim/fail/badset3.mod: New test. * gm2/pim/fail/badset4.mod: New test. Signed-off-by: Gaius Mulley Diff: --- gcc/m2/gm2-compiler/M2Check.mod | 111 +-- gcc/m2/gm2-compiler/M2GenGCC.mod| 212 ++-- gcc/m2/gm2-compiler/M2Quads.mod | 2 +- gcc/testsuite/gm2/cse/pass/testcse54.mod| 7 + gcc/testsuite/gm2/iso/run/pass/array9.mod | 28 gcc/testsuite/gm2/iso/run/pass/strcons3.mod | 30 gcc/testsuite/gm2/iso/run/pass/strcons4.mod | 36 + gcc/testsuite/gm2/pim/fail/badset1.mod | 13 ++ gcc/testsuite/gm2/pim/fail/badset2.mod | 13 ++ gcc/testsuite/gm2/pim/fail/badset3.mod | 11 ++ gcc/testsuite/gm2/pim/fail/badset4.mod | 11 ++ 11 files changed, 383 insertions(+), 91 deletions(-) diff --git a/gcc/m2/gm2-compiler/M2Check.mod b/gcc/m2/gm2-compiler/M2Check.mod index 5b45ad39c11..20d463d207b 100644 --- a/gcc/m2/gm2-compiler/M2Check.mod +++ b/gcc/m2/gm2-compiler/M2Check.mod @@ -46,7 +46,8 @@ FROM SymbolTable IMPORT NulSym, IsRecord, IsSet, GetDType, GetSType, IsType, GetDeclaredMod, IsSubrange, GetArraySubscript, IsConst, IsReallyPointer, IsPointer, IsParameter, ModeOfAddr, GetMode, GetType, IsUnbounded, IsComposite, IsConstructor, -IsParameter, IsConstString, IsConstLitInternal, IsConstLit ; +IsParameter, IsConstString, IsConstLitInternal, IsConstLit, +GetStringLength ; FROM M2GCCDeclare IMPORT GetTypeMin, GetTypeMax ; FROM M2System IMPORT Address ; @@ -258,7 +259,35 @@ END checkSubrange ; (* - checkArrayTypeEquivalence - + checkUnbounded - check to see if the unbounded is type compatible with right. +This is only allowed during parameter passing. +*) + +PROCEDURE checkUnbounded (result: status; tinfo: tInfo; unbounded, right: CARDINAL) : status ; +VAR + lLow, rLow, + lHigh, rHigh: CARDINAL ; +BEGIN + (* Firstly check to see if we have resolved this as false. *) + IF isFalse (result) + THEN + RETURN result + ELSE + Assert (IsUnbounded (unbounded)) ; + IF tinfo^.kind = parameter + THEN + (* --fixme-- we should check the unbounded data type against the type of right. *) + RETURN true + ELSE + (* Not allowed to use an unbounded symbol (type) in an expression or assignment. *) + RETURN false + END + END +END checkUnbounded ; + + +(* + checkArrayTypeEquivalence - check array and unbounded array type equivalence. *) PROCEDURE checkArrayTypeEquivalence (result: status; tinfo: tInfo; @@ -273,7 +302,7 @@ BEGIN THEN lSub := GetArraySubscript (left) ; rSub := GetArraySubscript (right) ; - result := checkPair (result, tinfo, GetType (left), GetType (right)) ; + result := checkPair (result, tinfo, GetSType (left), GetSType (right)) ; IF (lSub # NulSym) AND (rSub # NulSym) THEN result := checkSubrange (result, tinfo, getSType (lSub), getSType (rSub)) @@ -284,8 +313,22 @@ BEGIN THEN RETURN true ELSE - result := checkPair (result, tinfo, GetType (left), GetType (right)) + re
[gcc r14-9464] libcpp: Fix __has_include_next ICE in the last directory of the path [PR80755]
https://gcc.gnu.org/g:6c166e55b15894ceb07dcc7b55f900e50e24ec5b commit r14-9464-g6c166e55b15894ceb07dcc7b55f900e50e24ec5b Author: Lewis Hyatt Date: Wed Dec 20 16:27:42 2023 -0500 libcpp: Fix __has_include_next ICE in the last directory of the path [PR80755] In libcpp/files.cc, the function _cpp_has_header(), which implements __has_include and __has_include_next, does not check for a NULL return value from search_path_head(), leading to an ICE tripping an assert when _cpp_find_file() tries to use it. Fix it by checking for that case and silently returning false instead. As suggested by the PR author, it is easiest to make a testcase by using the -idirafter option. To enable that, also modify the dg-additional-options testsuite procedure to make the global $srcdir available, since -idirafter requires the full path. libcpp/ChangeLog: PR preprocessor/80755 * files.cc (search_path_head): Add SUPPRESS_DIAGNOSTIC argument defaulting to false. (_cpp_has_header): Silently return false if the search path has been exhausted, rather than issuing a diagnostic and then hitting an assert. gcc/testsuite/ChangeLog: * lib/gcc-defs.exp (dg-additional-options): Make $srcdir usable in a dg-additional-options directive. * c-c++-common/cpp/has-include-next-2-dir/has-include-next-2.h: New test. * c-c++-common/cpp/has-include-next-2.c: New test. Diff: --- .../cpp/has-include-next-2-dir/has-include-next-2.h | 3 +++ gcc/testsuite/c-c++-common/cpp/has-include-next-2.c | 4 gcc/testsuite/lib/gcc-defs.exp | 1 + libcpp/files.cc | 12 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/gcc/testsuite/c-c++-common/cpp/has-include-next-2-dir/has-include-next-2.h b/gcc/testsuite/c-c++-common/cpp/has-include-next-2-dir/has-include-next-2.h new file mode 100644 index 000..1e4be6ce7a3 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/has-include-next-2-dir/has-include-next-2.h @@ -0,0 +1,3 @@ +#if __has_include_next() +/* This formerly led to an ICE when the current directory was the last one in the path. */ +#endif diff --git a/gcc/testsuite/c-c++-common/cpp/has-include-next-2.c b/gcc/testsuite/c-c++-common/cpp/has-include-next-2.c new file mode 100644 index 000..4928d3e992c --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/has-include-next-2.c @@ -0,0 +1,4 @@ +/* PR preprocessor/80755 */ +/* { dg-do preprocess } */ +/* { dg-additional-options "-idirafter $srcdir/c-c++-common/cpp/has-include-next-2-dir" } */ +#include diff --git a/gcc/testsuite/lib/gcc-defs.exp b/gcc/testsuite/lib/gcc-defs.exp index 56851f4a082..70215ed4905 100644 --- a/gcc/testsuite/lib/gcc-defs.exp +++ b/gcc/testsuite/lib/gcc-defs.exp @@ -280,6 +280,7 @@ if { [info exists env(GCC_RUNTEST_PARALLELIZE_DIR)] \ proc dg-additional-options { args } { upvar dg-extra-tool-flags extra-tool-flags +global srcdir if { [llength $args] > 3 } { error "[lindex $args 0]: too many arguments" diff --git a/libcpp/files.cc b/libcpp/files.cc index e66eef46534..c61df339e20 100644 --- a/libcpp/files.cc +++ b/libcpp/files.cc @@ -181,7 +181,8 @@ static bool read_file_guts (cpp_reader *pfile, _cpp_file *file, static bool read_file (cpp_reader *pfile, _cpp_file *file, location_t loc); static struct cpp_dir *search_path_head (cpp_reader *, const char *fname, -int angle_brackets, enum include_type); +int angle_brackets, enum include_type, +bool suppress_diagnostic = false); static const char *dir_name_of_file (_cpp_file *file); static void open_file_failed (cpp_reader *pfile, _cpp_file *file, int, location_t); @@ -1041,7 +1042,7 @@ _cpp_mark_file_once_only (cpp_reader *pfile, _cpp_file *file) nothing left in the path, returns NULL. */ static struct cpp_dir * search_path_head (cpp_reader *pfile, const char *fname, int angle_brackets, - enum include_type type) + enum include_type type, bool suppress_diagnostic) { cpp_dir *dir; _cpp_file *file; @@ -1070,7 +1071,7 @@ search_path_head (cpp_reader *pfile, const char *fname, int angle_brackets, return make_cpp_dir (pfile, dir_name_of_file (file), pfile->buffer ? pfile->buffer->sysp : 0); - if (dir == NULL) + if (dir == NULL && !suppress_diagnostic) cpp_error (pfile, CPP_DL_ERROR, "no include path in which to search for %s", fname); @@ -2164,7 +2165,10 @@ bool _cpp_has_header (cpp_reader *pfile, const char *fname, int angle_brackets, enum include_type type) { - cpp_dir *start_dir = search_path_h
[gcc r14-9465] libcpp: Fix macro expansion for argument of __has_include [PR110558]
https://gcc.gnu.org/g:942497ad74272e0ef16020d628e471c5f21474b0 commit r14-9465-g942497ad74272e0ef16020d628e471c5f21474b0 Author: Lewis Hyatt Date: Tue Dec 12 17:46:36 2023 -0500 libcpp: Fix macro expansion for argument of __has_include [PR110558] When the file name for a #include directive is the result of stringifying a macro argument, libcpp needs to take some care to get the whitespace correct; in particular stringify_arg() needs to see a CPP_PADDING token between macro tokens so that it can figure out when to output space between tokens. The CPP_PADDING tokens are not normally generated when handling a preprocessor directive, but for #include-like directives, libcpp sets the state variable pfile->state.directive_wants_padding to TRUE so that the CPP_PADDING tokens will be output, and then everything works fine for computed includes. As the PR points out, things do not work fine for __has_include. Fix that by setting the state variable the same as is done for #include. libcpp/ChangeLog: PR preprocessor/110558 * macro.cc (builtin_has_include): Set pfile->state.directive_wants_padding prior to lexing the file name, in case it comes from macro expansion. gcc/testsuite/ChangeLog: PR preprocessor/110558 * c-c++-common/cpp/has-include-2.c: New test. * c-c++-common/cpp/has-include-2.h: New test. Diff: --- gcc/testsuite/c-c++-common/cpp/has-include-2.c | 12 gcc/testsuite/c-c++-common/cpp/has-include-2.h | 1 + libcpp/macro.cc| 3 +++ 3 files changed, 16 insertions(+) diff --git a/gcc/testsuite/c-c++-common/cpp/has-include-2.c b/gcc/testsuite/c-c++-common/cpp/has-include-2.c new file mode 100644 index 000..5cd00cb3fb5 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/has-include-2.c @@ -0,0 +1,12 @@ +/* PR preprocessor/110558 */ +/* { dg-do preprocess } */ +#define STRINGIZE(x) #x +#define GET_INCLUDE(i) STRINGIZE(has-include-i.h) +/* Spaces surrounding the macro args previously caused a problem for __has_include(). */ +#if __has_include(GET_INCLUDE(2)) && __has_include(GET_INCLUDE( 2)) && __has_include(GET_INCLUDE( 2 )) +#include GET_INCLUDE(2) +#include GET_INCLUDE( 2) +#include GET_INCLUDE( 2 ) +#else +#error "__has_include did not handle padding properly" /* { dg-bogus "__has_include" } */ +#endif diff --git a/gcc/testsuite/c-c++-common/cpp/has-include-2.h b/gcc/testsuite/c-c++-common/cpp/has-include-2.h new file mode 100644 index 000..57c402b32a8 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/has-include-2.h @@ -0,0 +1 @@ +/* PR preprocessor/110558 */ diff --git a/libcpp/macro.cc b/libcpp/macro.cc index a3d2c159f8c..352eb2e4fd9 100644 --- a/libcpp/macro.cc +++ b/libcpp/macro.cc @@ -398,6 +398,8 @@ builtin_has_include (cpp_reader *pfile, cpp_hashnode *op, bool has_next) NODE_NAME (op)); pfile->state.angled_headers = true; + const auto sav_padding = pfile->state.directive_wants_padding; + pfile->state.directive_wants_padding = true; const cpp_token *token = cpp_get_token_no_padding (pfile); bool paren = token->type == CPP_OPEN_PAREN; if (paren) @@ -406,6 +408,7 @@ builtin_has_include (cpp_reader *pfile, cpp_hashnode *op, bool has_next) cpp_error (pfile, CPP_DL_ERROR, "missing '(' before \"%s\" operand", NODE_NAME (op)); pfile->state.angled_headers = false; + pfile->state.directive_wants_padding = sav_padding; bool bracket = token->type != CPP_STRING; char *fname = NULL;
[gcc r14-9466] libstdc++: Update C++23 status in the manual
https://gcc.gnu.org/g:2a556dbec2e522655175374c68d61a39b1463c7e commit r14-9466-g2a556dbec2e522655175374c68d61a39b1463c7e Author: Jonathan Wakely Date: Thu Mar 14 11:47:56 2024 + libstdc++: Update C++23 status in the manual libstdc++-v3/ChangeLog: * doc/xml/manual/status_cxx2023.xml: Update C++23 status table. * doc/html/manual/status.html: Regenerate. * include/bits/version.def: Fix typo in comment. Diff: --- libstdc++-v3/doc/html/manual/status.html | 146 ++--- libstdc++-v3/doc/xml/manual/status_cxx2023.xml | 289 ++--- libstdc++-v3/include/bits/version.def | 2 +- 3 files changed, 373 insertions(+), 64 deletions(-) diff --git a/libstdc++-v3/doc/html/manual/status.html b/libstdc++-v3/doc/html/manual/status.html index dafd48035a6..ea8fd485cb9 100644 --- a/libstdc++-v3/doc/html/manual/status.html +++ b/libstdc++-v3/doc/html/manual/status.html @@ -1832,11 +1832,20 @@ or any notes about the implementation. https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2278r4.html"; target="_top"> P2278R4 - 13.1 __cpp_lib_ranges_as_const >= 202207L ranges::to + 13.1 __cpp_lib_ranges_as_const >= 202207L ranges::to https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1206r7.pdf"; target="_top"> P1206R7 -__cpp_lib_ranges_to_container >= 202202L Pipe support for user-defined range adaptors + 14.1 (ranges::to function) + __cpp_lib_containers_ranges >= 202202L, + __cpp_lib_ranges_to_container >= 202202L + Ranges iterators as inputs to non-Ranges algorithms +https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2408r5.html"; target="_top"> +P2408R5 + + + __cpp_lib_algorithm_iterator_requirements >= 202207L + Pipe support for user-defined range adaptors https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2387r3.html"; target="_top"> P2387R3 @@ -1861,11 +1870,19 @@ or any notes about the implementation. https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2302r4.html"; target="_top"> P2302R4 - 13.1 __cpp_lib_ranges_contains >= 202207L ranges::fold + 13.1 __cpp_lib_ranges_contains >= 202207L Making multi-param constructors of views explicit +https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2711r1.html"; target="_top"> +P2711R1 + + ranges::fold https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2322r6.html"; target="_top"> P2322R6 - 13.1 __cpp_lib_ranges_fold >= 202207L + 13.1 __cpp_lib_ranges_fold >= 202207L Relaxing Ranges Just A Smidge +https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2609r3.html"; target="_top"> +P2609R3 + +__cpp_lib_ranges >= 202302L Compile-time programming A proposal for a type trait to detect scoped enumerations https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1048r1.pdf"; target="_top"> @@ -1899,29 +1916,35 @@ or any notes about the implementation. https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1413r3.pdf"; target="_top"> P1413R3 - A type trait to detect reference binding to temporary + A type trait to detect reference binding to temporary https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2255r2.html"; target="_top"> P2255R2 - 13.1 (missing changes to std::tuple __cpp_lib_reference_from_temporary >= 202202L -Strings and text - string contains function -https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1679r3.html"; target="_top"> -P1679R3 + +13.1 (missing changes to std::tuple) 14.1 (complete) + __cpp_lib_reference_from_temporary >= 202202L +Move-only types for equality_comparable_with, totally_ordered_with, + and three_way_comparable_with + +https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2404r3.pdf"; target="_top"> +P2404R3 - 11.1 __cpp_lib_string_contains >= 202011L Prohibit std::basic_string and std::basic_string_view construction from nullptr -https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2166r1.html"; target="_top"> -P2166R1 +__cpp_lib_concepts >= 202207L A trait for implicit lifetime types +https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2674r1.pdf"; target="_top"> +P2674R1 - 12.1 basic_string::resize_and_overwrite -https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1072r10.html"; target="_top"> -P1072R10 +__cpp_lib_is_implicit_lifetime >= 202302L + common_reference_t of reference_wrapper + S
[gcc r14-9467] libstdc++: Correct notes about std::call_once in manual [PR66146]
https://gcc.gnu.org/g:e6836bbbd7a01af0791c02087e568b4822418c0d commit r14-9467-ge6836bbbd7a01af0791c02087e568b4822418c0d Author: Jonathan Wakely Date: Thu Mar 14 11:52:17 2024 + libstdc++: Correct notes about std::call_once in manual [PR66146] The bug with exceptions thrown during a std::call_once call affects all targets, so fix the docs that say it only affects non-Linux targets. libstdc++-v3/ChangeLog: PR libstdc++/66146 * doc/xml/manual/status_cxx2011.xml: Remove mention of Linux in note about std::call_once. * doc/xml/manual/status_cxx2014.xml: Likewise. * doc/xml/manual/status_cxx2017.xml: Likewise. * doc/html/manual/status.html: Regenerate. Diff: --- libstdc++-v3/doc/html/manual/status.html | 6 +++--- libstdc++-v3/doc/xml/manual/status_cxx2011.xml | 2 +- libstdc++-v3/doc/xml/manual/status_cxx2014.xml | 2 +- libstdc++-v3/doc/xml/manual/status_cxx2017.xml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/doc/html/manual/status.html b/libstdc++-v3/doc/html/manual/status.html index ea8fd485cb9..2e293d32f81 100644 --- a/libstdc++-v3/doc/html/manual/status.html +++ b/libstdc++-v3/doc/html/manual/status.html @@ -217,7 +217,7 @@ particular release. 30 Thread support - 30.1GeneralY 30.2RequirementsY 30.3Threads 30.3.1Class threadPartialthread::id comparisons not well-defined30.3.2Namespace this_threadY 30.4Mutual exclusion 30.4.1Mutex requirements 30.4.1.1In general 30.4.1.2Mutex types 30.4.1.2.1Class mutexY 30.4.1.2.2Class recursive_mutexY 30.4.1.3Timed mutex types 30.4.1.3.1Class timed_mutexY 30.4.1.3.2Class recursive_timed_mutexY 30. 4.2Locks 30.4.2.1Class template lock_guardY 30.4.2.2Class template unique_lockY 30.4.3Generic locking algorithmsY 30.4.4Call once 30.4.4.1Struct once_flagY 30.4.4.2Function call_onceYException support is broken on non -Linux targets. + 30.1GeneralY 30.2RequirementsY 30.3Threads 30.3.1Class threadPartialthread::id comparisons not well-defined30.3.2Namespace this_threadY 30.4Mutual exclusion 30.4.1Mutex requirements 30.4.1.1In general 30.4.1.2Mutex types 30.4.1.2.1Class mutexY 30.4.1.2.2Class recursive_mutexY 30.4.1.3Timed mutex types 30.4.1.3.1Class timed_mutexY 30.4.1.3.2Class recursive_timed_mutexY 30. 4.2Locks 30.4.2.1Class template lock_guardY 30.4.2.2Class template unique_lockY 30.4.3Generic locking algorithmsY 30.4.4Call once 30.4.4.1Struct once_flagY 30.4.4.2Function call_onceYException support is broken. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66146"; target="_top">PR 66146. 30.5Condition variablesY 30.5.1Class condition_variableY 30.5.2Class condition_variable_anyY 30.6Futures 30.6.1Overview 30.6.2Error handlingY 30.6.3Class future_errorY 30.6.4Shared stateY 30.6.5Class template promiseY 30.6.6Class template futureY 30.6.7Class template shared_futureY 30.6.8Function template asyncY 30.6.9Class template packaged_taskY @@ -490,7 +490,7 @@ not in any particular release. 30 Thread support - 30.1GeneralY 30.2RequirementsY 30.3Threads 30.3.1Class threadPartialthread::id comparisons not well-defined30.3.2Namespace this_threadY 30.4Mutual exclusion 30.4.1Mutex requirements 30.4.1.1In general 30.4.1.2Mutex types 30.4.1.2.1Class mutexY 30.4.1.2.2Class recursive_mutexY 30.4.1.3Timed mutex types 30.4.1.3.1Class timed_mutexY 30.4.1.3.2Class recursive_timed_mutexY 30. 4.1.4Shared timed mutex types 30.4.1.4.1Class shared_timed_mutexY 30.4.2Locks 30.4.2.1Class template lock_guardY 30.4.2.2Class template unique_lockY 30.4.2.3Class template shared_lockY 30.4.3Generic locking algorithmsY < td align="left">30.4.4Call once 30.4.4.1Struct once_flagY 30.4.4.2Function call_onceBrokenException support is broken on non-Linux targets. + 30.1GeneralY 30.2RequirementsY 30.3Threads 30.3.1Class threadPartialthread::id comparisons not well-defined30.3.2Namespace this_threadY 30.4Mutual exclusion 30.4.1Mutex requirements 30.4.1.1In general 30.4.1.2Mutex types 30.4.1.2.1Class mutexY 30.4.1.2.2Class recursive_mutexY 30.4.1.3Timed mutex types 30.4.1.3.1Class timed_mutexY 30.4.1.3.2Class recursive_timed_mutexY 30. 4.1.4Shared timed mutex types 30.4.1.4.1Class shared_timed_mutexY 30.4.2Locks 30.4.2.1Class template lock_guardY 30.4.2.2Class template unique_lockY 30.4.2.3Class template shared_lockY 30.4.3Generic locking algorithmsY < td align="left">30.4.4Call once 30.4.4.1Struct once_flagY 30.4.4.2Function call_onceBrokenException support is broken. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66146"; target="_top">PR 66146. 30.5Condition variablesY 30.5.1Class condition_variableY 30.5.2Class condition_variable_anyY 30.6Futures 30.6.1Overview 30.6.2Error handlingY 30.6.3Class future_errorY 30.6.4Shared stateY 30.6.5Class
[gcc r14-9468] s390: fix htm-builtins test cases
https://gcc.gnu.org/g:075104eef6d0ff215c394b6eaadcb525fa7c4975 commit r14-9468-g075104eef6d0ff215c394b6eaadcb525fa7c4975 Author: Juergen Christ Date: Wed Oct 25 14:57:03 2023 +0200 s390: fix htm-builtins test cases Transactional and non-transactional stores to the same cache line cause transactions to abort on newer generations. Add sufficient padding to make sure another cache line is used. Tested on s390. gcc/testsuite/ChangeLog: * gcc.target/s390/htm-builtins-1.c: Fix. * gcc.target/s390/htm-builtins-2.c: Fix. Signed-off-by: Juergen Christ Diff: --- gcc/testsuite/gcc.target/s390/htm-builtins-1.c | 4 +++- gcc/testsuite/gcc.target/s390/htm-builtins-2.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.target/s390/htm-builtins-1.c b/gcc/testsuite/gcc.target/s390/htm-builtins-1.c index ff43be9fe73..4f95bf3acca 100644 --- a/gcc/testsuite/gcc.target/s390/htm-builtins-1.c +++ b/gcc/testsuite/gcc.target/s390/htm-builtins-1.c @@ -53,9 +53,11 @@ __attribute__ ((aligned(256))) struct __attribute__ ((aligned(256))) struct { volatile uint64_t c1; + char pad1[256 - sizeof(uint64_t)]; volatile uint64_t c2; + char pad2[256 - sizeof(uint64_t)]; volatile uint64_t c3; -} counters = { 0, 0, 0 }; +} counters = { 0 }; /* local helper functions - */ diff --git a/gcc/testsuite/gcc.target/s390/htm-builtins-2.c b/gcc/testsuite/gcc.target/s390/htm-builtins-2.c index bb9d346ea56..2e838caacc8 100644 --- a/gcc/testsuite/gcc.target/s390/htm-builtins-2.c +++ b/gcc/testsuite/gcc.target/s390/htm-builtins-2.c @@ -94,9 +94,11 @@ float global_float_3 = 0.0; __attribute__ ((aligned(256))) struct { volatile uint64_t c1; + char pad1[256 - sizeof(uint64_t)]; volatile uint64_t c2; + char pad2[256 - sizeof(uint64_t)]; volatile uint64_t c3; -} counters = { 0, 0, 0 }; +} counters = { 0 }; /* local helper functions - */
[gcc r14-9469] aarch64: Fix TImode __sync_*_compare_and_exchange expansion with LSE [PR114310]
https://gcc.gnu.org/g:9349aefa1df7ae36714b7b9f426ad46e314892d1 commit r14-9469-g9349aefa1df7ae36714b7b9f426ad46e314892d1 Author: Jakub Jelinek Date: Thu Mar 14 14:09:20 2024 +0100 aarch64: Fix TImode __sync_*_compare_and_exchange expansion with LSE [PR114310] The following testcase ICEs with LSE atomics. The problem is that the @atomic_compare_and_swap expander uses aarch64_reg_or_zero predicate for the desired operand, which is fine, given that for most of the modes and even for TImode in some cases it can handle zero immediate just fine, but the TImode @aarch64_compare_and_swap_lse just uses register_operand for that operand instead, again intentionally so, because the casp, caspa, caspl and caspal instructions need to use a pair of consecutive registers for the operand and xzr is just one register and we can't just store zero into the link register to emulate pair of zeros. So, the following patch fixes that by forcing the newval operand into a register for the TImode LSE case. 2024-03-14 Jakub Jelinek PR target/114310 * config/aarch64/aarch64.cc (aarch64_expand_compare_and_swap): For TImode force newval into a register. * gcc.dg/pr114310.c: New test. Diff: --- gcc/config/aarch64/aarch64.cc | 2 ++ gcc/testsuite/gcc.dg/pr114310.c | 20 2 files changed, 22 insertions(+) diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index ae040781c43..1ea84c8bd73 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -24693,6 +24693,8 @@ aarch64_expand_compare_and_swap (rtx operands[]) rval = copy_to_mode_reg (r_mode, oldval); else emit_move_insn (rval, gen_lowpart (r_mode, oldval)); + if (mode == TImode) + newval = force_reg (mode, newval); emit_insn (gen_aarch64_compare_and_swap_lse (mode, rval, mem, newval, mod_s)); diff --git a/gcc/testsuite/gcc.dg/pr114310.c b/gcc/testsuite/gcc.dg/pr114310.c new file mode 100644 index 000..55edd800e42 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr114310.c @@ -0,0 +1,20 @@ +/* PR target/114310 */ +/* { dg-do run { target int128 } } */ + +volatile __attribute__((aligned (sizeof (__int128_t __int128_t v = 10; + +int +main () +{ +#if __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 + if (__sync_val_compare_and_swap (&v, (__int128_t) 10, (__int128_t) 0) != 10) +__builtin_abort (); + if (__sync_val_compare_and_swap (&v, (__int128_t) 10, (__int128_t) 15) != 0) +__builtin_abort (); + if (__sync_val_compare_and_swap (&v, (__int128_t) 0, (__int128_t) 42) != 0) +__builtin_abort (); + if (__sync_val_compare_and_swap (&v, (__int128_t) 31, (__int128_t) 35) != 42) +__builtin_abort (); +#endif + return 0; +}
[gcc r14-9470] Fix 'char' initialization, copy, check in 'libgomp.oacc-fortran/acc-memcpy.f90'
https://gcc.gnu.org/g:25242ed8eb93613af6f296785da2d4ece816b7d6 commit r14-9470-g25242ed8eb93613af6f296785da2d4ece816b7d6 Author: Thomas Schwinge Date: Wed Mar 6 23:18:08 2024 +0100 Fix 'char' initialization, copy, check in 'libgomp.oacc-fortran/acc-memcpy.f90' Our dear friend '-Wuninitialized' reported: [...]/libgomp.oacc-fortran/acc-memcpy.f90:18:27: 18 | char(j) = int (j, int8) | ^ Warning: ‘j’ may be used uninitialized [-Wmaybe-uninitialized] [...]/libgomp.oacc-fortran/acc-memcpy.f90:14:20: 14 | integer(int8) :: j |^ note: ‘j’ was declared here ..., but actually there were other issues. libgomp/ * testsuite/libgomp.oacc-fortran/acc-memcpy.f90: Fix 'char' initialization, copy, check. Diff: --- libgomp/testsuite/libgomp.oacc-fortran/acc-memcpy.f90 | 8 +++- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libgomp/testsuite/libgomp.oacc-fortran/acc-memcpy.f90 b/libgomp/testsuite/libgomp.oacc-fortran/acc-memcpy.f90 index 670dc50ff07..844d08a4661 100644 --- a/libgomp/testsuite/libgomp.oacc-fortran/acc-memcpy.f90 +++ b/libgomp/testsuite/libgomp.oacc-fortran/acc-memcpy.f90 @@ -11,15 +11,14 @@ program main integer(int8), allocatable :: char(:) type(c_ptr) :: dptr integer(c_intptr_t) :: i - integer(int8) :: j allocate(char(-128:127)) do i = -128, 127 -char(j) = int (j, int8) +char(i) = int (i, int8) end do dptr = acc_malloc (256_c_size_t) - call acc_memcpy_to_device (dptr, char, 255_c_size_t) + call acc_memcpy_to_device (dptr, char, 256_c_size_t) do i = 0, 255 if (acc_is_present (transfer (transfer(char, i) + i, dptr), 1)) & @@ -31,8 +30,7 @@ program main call acc_memcpy_from_device (char, dptr, 256_c_size_t) do i = -128, 127 -char(i) = int (j, int8) -if (char(i) /= j) & +if (char(i) /= i) & stop 2 end do
[gcc r14-9471] Minor fixes for OpenACC/Fortran 'self' clause for compute constructs
https://gcc.gnu.org/g:473c6123ffad38dddef7b126bf97971784d94b40 commit r14-9471-g473c6123ffad38dddef7b126bf97971784d94b40 Author: Thomas Schwinge Date: Fri Oct 20 15:49:35 2023 +0200 Minor fixes for OpenACC/Fortran 'self' clause for compute constructs ... to fix up recent commit 3a3596389c2e539cb8fd5dc5784a4e2afe193a2a "OpenACC 2.7: Implement self clause for compute constructs". gcc/fortran/ * dump-parse-tree.cc (show_omp_clauses): Handle 'self_expr'. * openmp.cc (gfc_free_omp_clauses): Likewise. * trans-openmp.cc (gfc_split_omp_clauses): Don't handle 'self_expr'. Diff: --- gcc/fortran/dump-parse-tree.cc | 6 ++ gcc/fortran/openmp.cc | 1 + gcc/fortran/trans-openmp.cc| 2 -- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/dump-parse-tree.cc b/gcc/fortran/dump-parse-tree.cc index db84b06289b..7bc78663768 100644 --- a/gcc/fortran/dump-parse-tree.cc +++ b/gcc/fortran/dump-parse-tree.cc @@ -1619,6 +1619,12 @@ show_omp_clauses (gfc_omp_clauses *omp_clauses) show_expr (omp_clauses->if_exprs[i]); fputc (')', dumpfile); } + if (omp_clauses->self_expr) +{ + fputs (" SELF(", dumpfile); + show_expr (omp_clauses->self_expr); + fputc (')', dumpfile); +} if (omp_clauses->final_expr) { fputs (" FINAL(", dumpfile); diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index 5c44e666eb9..315ec68f259 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -164,6 +164,7 @@ gfc_free_omp_clauses (gfc_omp_clauses *c) gfc_free_expr (c->if_expr); for (i = 0; i < OMP_IF_LAST; i++) gfc_free_expr (c->if_exprs[i]); + gfc_free_expr (c->self_expr); gfc_free_expr (c->final_expr); gfc_free_expr (c->num_threads); gfc_free_expr (c->chunk_size); diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index 7a088ec5b2d..f867e2240bf 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -6840,8 +6840,6 @@ gfc_split_omp_clauses (gfc_code *code, /* And this is copied to all. */ clausesa[GFC_OMP_SPLIT_TARGET].if_expr = code->ext.omp_clauses->if_expr; - clausesa[GFC_OMP_SPLIT_TARGET].self_expr - = code->ext.omp_clauses->self_expr; clausesa[GFC_OMP_SPLIT_TARGET].nowait = code->ext.omp_clauses->nowait; }
[gcc r14-9472] OpenACC 2.7: front-end support for readonly modifier: Add basic OpenACC 'declare' testing
https://gcc.gnu.org/g:38958ac987dc3e6162e2ddaba3c7e7f41381e079 commit r14-9472-g38958ac987dc3e6162e2ddaba3c7e7f41381e079 Author: Thomas Schwinge Date: Thu Mar 14 15:01:01 2024 +0100 OpenACC 2.7: front-end support for readonly modifier: Add basic OpenACC 'declare' testing ... to complement commit ddf852dac2abaca317c10b8323f338123b0585c8 "OpenACC 2.7: front-end support for readonly modifier". gcc/testsuite/ * c-c++-common/goacc/readonly-1.c: Add basic OpenACC 'declare' testing. * gfortran.dg/goacc/readonly-1.f90: Likewise. Diff: --- gcc/testsuite/c-c++-common/goacc/readonly-1.c | 5 + gcc/testsuite/gfortran.dg/goacc/readonly-1.f90 | 6 ++ 2 files changed, 11 insertions(+) diff --git a/gcc/testsuite/c-c++-common/goacc/readonly-1.c b/gcc/testsuite/c-c++-common/goacc/readonly-1.c index 34fc92c24d5..300464c92e3 100644 --- a/gcc/testsuite/c-c++-common/goacc/readonly-1.c +++ b/gcc/testsuite/c-c++-common/goacc/readonly-1.c @@ -8,12 +8,15 @@ struct S int a[32], b[32]; #pragma acc declare copyin(readonly: a) copyin(b) +/* Not visible in 'original' dump; handled via 'offload_vars'. */ int main (void) { int x[32], y[32]; struct S s = {x, 0}; + #pragma acc declare copyin(readonly: x/*[:32]*/, s/*.ptr[:16]*/) copyin(y/*[:32]*/) + #pragma acc parallel copyin(readonly: x[:32], s.ptr[:16]) copyin(y[:32]) { #pragma acc cache (readonly: x[:32]) @@ -43,6 +46,8 @@ int main (void) return 0; } +/* { dg-final { scan-tree-dump-times "(?n)#pragma acc declare map\\(to:y\\) map\\(readonly,to:s\\) map\\(readonly,to:x\\)" 1 "original" } } */ + /* { dg-final { scan-tree-dump-times "(?n)#pragma acc parallel map\\(to:y\\\[0\\\] \\\[len: \[0-9\]+\\\]\\) .+ map\\(readonly,to:\\*s.ptr \\\[len: \[0-9\]+\\\]\\) .+ map\\(readonly,to:x\\\[0\\\] \\\[len: \[0-9\]+\\\]\\)" 1 "original" { target { c } } } } */ /* { dg-final { scan-tree-dump-times "(?n)#pragma acc kernels map\\(to:y\\\[0\\\] \\\[len: \[0-9\]+\\\]\\) .+ map\\(readonly,to:\\*s.ptr \\\[len: \[0-9\]+\\\]\\) .+ map\\(readonly,to:x\\\[0\\\] \\\[len: \[0-9\]+\\\]\\)" 1 "original" { target { c } } } } */ /* { dg-final { scan-tree-dump-times "(?n)#pragma acc serial map\\(to:y\\\[0\\\] \\\[len: \[0-9\]+\\\]\\) .+ map\\(readonly,to:\\*s.ptr \\\[len: \[0-9\]+\\\]\\) .+ map\\(readonly,to:x\\\[0\\\] \\\[len: \[0-9\]+\\\]\\)" 1 "original" { target { c } } } } */ diff --git a/gcc/testsuite/gfortran.dg/goacc/readonly-1.f90 b/gcc/testsuite/gfortran.dg/goacc/readonly-1.f90 index 696ebd08321..fc1e2719e67 100644 --- a/gcc/testsuite/gfortran.dg/goacc/readonly-1.f90 +++ b/gcc/testsuite/gfortran.dg/goacc/readonly-1.f90 @@ -3,6 +3,9 @@ subroutine foo (a, n) integer :: n, a(:) integer :: i, b(n), c(n) + !!$acc declare copyin(readonly: a(:), b(:n)) copyin(c(:)) + !$acc declare copyin(readonly: b) copyin(c) + !$acc parallel copyin(readonly: a(:), b(:n)) copyin(c(:)) do i = 1,32 !$acc cache (readonly: a(:), b(:n)) @@ -74,6 +77,9 @@ program main end program main +! The front end turns OpenACC 'declare' into OpenACC 'data'. +! { dg-final { scan-tree-dump-times "(?n)#pragma acc data map\\(readonly,to:\\*b\\) map\\(alloc:b.+ map\\(to:\\*c\\) map\\(alloc:c.+" 1 "original" } } +! { dg-final { scan-tree-dump-times "(?n)#pragma acc data map\\(readonly,to:g\\) map\\(to:h\\)" 1 "original" } } ! { dg-final { scan-tree-dump-times "(?n)#pragma acc parallel map\\(readonly,to:\\*.+ map\\(alloc:a.+ map\\(readonly,to:\\*.+ map\\(alloc:b.+ map\\(to:\\*.+ map\\(alloc:c.+" 1 "original" } } ! { dg-final { scan-tree-dump-times "(?n)#pragma acc parallel map\\(readonly,to:a.+ map\\(alloc:a.+ map\\(readonly,to:b.+ map\\(alloc:b.+ map\\(to:c.+ map\\(alloc:c.+" 1 "original" } } ! { dg-final { scan-tree-dump-times "(?n)#pragma acc kernels map\\(readonly,to:\\*.+ map\\(alloc:a.+ map\\(readonly,to:\\*.+ map\\(alloc:b.+ map\\(to:\\*.+ map\\(alloc:c.+" 1 "original" } }
[gcc r14-9473] libstdc++: Add missing clear_padding in __atomic_float constructor
https://gcc.gnu.org/g:0adc8c5f146b108f99c4df09e43276e3a2419262 commit r14-9473-g0adc8c5f146b108f99c4df09e43276e3a2419262 Author: xndcn Date: Fri Feb 16 11:00:13 2024 + libstdc++: Add missing clear_padding in __atomic_float constructor For 80-bit long double we need to clear the padding bits on construction. libstdc++-v3/ChangeLog: * include/bits/atomic_base.h (__atomic_float::__atomic_float(Fp)): Clear padding. * testsuite/29_atomics/atomic_float/compare_exchange_padding.cc: New test. Signed-off-by: xndcn Reviewed-by: Jonathan Wakely Diff: --- libstdc++-v3/include/bits/atomic_base.h| 2 +- .../atomic_float/compare_exchange_padding.cc | 53 ++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h index b857b441169..dd360302f80 100644 --- a/libstdc++-v3/include/bits/atomic_base.h +++ b/libstdc++-v3/include/bits/atomic_base.h @@ -1283,7 +1283,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr __atomic_float(_Fp __t) : _M_fp(__t) - { } + { __atomic_impl::__clear_padding(_M_fp); } __atomic_float(const __atomic_float&) = delete; __atomic_float& operator=(const __atomic_float&) = delete; diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_float/compare_exchange_padding.cc b/libstdc++-v3/testsuite/29_atomics/atomic_float/compare_exchange_padding.cc new file mode 100644 index 000..49626ac6651 --- /dev/null +++ b/libstdc++-v3/testsuite/29_atomics/atomic_float/compare_exchange_padding.cc @@ -0,0 +1,53 @@ +// { dg-do run { target c++20 } } +// { dg-options "-O0" } +// { dg-additional-options "[atomic_link_flags [get_multilibs]] -latomic" } + +#include +#include +#include +#include + +template +void __attribute__((noinline,noipa)) +fill_padding(T& f) +{ + T mask; + std::memset(&mask, 0xff, sizeof(T)); + __builtin_clear_padding(&mask); + unsigned char* ptr_f = (unsigned char*)&f; + unsigned char* ptr_mask = (unsigned char*)&mask; + for (unsigned i = 0; i < sizeof(T); i++) + { +if (ptr_mask[i] == 0x00) +{ + ptr_f[i] = 0xff; +} + } +} + +void +test01() +{ + // test for long double with padding (float80) + if constexpr (std::numeric_limits::digits == 64) + { +long double f = 0.5f; // long double has padding bits on x86 +fill_padding(f); +std::atomic as{ f }; // padding cleared on constructor +long double t = 1.5; + +as.fetch_add(t); +long double s = f + t; +t = as.load(); +VERIFY(s == t); // padding ignored on comparison +fill_padding(s); +VERIFY(as.compare_exchange_weak(s, f)); // padding cleared on cmpexchg +fill_padding(f); +VERIFY(as.compare_exchange_strong(f, t)); // padding cleared on cmpexchg + } +} + +int main() +{ + test01(); +}
[gcc r14-9474] LoongArch: Remove unused and incorrect "sge_" define_insn
https://gcc.gnu.org/g:f98b85b1ef74b7c5c0852b3d063262bce63df14e commit r14-9474-gf98b85b1ef74b7c5c0852b3d063262bce63df14e Author: Xi Ruoyao Date: Wed Mar 13 20:44:38 2024 +0800 LoongArch: Remove unused and incorrect "sge_" define_insn If this insn is really used, we'll have something like slti $r4,$r0,$r5 in the code. The assembler will reject it because slti wants 2 register operands and 1 immediate operand. But we've not got any bug report for this, indicating this define_insn is unused at all. Note that do_store_flag (in expr.cc) is already converting x >= 1 to x > 0 unconditionally, so this define_insn is indeed unused and we can just remove it. gcc/ChangeLog: * config/loongarch/loongarch.md (any_ge): Remove. (sge_): Remove. Diff: --- gcc/config/loongarch/loongarch.md | 10 -- 1 file changed, 10 deletions(-) diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md index 525e1e82183..18fd9c1e7d5 100644 --- a/gcc/config/loongarch/loongarch.md +++ b/gcc/config/loongarch/loongarch.md @@ -517,7 +517,6 @@ ;; These code iterators allow the signed and unsigned scc operations to use ;; the same template. (define_code_iterator any_gt [gt gtu]) -(define_code_iterator any_ge [ge geu]) (define_code_iterator any_lt [lt ltu]) (define_code_iterator any_le [le leu]) @@ -3355,15 +3354,6 @@ [(set_attr "type" "slt") (set_attr "mode" "")]) -(define_insn "*sge_" - [(set (match_operand:GPR 0 "register_operand" "=r") - (any_ge:GPR (match_operand:X 1 "register_operand" "r") -(const_int 1)))] - "" - "slti\t%0,%.,%1" - [(set_attr "type" "slt") - (set_attr "mode" "")]) - (define_insn "*slt_" [(set (match_operand:GPR 0 "register_operand" "=r") (any_lt:GPR (match_operand:X 1 "register_operand" "r")
[gcc r14-9475] PR modula2/114333 set type comparison against cardinal should cause error addendum
https://gcc.gnu.org/g:7aeedff6a426cc05024af0bc92116d676a5ba42b commit r14-9475-g7aeedff6a426cc05024af0bc92116d676a5ba42b Author: Gaius Mulley Date: Thu Mar 14 15:34:36 2024 + PR modula2/114333 set type comparison against cardinal should cause error addendum This patch applies the new stricter type checking procedure function to the remaining 6 comparisons: less, greater, lessequ, greequ, ifin and ifnotin. gcc/m2/ChangeLog: PR modula2/114333 * gm2-compiler/M2GenGCC.mod (CodeStatement): Remove op1, op2 and op3 parameters to CodeIfLess, CodeIfLessEqu, CodeIfGreEqu, CodeIfGre, CodeIfIn, CodeIfNotIn. (CodeIfLess): Rewrite. (PerformCodeIfLess): New procedure. (CodeIfLess): Rewrite. (PerformCodeIfLess): New procedure. (CodeIfLessEqu): Rewrite. (PerformCodeIfLessEqu): New procedure. (CodeIfGreEqu): Rewrite. (PerformCodeIfGreEqu): New procedure. (CodeIfGre): Rewrite. (PerformCodeIfGre): New procedure. (CodeIfIn): Rewrite. (PerformCodeIfIn): New procedure. (CodeIfNotIn): Rewrite. (PerformCodeIfNotIn): New procedure. gcc/testsuite/ChangeLog: PR modula2/114333 * gm2/pim/fail/badset5.mod: New test. * gm2/pim/fail/badset6.mod: New test. Signed-off-by: Gaius Mulley Diff: --- gcc/m2/gm2-compiler/M2GenGCC.mod | 438 - gcc/testsuite/gm2/pim/fail/badset5.mod | 13 + gcc/testsuite/gm2/pim/fail/badset6.mod | 23 ++ 3 files changed, 300 insertions(+), 174 deletions(-) diff --git a/gcc/m2/gm2-compiler/M2GenGCC.mod b/gcc/m2/gm2-compiler/M2GenGCC.mod index 7633b8425ae..7e27373a6ac 100644 --- a/gcc/m2/gm2-compiler/M2GenGCC.mod +++ b/gcc/m2/gm2-compiler/M2GenGCC.mod @@ -510,14 +510,14 @@ BEGIN LogicalAndOp : CodeSetAnd (q) | LogicalXorOp : CodeSetSymmetricDifference (q) | LogicalDiffOp : CodeSetLogicalDifference (q) | - IfLessOp : CodeIfLess (q, op1, op2, op3) | + IfLessOp : CodeIfLess (q) | IfEquOp: CodeIfEqu (q) | IfNotEquOp : CodeIfNotEqu (q) | - IfGreEquOp : CodeIfGreEqu (q, op1, op2, op3) | - IfLessEquOp: CodeIfLessEqu (q, op1, op2, op3) | - IfGreOp: CodeIfGre (q, op1, op2, op3) | - IfInOp : CodeIfIn (q, op1, op2, op3) | - IfNotInOp : CodeIfNotIn (q, op1, op2, op3) | + IfGreEquOp : CodeIfGreEqu (q) | + IfLessEquOp: CodeIfLessEqu (q) | + IfGreOp: CodeIfGre (q) | + IfInOp : CodeIfIn (q) | + IfNotInOp : CodeIfNotIn (q) | IndrXOp: CodeIndrX (q, op1, op2, op3) | XIndrOp: CodeXIndr (q) | CallOp : CodeCall (CurrentQuadToken, op3) | @@ -6831,50 +6831,67 @@ END CodeIfSetLess ; (* - CodeIfLess - codes the quadruple if op1 < op2 then goto op3 + PerformCodeIfLess - codes the quadruple if op1 < op2 then goto op3 *) -PROCEDURE CodeIfLess (quad: CARDINAL; op1, op2, op3: CARDINAL) ; +PROCEDURE PerformCodeIfLess (quad: CARDINAL) ; VAR tl, tr : Tree ; - location: location_t ; + location : location_t ; + left, right, dest, combined, + leftpos, rightpos, destpos : CARDINAL ; + overflow : BOOLEAN ; + op : QuadOperator ; BEGIN - location := TokenToLocation(CurrentQuadToken) ; + GetQuadOtok (quad, combined, op, +left, right, dest, overflow, +leftpos, rightpos, destpos) ; + location := TokenToLocation (combined) ; - (* firstly ensure that any constant literal is declared *) - DeclareConstant(CurrentQuadToken, op1) ; - DeclareConstant(CurrentQuadToken, op2) ; - IF IsConst(op1) AND IsConst(op2) + IF IsConst(left) AND IsConst(right) THEN - PushValue(op1) ; - PushValue(op2) ; + PushValue(left) ; + PushValue(right) ; IF Less(CurrentQuadToken) THEN - BuildGoto(location, string(CreateLabelName(op3))) + BuildGoto(location, string(CreateLabelName(dest))) ELSE (* fall through *) END - ELSIF IsConstSet(op1) OR (IsVar(op1) AND IsSet(SkipType(GetType(op1 OR - IsConstSet(op2) OR (IsVar(op2) AND IsSet(SkipType(GetType(op2 + ELSIF IsConstSet(left) OR (IsVar(left) AND IsSet(SkipType(GetType(left OR + IsConstSet(right) OR (IsVar(right) AND IsSet(SkipType(GetType(right THEN - CodeIfSetLess(quad, op1, op2, op3) + CodeIfSetLess(quad, left, right, dest) ELSE - IF IsComposite(GetType(op1)) OR IsComposite(GetType(op2)) + IF IsComposite(GetType(left)) OR IsComposite(GetType(right)) THEN - MetaErrorT2 (CurrentQuadToken, + MetaErrorT2 (combined, 'compar
[gcc(refs/users/dfaust/heads/gcc-13-bpf)] btf: fix type id in BTF_KIND_FUNC struct data.
https://gcc.gnu.org/g:193966aab3bba1ca27630a23f4b575c53be9af03 commit 193966aab3bba1ca27630a23f4b575c53be9af03 Author: Cupertino Miranda Date: Tue Jan 30 19:01:12 2024 + btf: fix type id in BTF_KIND_FUNC struct data. This patch corrects the addition of +1 on the type id, which originally was done in the wrong location and led to func_dtd->dtd_type for BTF_KIND_FUNC struct data to contain the type id of the previous entry. gcc/ChangeLog: * btfout.cc (btf_collect_dataset): Corrects BTF type id. (cherry picked from commit 0198cade5ac15c35ed3f5af54060d7bc6a39f326) Diff: --- gcc/btfout.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gcc/btfout.cc b/gcc/btfout.cc index 2b087130d58..0c496e49c2d 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -457,7 +457,8 @@ btf_collect_datasec (ctf_container_ref ctfc) func_dtd->dtd_data.ctti_type = dtd->dtd_type; func_dtd->linkage = dtd->linkage; func_dtd->dtd_name = dtd->dtd_name; - func_dtd->dtd_type = num_types_added + num_types_created; + /* +1 for the sentinel type not in the types map. */ + func_dtd->dtd_type = num_types_added + num_types_created + 1; /* Only the BTF_KIND_FUNC type actually references the name. The BTF_KIND_FUNC_PROTO is always anonymous. */ @@ -480,8 +481,7 @@ btf_collect_datasec (ctf_container_ref ctfc) struct btf_var_secinfo info; - /* +1 for the sentinel type not in the types map. */ - info.type = func_dtd->dtd_type + 1; + info.type = func_dtd->dtd_type; /* Both zero at compile time. */ info.size = 0;
[gcc(refs/users/dfaust/heads/gcc-13-bpf)] btf: add BTF_KIND_FUNC traversal function.
https://gcc.gnu.org/g:1ab0c08b0885fa7549a635f9bae1422499562fc8 commit 1ab0c08b0885fa7549a635f9bae1422499562fc8 Author: Cupertino Miranda Date: Mon Feb 12 17:36:21 2024 + btf: add BTF_KIND_FUNC traversal function. The patch adds a traversal function to traverse all BTF_KIND_FUNC nodes with a callback function. Used for .BTF.ext section content creation. gcc/ChangeLog: * btfout.cc (output_btf_func_types): Use FOR_EACH_VEC_ELT. (traverse_btf_func_types): Define function. * ctfc.h (funcs_traverse_callback): Typedef for function prototype. (traverse_btf_func_types): Add prototype. (cherry picked from commit 69a3ce49bda929e1ffbc1fc1123f5f2485ec944d) Diff: --- gcc/btfout.cc | 22 -- gcc/ctfc.h| 3 +++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gcc/btfout.cc b/gcc/btfout.cc index 0c496e49c2d..0cc0f84a4a8 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -1276,8 +1276,10 @@ output_btf_types (ctf_container_ref ctfc) static void output_btf_func_types (ctf_container_ref ctfc) { - for (size_t i = 0; i < vec_safe_length (funcs); i++) -btf_asm_func_type (ctfc, (*funcs)[i], i); + ctf_dtdef_ref ref; + unsigned i; + FOR_EACH_VEC_ELT (*funcs, i, ref) +btf_asm_func_type (ctfc, ref, i); } /* Output all BTF_KIND_DATASEC records. */ @@ -1452,4 +1454,20 @@ btf_finalize (void) tu_ctfc = NULL; } +/* Traversal function for all BTF_KIND_FUNC type records. */ + +bool +traverse_btf_func_types (funcs_traverse_callback callback, void *data) +{ + ctf_dtdef_ref ref; + unsigned i; + FOR_EACH_VEC_ELT (*funcs, i, ref) +{ + bool stop = callback (ref, data); + if (stop == true) + return true; +} + return false; +} + #include "gt-btfout.h" diff --git a/gcc/ctfc.h b/gcc/ctfc.h index bf1841a7fcb..4034ca861b1 100644 --- a/gcc/ctfc.h +++ b/gcc/ctfc.h @@ -441,6 +441,9 @@ extern int ctf_add_variable (ctf_container_ref, const char *, ctf_id_t, extern ctf_id_t ctf_lookup_tree_type (ctf_container_ref, const tree); extern ctf_id_t get_btf_id (ctf_id_t); +typedef bool (*funcs_traverse_callback) (ctf_dtdef_ref, void *); +bool traverse_btf_func_types (funcs_traverse_callback, void *); + /* CTF section does not emit location information; at this time, location information is needed for BTF CO-RE use-cases. */
[gcc(refs/users/dfaust/heads/gcc-13-bpf)] bpf: Always emit .BTF.ext section if generating BTF
https://gcc.gnu.org/g:4583f84ba8e6729079e4ca5f745b4ebc58b27ab5 commit 4583f84ba8e6729079e4ca5f745b4ebc58b27ab5 Author: Cupertino Miranda Date: Mon Feb 12 17:37:37 2024 + bpf: Always emit .BTF.ext section if generating BTF BPF applications, when generating BTF information should always create a .BTF.ext section. Current implementation was only creating it when -mco-re option was used. This patch makes .BTF.ext always be generated for BPF target objects. The patch also adds conditions around btf_finalize function call such that BTF deallocation happens later for BPF target. For BPF, btf_finalize is only called after .BTF.ext is generated. gcc/ChangeLog: * config/bpf/bpf.cc (bpf_option_override): Make .BTF.ext enabled by default for BPF. (bpf_file_end): Call BTF deallocation. (bpf_asm_init_sections): Correct condition. * dwarf2ctf.cc (ctf_debug_finalize): Conditionally execute BTF deallocation. (ctf_debuf_finish): Correct condition for calling ctf_debug_finalize. (cherry picked from commit 38d2eb337b41e9cdc5eb89ab865d74ef5304bc03) Diff: --- gcc/config/bpf/bpf.cc | 20 +--- gcc/dwarf2ctf.cc | 12 ++-- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc index 394be5f961f..89d3b6b8dfd 100644 --- a/gcc/config/bpf/bpf.cc +++ b/gcc/config/bpf/bpf.cc @@ -197,10 +197,8 @@ bpf_option_override (void) if (TARGET_BPF_CORE && !btf_debuginfo_p ()) error ("BPF CO-RE requires BTF debugging information, use %<-gbtf%>"); - /* To support the portability needs of BPF CO-RE approach, BTF debug - information includes the BPF CO-RE relocations. */ - if (TARGET_BPF_CORE) -write_symbols |= BTF_WITH_CORE_DEBUG; + /* BPF applications always generate .BTF.ext. */ + write_symbols |= BTF_WITH_CORE_DEBUG; /* Unlike much of the other BTF debug information, the information necessary for CO-RE relocations is added to the CTF container by the BPF backend. @@ -220,10 +218,7 @@ bpf_option_override (void) /* -gbtf implies -mcore when using the BPF backend, unless -mno-co-re is specified. */ if (btf_debuginfo_p () && !(target_flags_explicit & MASK_BPF_CORE)) -{ - target_flags |= MASK_BPF_CORE; - write_symbols |= BTF_WITH_CORE_DEBUG; -} +target_flags |= MASK_BPF_CORE; /* Determine available features from ISA setting (-mcpu=). */ if (bpf_has_jmpext == -1) @@ -268,7 +263,7 @@ bpf_option_override (void) static void bpf_asm_init_sections (void) { - if (TARGET_BPF_CORE) + if (btf_debuginfo_p () && btf_with_core_debuginfo_p ()) btf_ext_init (); } @@ -280,8 +275,11 @@ bpf_asm_init_sections (void) static void bpf_file_end (void) { - if (TARGET_BPF_CORE) -btf_ext_output (); + if (btf_debuginfo_p () && btf_with_core_debuginfo_p ()) +{ + btf_ext_output (); + btf_finalize (); +} } #undef TARGET_ASM_FILE_END diff --git a/gcc/dwarf2ctf.cc b/gcc/dwarf2ctf.cc index b2945713036..02431602af3 100644 --- a/gcc/dwarf2ctf.cc +++ b/gcc/dwarf2ctf.cc @@ -944,7 +944,10 @@ ctf_debug_finalize (const char *filename, bool btf) if (btf) { btf_output (filename); - btf_finalize (); + /* btf_finalize when compiling BPF applciations gets deallocated by the +BPF target in bpf_file_end. */ + if (btf_debuginfo_p () && !btf_with_core_debuginfo_p ()) + btf_finalize (); } else @@ -1027,11 +1030,8 @@ ctf_debug_finish (const char * filename) /* Emit BTF debug info here when CO-RE relocations need to be generated. BTF with CO-RE relocations needs to be generated when CO-RE is in effect for the BPF target. */ - if (btf_with_core_debuginfo_p ()) -{ - gcc_assert (btf_debuginfo_p ()); - ctf_debug_finalize (filename, btf_debuginfo_p ()); -} + if (btf_debuginfo_p () && btf_with_core_debuginfo_p ()) +ctf_debug_finalize (filename, btf_debuginfo_p ()); } #include "gt-dwarf2ctf.h"
[gcc(refs/users/dfaust/heads/gcc-13-bpf)] bpf: implementation of func_info in .BTF.ext.
https://gcc.gnu.org/g:ab9ca7ee0825823e24048a1c213ef2dc587d6bc7 commit ab9ca7ee0825823e24048a1c213ef2dc587d6bc7 Author: Cupertino Miranda Date: Mon Feb 12 17:46:03 2024 + bpf: implementation of func_info in .BTF.ext. Kernel verifier complains in some particular cases for missing func_info implementation in .BTF.ext. This patch implements it. Strings are cached locally in coreout.cc to avoid adding duplicated strings in the string list. This string deduplication should eventually be moved to the CTFC functions such that this happens widely. With this implementation, the CO-RE relocations information was also simplified and integrated with the FuncInfo structures. gcc/Changelog: PR target/113453 * config/bpf/bpf.cc (bpf_function_prologue): Define target hook. * config/bpf/coreout.cc (brf_ext_info_section) (btf_ext_info): Move from coreout.h (btf_ext_funcinfo, btf_ext_lineinfo): Add struct. (bpf_core_reloc): Rename to btf_ext_core_reloc. (btf_ext): Add static variable. (btfext_info_sec_find_or_add, SEARCH_NODE_AND_RETURN) (bpf_create_or_find_funcinfo, bpt_create_core_reloc) (btf_ext_add_string, btf_funcinfo_type_callback) (btf_add_func_info_for, btf_validate_funcinfo) (btf_ext_info_len, output_btfext_func_info): Add function. (output_btfext_header, bpf_core_reloc_add) (output_btfext_core_relocs, btf_ext_init, btf_ext_output): Change to support new structs. * config/bpf/coreout.h (btf_ext_funcinfo, btf_ext_lineinfo): Move and change in coreout.cc. (btf_add_func_info_for, btf_ext_add_string): Add prototypes. gcc/testsuite/ChangeLog: PR target/113453 * gcc.target/bpf/btfext-funcinfo-nocore.c: Add. * gcc.target/bpf/btfext-funcinfo.c: Add. * gcc.target/bpf/core-attr-5.c: Fix regexp. * gcc.target/bpf/core-attr-6.c: Fix regexp. * gcc.target/bpf/core-builtin-fieldinfo-offset-1.c: Fix regexp. * gcc.target/bpf/core-section-1.c: Fix regexp. (cherry picked from commit 77142bdba485057550c5d849864948b0d20be8af) Diff: --- gcc/config/bpf/bpf.cc | 12 + gcc/config/bpf/coreout.cc | 514 +++-- gcc/config/bpf/coreout.h | 20 +- .../gcc.target/bpf/btfext-funcinfo-nocore.c| 42 ++ gcc/testsuite/gcc.target/bpf/btfext-funcinfo.c | 46 ++ gcc/testsuite/gcc.target/bpf/core-attr-5.c | 9 +- gcc/testsuite/gcc.target/bpf/core-attr-6.c | 6 +- .../bpf/core-builtin-fieldinfo-offset-1.c | 13 +- gcc/testsuite/gcc.target/bpf/core-section-1.c | 2 +- 9 files changed, 502 insertions(+), 162 deletions(-) diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc index 89d3b6b8dfd..233025aac95 100644 --- a/gcc/config/bpf/bpf.cc +++ b/gcc/config/bpf/bpf.cc @@ -386,6 +386,18 @@ bpf_compute_frame_layout (void) #undef TARGET_COMPUTE_FRAME_LAYOUT #define TARGET_COMPUTE_FRAME_LAYOUT bpf_compute_frame_layout +/* Defined to initialize data for func_info region in .BTF.ext section. */ + +static void +bpf_function_prologue (FILE *f ATTRIBUTE_UNUSED) +{ + if (btf_debuginfo_p ()) +btf_add_func_info_for (cfun->decl, current_function_func_begin_label); +} + +#undef TARGET_ASM_FUNCTION_PROLOGUE +#define TARGET_ASM_FUNCTION_PROLOGUE bpf_function_prologue + /* Expand to the instructions in a function prologue. This function is called when expanding the 'prologue' pattern in bpf.md. */ diff --git a/gcc/config/bpf/coreout.cc b/gcc/config/bpf/coreout.cc index 0c5d166298f..7ac7f8bdde1 100644 --- a/gcc/config/bpf/coreout.cc +++ b/gcc/config/bpf/coreout.cc @@ -31,6 +31,7 @@ #include "btf.h" #include "rtl.h" #include "tree-pretty-print.h" +#include "cgraph.h" #include "coreout.h" @@ -95,64 +96,193 @@ result, a single .BTF.ext section can contain CO-RE relocations for multiple programs in distinct sections. */ -/* Internal representation of a BPF CO-RE relocation record. */ +/* BTF.ext debug info section. */ +static GTY (()) section * btf_ext_info_section; + +#ifndef BTF_EXT_INFO_SECTION_NAME +#define BTF_EXT_INFO_SECTION_NAME ".BTF.ext" +#endif +#define BTF_EXT_INFO_SECTION_FLAGS (SECTION_DEBUG) + +#ifndef BTF_EXT_INFO_SECTION_LABEL +#define BTF_EXT_INFO_SECTION_LABEL "Lbtfext" +#endif + +#define MAX_BTF_EXT_LABEL_BYTES 40 +static char btf_ext_info_section_label[MAX_BTF_EXT_LABEL_BYTES]; + +/* A funcinfo record, in the .BTF.ext funcinfo section. */ +struct GTY ((chain_next ("%h.next"))) btf_ext_funcinfo +{ + uint32_t type; /* Type ID of a BTF_KIND_FUNC type. */ + const char *fnname; + const char *label; + + struct btf_ext_funcinfo *next; /* Linked list to collect func_info elems.
[gcc(refs/users/dfaust/heads/gcc-13-bpf)] bpf: renames coreout.* files to btfext-out.*.
https://gcc.gnu.org/g:5cb3615ed932faa521e2587c047b0771816c14aa commit 5cb3615ed932faa521e2587c047b0771816c14aa Author: Cupertino Miranda Date: Mon Feb 12 17:56:04 2024 + bpf: renames coreout.* files to btfext-out.*. gcc/ChangeLog: * config.gcc (target_gtfiles): Change coreout to btfext-out. (extra_objs): Change coreout to btfext-out. * config/bpf/coreout.cc: Rename to btfext-out.cc. * config/bpf/btfext-out.cc: Add. * config/bpf/coreout.h: Rename to btfext-out.h. * config/bpf/btfext-out.h: Add. * config/bpf/core-builtins.cc: Change include. * config/bpf/core-builtins.h: Change include. * config/bpf/t-bpf: Accomodate renamed files. (cherry picked from commit 13914f4be9d7d4ac075e780b7a4bd8bac2ca1f15) Diff: --- gcc/config.gcc | 4 ++-- gcc/config/bpf/{coreout.cc => btfext-out.cc} | 4 ++-- gcc/config/bpf/{coreout.h => btfext-out.h} | 2 +- gcc/config/bpf/core-builtins.cc | 2 +- gcc/config/bpf/core-builtins.h | 2 +- gcc/config/bpf/t-bpf | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gcc/config.gcc b/gcc/config.gcc index db5de8f034b..36388e0e4cc 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -1594,8 +1594,8 @@ bpf-*-*) tmake_file="${tmake_file} bpf/t-bpf" use_collect2=no use_gcc_stdint=provide -extra_objs="coreout.o core-builtins.o" -target_gtfiles="$target_gtfiles \$(srcdir)/config/bpf/coreout.cc \$(srcdir)/config/bpf/core-builtins.cc" +extra_objs="btfext-out.o core-builtins.o" +target_gtfiles="$target_gtfiles \$(srcdir)/config/bpf/btfext-out.cc \$(srcdir)/config/bpf/core-builtins.cc" ;; cris-*-elf | cris-*-none) tm_file="elfos.h newlib-stdint.h ${tm_file}" diff --git a/gcc/config/bpf/coreout.cc b/gcc/config/bpf/btfext-out.cc similarity index 99% rename from gcc/config/bpf/coreout.cc rename to gcc/config/bpf/btfext-out.cc index 7ac7f8bdde1..7b7b0a9c8c2 100644 --- a/gcc/config/bpf/coreout.cc +++ b/gcc/config/bpf/btfext-out.cc @@ -33,7 +33,7 @@ #include "tree-pretty-print.h" #include "cgraph.h" -#include "coreout.h" +#include "btfext-out.h" /* This file contains data structures and routines for construction and output of BPF Compile Once - Run Everywhere (BPF CO-RE) information. @@ -614,4 +614,4 @@ btf_ext_output (void) dw2_asm_output_data (4, 0, "Required padding by libbpf structs"); } -#include "gt-coreout.h" +#include "gt-btfext-out.h" diff --git a/gcc/config/bpf/coreout.h b/gcc/config/bpf/btfext-out.h similarity index 98% rename from gcc/config/bpf/coreout.h rename to gcc/config/bpf/btfext-out.h index e909344bee8..5dbbdc04a1a 100644 --- a/gcc/config/bpf/coreout.h +++ b/gcc/config/bpf/btfext-out.h @@ -1,4 +1,4 @@ -/* coreout.h - Declarations and definitions related to +/* btfext-out.h - Declarations and definitions related to BPF Compile Once - Run Everywhere (CO-RE) support. Copyright (C) 2021-2023 Free Software Foundation, Inc. diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc index 1376c930903..570306974a0 100644 --- a/gcc/config/bpf/core-builtins.cc +++ b/gcc/config/bpf/core-builtins.cc @@ -45,7 +45,7 @@ along with GCC; see the file COPYING3. If not see #include "ctfc.h" #include "btf.h" -#include "coreout.h" +#include "btfext-out.h" #include "core-builtins.h" /* BPF CO-RE builtins definition. diff --git a/gcc/config/bpf/core-builtins.h b/gcc/config/bpf/core-builtins.h index c54f6ddac81..e56b55b94e0 100644 --- a/gcc/config/bpf/core-builtins.h +++ b/gcc/config/bpf/core-builtins.h @@ -1,7 +1,7 @@ #ifndef BPF_CORE_BUILTINS_H #define BPF_CORE_BUILTINS_H -#include "coreout.h" +#include "btfext-out.h" enum bpf_builtins { diff --git a/gcc/config/bpf/t-bpf b/gcc/config/bpf/t-bpf index 18f1fa67794..dc50332350c 100644 --- a/gcc/config/bpf/t-bpf +++ b/gcc/config/bpf/t-bpf @@ -1,7 +1,7 @@ -TM_H += $(srcdir)/config/bpf/coreout.h $(srcdir)/config/bpf/core-builtins.h +TM_H += $(srcdir)/config/bpf/btfext-out.h $(srcdir)/config/bpf/core-builtins.h -coreout.o: $(srcdir)/config/bpf/coreout.cc +btfext-out.o: $(srcdir)/config/bpf/btfext-out.cc $(COMPILE) $< $(POSTCOMPILE)
[gcc(refs/users/dfaust/heads/gcc-13-bpf)] bpf: add inline memset expansion
https://gcc.gnu.org/g:548dbf6f87878800f214982e6c6d104b8a2a6ea1 commit 548dbf6f87878800f214982e6c6d104b8a2a6ea1 Author: David Faust Date: Mon Mar 4 09:35:01 2024 -0800 bpf: add inline memset expansion Similar to memmove and memcpy, the BPF backend cannot fall back on a library call to implement __builtin_memset, and should always expand calls to it inline if possible. This patch implements simple inline expansion of memset in the BPF backend in a verifier-friendly way. Similar to memcpy and memmove, the size must be an integer constant, as is also required by clang. gcc/ * config/bpf/bpf-protos.h (bpf_expand_setmem): New prototype. * config/bpf/bpf.cc (bpf_expand_setmem): New. * config/bpf/bpf.md (setmemdi): New define_expand. gcc/testsuite/ * gcc.target/bpf/memset-1.c: New test. (cherry picked from commit eae6b63b5b5426f943f58b5ae0bf0a6068ca8ad6) Diff: --- gcc/config/bpf/bpf-protos.h | 1 + gcc/config/bpf/bpf.cc | 66 + gcc/config/bpf/bpf.md | 17 + gcc/testsuite/gcc.target/bpf/memset-1.c | 39 +++ 4 files changed, 123 insertions(+) diff --git a/gcc/config/bpf/bpf-protos.h b/gcc/config/bpf/bpf-protos.h index 3b63b18857c..876569ab645 100644 --- a/gcc/config/bpf/bpf-protos.h +++ b/gcc/config/bpf/bpf-protos.h @@ -36,5 +36,6 @@ class gimple_opt_pass; gimple_opt_pass *make_pass_lower_bpf_core (gcc::context *ctxt); bool bpf_expand_cpymem (rtx *, bool); +bool bpf_expand_setmem (rtx *); #endif /* ! GCC_BPF_PROTOS_H */ diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc index 233025aac95..c008a961e51 100644 --- a/gcc/config/bpf/bpf.cc +++ b/gcc/config/bpf/bpf.cc @@ -1309,6 +1309,72 @@ bpf_expand_cpymem (rtx *operands, bool is_move) return true; } +/* Expand setmem, as from __builtin_memset. + OPERANDS are the same as the setmem pattern. + Return true if the expansion was successful, false otherwise. */ + +bool +bpf_expand_setmem (rtx *operands) +{ + /* Size must be constant for this expansion to work. */ + if (!CONST_INT_P (operands[1])) +{ + if (flag_building_libgcc) + warning (0, "could not inline call to %<__builtin_memset%>: " +"size must be constant"); + else + error ("could not inline call to %<__builtin_memset%>: " + "size must be constant"); + return false; +} + + /* Alignment is a CONST_INT. */ + gcc_assert (CONST_INT_P (operands[3])); + + rtx dst = operands[0]; + rtx size = operands[1]; + rtx val = operands[2]; + unsigned HOST_WIDE_INT size_bytes = UINTVAL (size); + unsigned align = UINTVAL (operands[3]); + enum machine_mode mode; + switch (align) +{ +case 1: mode = QImode; break; +case 2: mode = HImode; break; +case 4: mode = SImode; break; +case 8: mode = DImode; break; +default: + gcc_unreachable (); +} + + unsigned iters = size_bytes >> ceil_log2 (align); + unsigned remainder = size_bytes & (align - 1); + unsigned inc = GET_MODE_SIZE (mode); + unsigned offset = 0; + + for (unsigned int i = 0; i < iters; i++) +{ + emit_move_insn (adjust_address (dst, mode, offset), val); + offset += inc; +} + if (remainder & 4) +{ + emit_move_insn (adjust_address (dst, SImode, offset), val); + offset += 4; + remainder -= 4; +} + if (remainder & 2) +{ + emit_move_insn (adjust_address (dst, HImode, offset), val); + offset += 2; + remainder -= 2; +} + if (remainder & 1) +emit_move_insn (adjust_address (dst, QImode, offset), val); + + return true; +} + /* Finally, build the GCC target. */ struct gcc_target targetm = TARGET_INITIALIZER; diff --git a/gcc/config/bpf/bpf.md b/gcc/config/bpf/bpf.md index c467bff85b7..1b3cc5c9f6f 100644 --- a/gcc/config/bpf/bpf.md +++ b/gcc/config/bpf/bpf.md @@ -663,4 +663,21 @@ FAIL; }) +;; memset +;; 0 is dst +;; 1 is length +;; 2 is value +;; 3 is alignment +(define_expand "setmemdi" + [(set (match_operand:BLK 0 "memory_operand") + (match_operand:QI 2 "nonmemory_operand")) + (use (match_operand:DI 1 "general_operand")) + (match_operand 3 "immediate_operand")] + "" + { + if (bpf_expand_setmem (operands)) +DONE; + FAIL; +}) + (include "atomic.md") diff --git a/gcc/testsuite/gcc.target/bpf/memset-1.c b/gcc/testsuite/gcc.target/bpf/memset-1.c new file mode 100644 index 000..9e9f8eff028 --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/memset-1.c @@ -0,0 +1,39 @@ +/* Ensure memset is expanded inline rather than emitting a libcall. */ + +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +struct context { + unsigned int data; + unsigned int data_end; + unsigned int data_meta; + unsigned int ingress; + unsigned int queue_index; + unsigned int egress; +}; + +void +set_small (struct context *ctx) +{ + void *data = (void *)(long)
[gcc(refs/users/dfaust/heads/gcc-13-bpf)] ctf: fix incorrect CTF for multi-dimensional array types
https://gcc.gnu.org/g:f2cd7e1cb3d326ceb5af3e4629f1ab19dabe6d3f commit f2cd7e1cb3d326ceb5af3e4629f1ab19dabe6d3f Author: Cupertino Miranda Date: Thu Feb 29 10:56:13 2024 -0800 ctf: fix incorrect CTF for multi-dimensional array types PR debug/114186 DWARF DIEs of type DW_TAG_subrange_type are linked together to represent the information about the subsequent dimensions. The CTF processing was so far working through them in the opposite (incorrect) order. While fixing the issue, refactor the code a bit for readability. co-authored-By: Indu Bhagat gcc/ PR debug/114186 * dwarf2ctf.cc (gen_ctf_array_type): Invoke the ctf_add_array () in the correct order of the dimensions. (gen_ctf_subrange_type): Refactor out handling of DW_TAG_subrange_type DIE to here. gcc/testsuite/ PR debug/114186 * gcc.dg/debug/ctf/ctf-array-6.c: Add test. (cherry picked from commit 5d24bf3afd1bea3e51b87fb7ff24c21e29913999) Diff: --- gcc/dwarf2ctf.cc | 158 +-- gcc/testsuite/gcc.dg/debug/ctf/ctf-array-6.c | 14 +++ 2 files changed, 89 insertions(+), 83 deletions(-) diff --git a/gcc/dwarf2ctf.cc b/gcc/dwarf2ctf.cc index 02431602af3..7cbfe9a9b53 100644 --- a/gcc/dwarf2ctf.cc +++ b/gcc/dwarf2ctf.cc @@ -349,105 +349,97 @@ gen_ctf_pointer_type (ctf_container_ref ctfc, dw_die_ref ptr_type) return ptr_type_id; } -/* Generate CTF for an array type. */ +/* Recursively generate CTF for array dimensions starting at DIE C (of type + DW_TAG_subrange_type) until DIE LAST (of type DW_TAG_subrange_type) is + reached. ARRAY_ELEMS_TYPE_ID is base type for the array. */ static ctf_id_t -gen_ctf_array_type (ctf_container_ref ctfc, dw_die_ref array_type) +gen_ctf_subrange_type (ctf_container_ref ctfc, ctf_id_t array_elems_type_id, + dw_die_ref c, dw_die_ref last) { - dw_die_ref c; - ctf_id_t array_elems_type_id = CTF_NULL_TYPEID; + ctf_arinfo_t arinfo; + ctf_id_t array_node_type_id = CTF_NULL_TYPEID; - int vector_type_p = get_AT_flag (array_type, DW_AT_GNU_vector); - if (vector_type_p) -return array_elems_type_id; + dw_attr_node *upper_bound_at; + dw_die_ref array_index_type; + uint32_t array_num_elements; - dw_die_ref array_elems_type = ctf_get_AT_type (array_type); + if (dw_get_die_tag (c) == DW_TAG_subrange_type) +{ + /* When DW_AT_upper_bound is used to specify the size of an +array in DWARF, it is usually an unsigned constant +specifying the upper bound index of the array. However, +for unsized arrays, such as foo[] or bar[0], +DW_AT_upper_bound is a signed integer constant +instead. */ + + upper_bound_at = get_AT (c, DW_AT_upper_bound); + if (upper_bound_at + && AT_class (upper_bound_at) == dw_val_class_unsigned_const) + /* This is the upper bound index. */ + array_num_elements = get_AT_unsigned (c, DW_AT_upper_bound) + 1; + else if (get_AT (c, DW_AT_count)) + array_num_elements = get_AT_unsigned (c, DW_AT_count); + else + { + /* This is a VLA of some kind. */ + array_num_elements = 0; + } +} + else +gcc_unreachable (); - /* First, register the type of the array elements if needed. */ - array_elems_type_id = gen_ctf_type (ctfc, array_elems_type); + /* Ok, mount and register the array type. Note how the array + type we register here is the type of the elements in + subsequent "dimensions", if there are any. */ + arinfo.ctr_nelems = array_num_elements; - /* DWARF array types pretend C supports multi-dimensional arrays. - So for the type int[N][M], the array type DIE contains two - subrange_type children, the first with upper bound N-1 and the - second with upper bound M-1. + array_index_type = ctf_get_AT_type (c); + arinfo.ctr_index = gen_ctf_type (ctfc, array_index_type); - CTF, on the other hand, just encodes each array type in its own - array type CTF struct. Therefore we have to iterate on the - children and create all the needed types. */ + if (c == last) +arinfo.ctr_contents = array_elems_type_id; + else +arinfo.ctr_contents = gen_ctf_subrange_type (ctfc, array_elems_type_id, +dw_get_die_sib (c), last); - c = dw_get_die_child (array_type); - gcc_assert (c); - do -{ - ctf_arinfo_t arinfo; - dw_die_ref array_index_type; - uint32_t array_num_elements; + if (!ctf_type_exists (ctfc, c, &array_node_type_id)) +array_node_type_id = ctf_add_array (ctfc, CTF_ADD_ROOT, &arinfo, c); - c = dw_get_die_sib (c); + return array_node_type_id; +} - if (dw_get_die_tag (c) == DW_TAG_subrange_type) - { - dw_attr_node *upper_bound_at; - - array_index_type = ctf_get_AT_type (c); - - /* Whe
[gcc(refs/users/dfaust/heads/gcc-13-bpf)] bpf: testsuite: fix unresolved test in memset-1.c
https://gcc.gnu.org/g:64e6da250a07c19d302ec8648824cb42b608cf62 commit 64e6da250a07c19d302ec8648824cb42b608cf62 Author: David Faust Date: Thu Mar 7 09:23:38 2024 -0800 bpf: testsuite: fix unresolved test in memset-1.c The test was trying to do too much by both checking for an error, and checking the resulting assembly. Of course, due to the error no asm was produced, so the scan-asm went unresolved. Split it into two separate tests to fix the issue. gcc/testsuite/ * gcc.target/bpf/memset-1.c: Move error test case to... * gcc.target/bpf/memset-2.c: ... here. New test. (cherry picked from commit 10c609191c4462133d6a4ea10a739167204f2cd3) Diff: --- gcc/testsuite/gcc.target/bpf/memset-1.c | 8 gcc/testsuite/gcc.target/bpf/memset-2.c | 22 ++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/gcc/testsuite/gcc.target/bpf/memset-1.c b/gcc/testsuite/gcc.target/bpf/memset-1.c index 9e9f8eff028..7c4768c6e73 100644 --- a/gcc/testsuite/gcc.target/bpf/memset-1.c +++ b/gcc/testsuite/gcc.target/bpf/memset-1.c @@ -28,12 +28,4 @@ set_large (struct context *ctx) __builtin_memset (dest, 0xfe, 130); } -void -set_variable (struct context *ctx) -{ - void *data = (void *)(long)ctx->data; - char *dest = data; - __builtin_memset (dest, 0xbc, ctx->data_meta); /* { dg-error "could not inline call" } */ -} - /* { dg-final { scan-assembler-times "call" 0 } } */ diff --git a/gcc/testsuite/gcc.target/bpf/memset-2.c b/gcc/testsuite/gcc.target/bpf/memset-2.c new file mode 100644 index 000..0602a1a277c --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/memset-2.c @@ -0,0 +1,22 @@ +/* Test that we error if memset cannot be expanded inline. */ + +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +struct context { + unsigned int data; + unsigned int data_end; + unsigned int data_meta; + unsigned int ingress; + unsigned int queue_index; + unsigned int egress; +}; + + +void +set_variable (struct context *ctx) +{ + void *data = (void *)(long)ctx->data; + char *dest = data; + __builtin_memset (dest, 0xbc, ctx->data_meta); /* { dg-error "could not inline call" } */ +}
[gcc(refs/users/dfaust/heads/gcc-13-bpf)] bpf: add size threshold for inlining mem builtins
https://gcc.gnu.org/g:333445364ba7829dde7a9e8548a26c26eb979c21 commit 333445364ba7829dde7a9e8548a26c26eb979c21 Author: David Faust Date: Thu Mar 7 09:29:32 2024 -0800 bpf: add size threshold for inlining mem builtins BPF cannot fall back on library calls to implement memmove, memcpy and memset, so we attempt to expand these inline always if possible. However, this inline expansion was being attempted even for excessively large operations, which could result in gcc consuming huge amounts of memory and hanging. Add a size threshold in the BPF backend below which to always expand these operations inline, and introduce an option -minline-memops-threshold= to control the threshold. Defaults to 1024 bytes. gcc/ * config/bpf/bpf.cc (bpf_expand_cpymem, bpf_expand_setmem): Do not attempt inline expansion if size is above threshold. * config/bpf/bpf.opt (-minline-memops-threshold): New option. * doc/invoke.texi (eBPF Options) <-minline-memops-threshold>: Document. gcc/testsuite/ * gcc.target/bpf/inline-memops-threshold-1.c: New test. * gcc.target/bpf/inline-memops-threshold-2.c: New test. (cherry picked from commit 0e850eff58539fb79483664962fac6c46d65c79d) Diff: --- gcc/config/bpf/bpf.cc | 26 +- gcc/config/bpf/bpf.opt | 4 gcc/doc/invoke.texi| 11 - .../gcc.target/bpf/inline-memops-threshold-1.c | 15 + .../gcc.target/bpf/inline-memops-threshold-2.c | 11 + 5 files changed, 65 insertions(+), 2 deletions(-) diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc index c008a961e51..83843574029 100644 --- a/gcc/config/bpf/bpf.cc +++ b/gcc/config/bpf/bpf.cc @@ -1244,9 +1244,9 @@ bool bpf_expand_cpymem (rtx *operands, bool is_move) { /* Size must be constant for this expansion to work. */ + const char *name = is_move ? "memmove" : "memcpy"; if (!CONST_INT_P (operands[2])) { - const char *name = is_move ? "memmove" : "memcpy"; if (flag_building_libgcc) warning (0, "could not inline call to %<__builtin_%s%>: " "size must be constant", name); @@ -1275,6 +1275,18 @@ bpf_expand_cpymem (rtx *operands, bool is_move) gcc_unreachable (); } + /* For sizes above threshold, always use a libcall. */ + if (size_bytes > (unsigned HOST_WIDE_INT) bpf_inline_memops_threshold) +{ + if (flag_building_libgcc) + warning (0, "could not inline call to %<__builtin_%s%>: " +"too many bytes, use %<-minline-memops-threshold%>", name); + else + error ("could not inline call to %<__builtin_%s%>: " + "too many bytes, use %<-minline-memops-threshold%>", name); + return false; +} + unsigned iters = size_bytes >> ceil_log2 (align); unsigned remainder = size_bytes & (align - 1); @@ -1347,6 +1359,18 @@ bpf_expand_setmem (rtx *operands) gcc_unreachable (); } + /* For sizes above threshold, always use a libcall. */ + if (size_bytes > (unsigned HOST_WIDE_INT) bpf_inline_memops_threshold) +{ + if (flag_building_libgcc) + warning (0, "could not inline call to %<__builtin_memset%>: " +"too many bytes, use %<-minline-memops-threshold%>"); + else + error ("could not inline call to %<__builtin_memset%>: " + "too many bytes, use %<-minline-memops-threshold%>"); + return false; +} + unsigned iters = size_bytes >> ceil_log2 (align); unsigned remainder = size_bytes & (align - 1); unsigned inc = GET_MODE_SIZE (mode); diff --git a/gcc/config/bpf/bpf.opt b/gcc/config/bpf/bpf.opt index efa0380ee3f..ab166bfd865 100644 --- a/gcc/config/bpf/bpf.opt +++ b/gcc/config/bpf/bpf.opt @@ -106,3 +106,7 @@ Enum(asm_dialect) String(normal) Value(ASM_NORMAL) EnumValue Enum(asm_dialect) String(pseudoc) Value(ASM_PSEUDOC) + +minline-memops-threshold= +Target RejectNegative Joined UInteger Var(bpf_inline_memops_threshold) Init(1024) +-minline-memops-threshold= Maximum size of memset/memmove/memcpy to inline, larger sizes will use a library call. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 999867e9d6d..746ce282f39 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -946,7 +946,7 @@ Objective-C and Objective-C++ Dialects}. @gccoptlist{-mbig-endian -mlittle-endian -mframe-limit=@var{bytes} -mxbpf -mco-re -mno-co-re -mjmpext -mjmp32 -malu32 -mv3-atomics -mbswap -msdiv -msmov -mcpu=@var{version} --masm=@var{dialect}} +-masm=@var{dialect} -minline-memops-threshold=@var{bytes}} @emph{FR30 Options} @gccoptlist{-msmall-model -mno-lsim} @@ -24620,6 +24620,15 @@ Outputs pseudo-c assembly dialect. @end table +@opindex -minline-memops-threshold +@item -minline-memops-threshold=@var{bytes} +Specifies a si
[gcc(refs/users/dfaust/heads/gcc-13-bpf)] testsuite: ctf: make array in ctf-file-scope-1 fixed length
https://gcc.gnu.org/g:3eae1cdff0cf06bd21b51700e22d443110d0adad commit 3eae1cdff0cf06bd21b51700e22d443110d0adad Author: David Faust Date: Fri Mar 1 10:43:24 2024 -0800 testsuite: ctf: make array in ctf-file-scope-1 fixed length The array member of struct SFOO in the ctf-file-scope-1 caused the test to fail for the BPF target, since BPF does not support dynamic stack allocation. The array does not need to variable length for the sake of the test, so make it fixed length instead to allow the test to run successfully for the bpf-unknown-none target. gcc/testsuite/ * gcc.dg/debug/ctf/ctf-file-scope-1.c (SFOO): Make array member fixed-length. (cherry picked from commit 64221c7bffbdd399e49554b0fb08b38325657596) Diff: --- gcc/testsuite/gcc.dg/debug/ctf/ctf-file-scope-1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-file-scope-1.c b/gcc/testsuite/gcc.dg/debug/ctf/ctf-file-scope-1.c index a683113e505..ddfb31da405 100644 --- a/gcc/testsuite/gcc.dg/debug/ctf/ctf-file-scope-1.c +++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-file-scope-1.c @@ -9,7 +9,7 @@ int foo (int n) { - typedef struct { int a[n]; } SFOO; + typedef struct { int a[6]; } SFOO; SFOO a; __attribute__ ((noinline)) SFOO gfoo (void) { return a; }
[gcc r14-9476] icf: Reset SSA_NAME_{PTR, RANGE}_INFO in successfully merged functions [PR113907]
https://gcc.gnu.org/g:7580e39452b65ab5fb5a06f3f1ad7d59720269b5 commit r14-9476-g7580e39452b65ab5fb5a06f3f1ad7d59720269b5 Author: Jakub Jelinek Date: Thu Mar 14 17:48:30 2024 +0100 icf: Reset SSA_NAME_{PTR,RANGE}_INFO in successfully merged functions [PR113907] AFAIK we have no code in LTO streaming to stream out or in SSA_NAME_{RANGE,PTR}_INFO, so LTO effectively throws it all away and let vrp1 and alias analysis after IPA recompute that. There is just one spot, for IPA VRP and IPA bit CCP we save/restore ranges and set SSA_NAME_{PTR,RANGE}_INFO e.g. on parameters depending on what we saved and propagated, but that is after streaming in bodies for the post IPA optimizations. Now, without LTO SSA_NAME_{RANGE,PTR}_INFO is already computed from earlier in many cases (er.g. evrp and early alias analysis but other spots too), but IPA ICF is ignoring the ranges and points-to details when comparing the bodies. I think ignoring that is just fine, that is effectively what we do for LTO where we throw that information away before the analysis, and not ignoring it could lead to fewer ICF merging possibilities. So, the following patch instead verifies that for LTO SSA_NAME_{PTR,RANGE}_INFO just isn't there on SSA_NAMEs in functions into which other functions have been ICFed, and for non-LTO throws that information away (which matches the LTO behavior). Another possibility would be to remember the SSA_NAME <-> SSA_NAME mapping vector (just one of the 2) on successful sem_function::equals on the sem_function which is not the chosen leader (e.g. how SSA_NAMEs in the leader map to SSA_NAMEs in the other function) and use that vector to union the ranges in sem_function::merge. I can implement that for comparison, but wanted to post this first if there is an agreement on doing that or if Honza thinks we should take SSA_NAME_{RANGE,PTR}_INFO into account. I think we can compare SSA_NAME_RANGE_INFO, but have no idea how to try to compare points to info. And I think it will result in less effective ICF for non-LTO vs. LTO unnecessarily. 2024-03-12 Jakub Jelinek PR middle-end/113907 * ipa-icf.cc (sem_item_optimizer::merge_classes): Reset SSA_NAME_RANGE_INFO and SSA_NAME_PTR_INFO on successfully ICF merged functions. * gcc.dg/pr113907-1.c: New test. Diff: --- gcc/ipa-icf.cc| 32 - gcc/testsuite/gcc.dg/pr113907-1.c | 49 +++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/gcc/ipa-icf.cc b/gcc/ipa-icf.cc index 5d5a42f9c6c..120d8544988 100644 --- a/gcc/ipa-icf.cc +++ b/gcc/ipa-icf.cc @@ -3398,6 +3398,7 @@ sem_item_optimizer::merge_classes (unsigned int prev_class_count, continue; sem_item *source = c->members[0]; + bool this_merged_p = false; if (DECL_NAME (source->decl) && MAIN_NAME_P (DECL_NAME (source->decl))) @@ -3445,7 +3446,7 @@ sem_item_optimizer::merge_classes (unsigned int prev_class_count, if (dbg_cnt (merged_ipa_icf)) { bool merged = source->merge (alias); - merged_p |= merged; + this_merged_p |= merged; if (merged && alias->type == VAR) { @@ -3454,6 +3455,35 @@ sem_item_optimizer::merge_classes (unsigned int prev_class_count, } } } + + merged_p |= this_merged_p; + if (this_merged_p + && source->type == FUNC + && (!flag_wpa || flag_checking)) + { + unsigned i; + tree name; + FOR_EACH_SSA_NAME (i, name, DECL_STRUCT_FUNCTION (source->decl)) + { + /* We need to either merge or reset SSA_NAME_*_INFO. + For merging we don't preserve the mapping between + original and alias SSA_NAMEs from successful equals + calls. */ + if (POINTER_TYPE_P (TREE_TYPE (name))) + { + if (SSA_NAME_PTR_INFO (name)) + { + gcc_checking_assert (!flag_wpa); + SSA_NAME_PTR_INFO (name) = NULL; + } + } + else if (SSA_NAME_RANGE_INFO (name)) + { + gcc_checking_assert (!flag_wpa); + SSA_NAME_RANGE_INFO (name) = NULL; + } + } + } } if (!m_merged_variables.is_empty ()) diff --git a/gcc/testsuite/gcc.dg/pr113907-1.c b/gcc/testsuite/gcc.dg/pr113907-1.c new file mode 100644 index 000..04c4fb8c128 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr113907-1.c @@ -0,0 +1,49 @@ +/* PR middle-end/113907 */ +/* { dg-do run } */ +/* { dg-options "-O2
[gcc r14-9477] gcn: Fix a comment typo
https://gcc.gnu.org/g:fd7104388406b77ad4b81eb77d976ecfff848913 commit r14-9477-gfd7104388406b77ad4b81eb77d976ecfff848913 Author: Jakub Jelinek Date: Thu Mar 14 17:51:32 2024 +0100 gcn: Fix a comment typo I've noticed a typo in the comment above ABI_VERSION_SPEC. Fixed thusly. 2024-03-14 Jakub Jelinek * config/gcn/gcn-hsa.h (ABI_VERSION_SPEC): Fix comment typo. Diff: --- gcc/config/gcn/gcn-hsa.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/config/gcn/gcn-hsa.h b/gcc/config/gcn/gcn-hsa.h index e5b93f7d9e5..9cf181f52a4 100644 --- a/gcc/config/gcn/gcn-hsa.h +++ b/gcc/config/gcn/gcn-hsa.h @@ -80,7 +80,7 @@ extern unsigned int gcn_local_sym_hash (const char *name); writes a new AMD GPU object file and the ABI version needs to be the same. - LLVM <= 17 defaults to 4 while LLVM >= 18 defaults to 5. GCC supports LLVM >= 13.0.1 and only LLVM >= 14 supports version 5. - Note that Fiji is only suppored with LLVM <= 17 as version 3 i no longer + Note that Fiji is only suppored with LLVM <= 17 as version 3 is no longer supported in LLVM >= 18. */ #define ABI_VERSION_SPEC "march=fiji:--amdhsa-code-object-version=3;" \ "!march=*|march=*:--amdhsa-code-object-version=4"
[gcc r14-9478] libstdc++: Add nodiscard in
https://gcc.gnu.org/g:df483ebd24689a3bebfae2089637a00eca0e5a12 commit r14-9478-gdf483ebd24689a3bebfae2089637a00eca0e5a12 Author: Jonathan Wakely Date: Mon Feb 26 13:17:13 2024 + libstdc++: Add nodiscard in Add the [[nodiscard]] attribute to several functions in . These all have no side effects and are only called for their return value (e.g. std::count) or produce a result that must not be discarded for correctness (e.g. std::remove). I was intending to add the attribute to a number of other functions like std::copy_if, std::unique_copy, std::set_union, and std::set_difference. I stopped when I noticed that MSVC doesn't use it on those functions, which I suspect is because they're often used with an insert iterator (e.g. std::back_insert_iterator). In that case it doesn't matter if you discard the result, because you have the container to tell you how many elements were copied to the output range. libstdc++-v3/ChangeLog: * include/bits/stl_algo.h (find_end, all_of, none_of, any_of) (find_if_not, is_partitioned, partition_point, remove) (remove_if, unique, lower_bound, upper_bound, equal_range) (binary_search, includes, is_sorted, is_sorted_until, minmax) (minmax_element, is_permutation, clamp, find_if, find_first_of) (adjacent_find, count, count_if, search, search_n, min_element) (max_element): Add nodiscard attribute. * include/bits/stl_algobase.h (min, max, lower_bound, equal) (lexicographical_compare, lexicographical_compare_three_way) (mismatch): Likewise. * include/bits/stl_heap.h (is_heap, is_heap_until): Likewise. * testsuite/25_algorithms/equal/debug/1_neg.cc: Add dg-warning. * testsuite/25_algorithms/equal/debug/2_neg.cc: Likewise. * testsuite/25_algorithms/equal/debug/3_neg.cc: Likewise. * testsuite/25_algorithms/find_first_of/concept_check_1.cc: Likewise. * testsuite/25_algorithms/is_permutation/2.cc: Likewise. * testsuite/25_algorithms/lexicographical_compare/71545.cc: Likewise. * testsuite/25_algorithms/lower_bound/33613.cc: Likewise. * testsuite/25_algorithms/lower_bound/debug/irreflexive.cc: Likewise. * testsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc: Likewise. * testsuite/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc: Likewise. * testsuite/25_algorithms/minmax/3.cc: Likewise. * testsuite/25_algorithms/search/78346.cc: Likewise. * testsuite/25_algorithms/search_n/58358.cc: Likewise. * testsuite/25_algorithms/unique/1.cc: Likewise. * testsuite/25_algorithms/unique/11480.cc: Likewise. * testsuite/25_algorithms/upper_bound/33613.cc: Likewise. * testsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc: Likewise. * testsuite/25_algorithms/upper_bound/debug/partitioned_pred_neg.cc: Likewise. * testsuite/ext/concept_checks.cc: Likewise. * testsuite/ext/is_heap/47709.cc: Likewise. * testsuite/ext/is_sorted/cxx0x.cc: Likewise. Diff: --- libstdc++-v3/include/bits/stl_algo.h | 102 ++--- libstdc++-v3/include/bits/stl_algobase.h | 32 +++ libstdc++-v3/include/bits/stl_heap.h | 8 +- .../testsuite/25_algorithms/equal/debug/1_neg.cc | 1 + .../testsuite/25_algorithms/equal/debug/2_neg.cc | 1 + .../testsuite/25_algorithms/equal/debug/3_neg.cc | 1 + .../25_algorithms/find_first_of/concept_check_1.cc | 1 + .../testsuite/25_algorithms/is_permutation/2.cc| 1 + .../25_algorithms/lexicographical_compare/71545.cc | 1 + .../testsuite/25_algorithms/lower_bound/33613.cc | 1 + .../25_algorithms/lower_bound/debug/irreflexive.cc | 1 + .../lower_bound/debug/partitioned_neg.cc | 1 + .../lower_bound/debug/partitioned_pred_neg.cc | 1 + libstdc++-v3/testsuite/25_algorithms/minmax/3.cc | 1 + .../testsuite/25_algorithms/search/78346.cc| 1 + .../testsuite/25_algorithms/search_n/58358.cc | 1 + libstdc++-v3/testsuite/25_algorithms/unique/1.cc | 1 + .../testsuite/25_algorithms/unique/11480.cc| 2 +- .../testsuite/25_algorithms/upper_bound/33613.cc | 1 + .../upper_bound/debug/partitioned_neg.cc | 1 + .../upper_bound/debug/partitioned_pred_neg.cc | 1 + libstdc++-v3/testsuite/ext/concept_checks.cc | 4 + libstdc++-v3/testsuite/ext/is_heap/47709.cc| 1 + libstdc++-v3/testsuite/ext/is_sorted/cxx0x.cc | 1 + 24 files changed, 95 insertions(+), 72 deletions(-) diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index 7a0cf6b673
[gcc r14-9479] libstdc++: Fix std::format("{}", negative_integer) [PR114325]
https://gcc.gnu.org/g:f89cfdb2f2e9b4fe517b1e00511c4d70a7014cbc commit r14-9479-gf89cfdb2f2e9b4fe517b1e00511c4d70a7014cbc Author: Jonathan Wakely Date: Wed Mar 13 21:19:54 2024 + libstdc++: Fix std::format("{}", negative_integer) [PR114325] The fast path for "{}" format strings has a bug for negative integers where the length passed to std::to_chars is too long. libstdc++-v3/ChangeLog: PR libstdc++/114325 * include/std/format (_Scanner::_M_scan): Pass correct length to __to_chars_10_impl. * testsuite/std/format/functions/format.cc: Check negative integers with empty format-spec. Diff: --- libstdc++-v3/include/std/format | 7 --- libstdc++-v3/testsuite/std/format/functions/format.cc | 5 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format index 1e839e88db4..613016d1a10 100644 --- a/libstdc++-v3/include/std/format +++ b/libstdc++-v3/include/std/format @@ -4091,6 +4091,7 @@ namespace __format __sink_out = __sink.out(); if constexpr (is_same_v<_CharT, char>) + // Fast path for "{}" format strings and simple format arg types. if (__fmt.size() == 2 && __fmt[0] == '{' && __fmt[1] == '}') { bool __done = false; @@ -4124,14 +4125,14 @@ namespace __format __uval = make_unsigned_t<_Tp>(~__arg) + 1u; else __uval = __arg; - const auto __n = __detail::__to_chars_len(__uval) + __neg; - if (auto __res = __sink_out._M_reserve(__n)) + const auto __n = __detail::__to_chars_len(__uval); + if (auto __res = __sink_out._M_reserve(__n + __neg)) { auto __ptr = __res.get(); *__ptr = '-'; __detail::__to_chars_10_impl(__ptr + (int)__neg, __n, __uval); - __res._M_bump(__n); + __res._M_bump(__n + __neg); __done = true; } } diff --git a/libstdc++-v3/testsuite/std/format/functions/format.cc b/libstdc++-v3/testsuite/std/format/functions/format.cc index a27fbe74631..4499397aaf9 100644 --- a/libstdc++-v3/testsuite/std/format/functions/format.cc +++ b/libstdc++-v3/testsuite/std/format/functions/format.cc @@ -157,6 +157,11 @@ test_std_examples() // Restore std::locale::global(std::locale::classic()); + +string s5 = format("{}", -100); // PR libstdc++/114325 +VERIFY(s5 == "-100"); +string s6 = format("{:d} {:d}", -123, 999); +VERIFY(s6 == "-123 999"); } }
[gcc r14-9480] gcc: xtensa: reorder movsi_internal patterns for better code generation during LRA
https://gcc.gnu.org/g:bc5a9dab55d13f888a3cdd150c8cf5c2244f35e0 commit r14-9480-gbc5a9dab55d13f888a3cdd150c8cf5c2244f35e0 Author: Max Filippov Date: Thu Mar 14 04:20:36 2024 -0700 gcc: xtensa: reorder movsi_internal patterns for better code generation during LRA After switching to LRA xtensa backend generates the following code for saving/loading registers: movi a9, 0x190 add a9, a9, sp s32i.n a3, a9, 0 instead of the shorter and more efficient s32i a3, a9, 0x190 E.g. the following code can be used to reproduce it: int f1(int a, int b, int c, int d, int e, int f, int *p); int f2(int a, int b, int c, int d, int e, int f, int *p); int f3(int a, int b, int c, int d, int e, int f, int *p); int foo(int a, int b, int c, int d, int e, int f) { int g[100]; return f1(a, b, c, d, e, f, g) + f2(a, b, c, d, e, f, g) + f3(a, b, c, d, e, f, g); } This happens in the LRA pass because s32i.n and l32i.n are listed before the s32i and l32i in the movsi_internal pattern and alternative consideration loop stops early. gcc/ * config/xtensa/xtensa.md (movsi_internal): Move l32i and s32i patterns ahead of the l32i.n and s32i.n. Diff: --- gcc/config/xtensa/xtensa.md | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md index 1a2249b059a..5cdf4dffe70 100644 --- a/gcc/config/xtensa/xtensa.md +++ b/gcc/config/xtensa/xtensa.md @@ -1270,13 +1270,15 @@ }) (define_insn "movsi_internal" - [(set (match_operand:SI 0 "nonimmed_operand" "=D,D,D,D,R,R,a,q,a,a,W,a,a,U,*a,*A") - (match_operand:SI 1 "move_operand" "M,D,d,R,D,d,r,r,I,Y,i,T,U,r,*A,*r"))] + [(set (match_operand:SI 0 "nonimmed_operand" "=D,D,D,a,U,D,R,R,a,q,a,a,W,a,*a,*A") + (match_operand:SI 1 "move_operand" "M,D,d,U,r,R,D,d,r,r,I,Y,i,T,*A,*r"))] "xtensa_valid_move (SImode, operands)" "@ movi.n\t%0, %x1 mov.n\t%0, %1 mov.n\t%0, %1 + %v1l32i\t%0, %1 + %v0s32i\t%1, %0 %v1l32i.n\t%0, %1 %v0s32i.n\t%1, %0 %v0s32i.n\t%1, %0 @@ -1286,13 +1288,11 @@ movi\t%0, %1 const16\t%0, %t1\;const16\t%0, %b1 %v1l32r\t%0, %1 - %v1l32i\t%0, %1 - %v0s32i\t%1, %0 rsr\t%0, ACCLO wsr\t%1, ACCLO" - [(set_attr "type" "move,move,move,load,store,store,move,move,move,move,move,load,load,store,rsr,wsr") + [(set_attr "type" "move,move,move,load,store,load,store,store,move,move,move,move,move,load,rsr,wsr") (set_attr "mode""SI") - (set_attr "length" "2,2,2,2,2,2,3,3,3,3,6,3,3,3,3,3")]) + (set_attr "length" "2,2,2,3,3,2,2,2,3,3,3,3,6,3,3,3")]) (define_split [(set (match_operand:SHI 0 "register_operand")
[gcc r14-9481] bpf: define INT8_TYPE as signed char
https://gcc.gnu.org/g:6cf4286ff9456685a29812a3560d00b956d62c39 commit r14-9481-g6cf4286ff9456685a29812a3560d00b956d62c39 Author: David Faust Date: Thu Mar 14 09:05:38 2024 -0700 bpf: define INT8_TYPE as signed char Change the BPF backend to define INT8_TYPE with an explicit sign, rather than a plain char. This is in line with other targets and removes the risk of int8_t being affected by the signedness of the plain char type of the host system. The motivation for this change is that even if `char' is defined to be signed in BPF targets, some BPF programs use the (mal)practice of including internal libc headers, either directly or indirectly via kernel headers, which in turn may trigger compilation errors regarding redefinitions of types. gcc/ * config/bpf/bpf.h (INT8_TYPE): Change to signed char. Diff: --- gcc/config/bpf/bpf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/config/bpf/bpf.h b/gcc/config/bpf/bpf.h index f107a5a4c34..3cc5daa1b58 100644 --- a/gcc/config/bpf/bpf.h +++ b/gcc/config/bpf/bpf.h @@ -99,7 +99,7 @@ #define SIG_ATOMIC_TYPE "char" -#define INT8_TYPE "char" +#define INT8_TYPE "signed char" #define INT16_TYPE "short int" #define INT32_TYPE "int" #define INT64_TYPE "long int"
[gcc r14-9482] hppa: Fix REG+D address support before reload
https://gcc.gnu.org/g:53fd0f5b1fd737a208c12909fa1188281cb370a3 commit r14-9482-g53fd0f5b1fd737a208c12909fa1188281cb370a3 Author: John David Anglin Date: Thu Mar 14 18:32:56 2024 + hppa: Fix REG+D address support before reload When generating PA 1.x code or code for GNU ld, floating-point accesses only support 5-bit displacements but integer accesses support 14-bit displacements. I mistakenly assumed reload could fix an invalid 14-bit displacement in a floating-point access but this is not the case. 2024-03-14 John David Anglin gcc/ChangeLog: PR target/114288 * config/pa/pa.cc (pa_legitimate_address_p): Don't allow 14-bit displacements before reload for modes that may use a floating-point load or store. Diff: --- gcc/config/pa/pa.cc | 15 +-- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/gcc/config/pa/pa.cc b/gcc/config/pa/pa.cc index 694123e37c9..129289f8e62 100644 --- a/gcc/config/pa/pa.cc +++ b/gcc/config/pa/pa.cc @@ -10968,20 +10968,15 @@ pa_legitimate_address_p (machine_mode mode, rtx x, bool strict, code_helper) /* Long 14-bit displacements always okay for these cases. */ if (INT14_OK_STRICT + || reload_completed || mode == QImode || mode == HImode) return true; - /* A secondary reload may be needed to adjust the displacement -of floating-point accesses when STRICT is nonzero. */ - if (strict) - return false; - - /* We get significantly better code if we allow long displacements -before reload for all accesses. Instructions must satisfy their -constraints after reload, so we must have an integer access. -Return true for both cases. */ - return true; + /* We have to limit displacements to those supported by +both floating-point and integer accesses as reload can't +fix invalid displacements. See PR114288. */ + return false; } if (!TARGET_DISABLE_INDEXING
[gcc r14-9483] PR modula2/114294 expression causes ICE
https://gcc.gnu.org/g:6dbf0d252f69ab2924256e6778ba7dc55d5b6915 commit r14-9483-g6dbf0d252f69ab2924256e6778ba7dc55d5b6915 Author: Gaius Mulley Date: Thu Mar 14 19:09:34 2024 + PR modula2/114294 expression causes ICE This patch fixes an ICE when encountering an expression: 1 + HIGH (a[0]). The fix was to assign a type to the constant created by BuildConstHighFromSym in M2Quads.mod. gcc/m2/ChangeLog: PR modula2/114294 * gm2-compiler/M2Quads.mod (BuildConstHighFromSym): Call PutConst to assign the type Cardinal in the result constant. gcc/testsuite/ChangeLog: PR modula2/114294 * gm2/pim/pass/log: Removed. * gm2/pim/pass/highexp.mod: New test. Signed-off-by: Gaius Mulley Diff: --- gcc/m2/gm2-compiler/M2Quads.mod| 1 + gcc/testsuite/gm2/pim/pass/highexp.mod | 9 + gcc/testsuite/gm2/pim/pass/log | 457 - 3 files changed, 10 insertions(+), 457 deletions(-) diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod index 0263074d845..1776a09b41f 100644 --- a/gcc/m2/gm2-compiler/M2Quads.mod +++ b/gcc/m2/gm2-compiler/M2Quads.mod @@ -8400,6 +8400,7 @@ VAR BEGIN PopT (NoOfParam) ; ReturnVar := MakeTemporary (tok, ImmediateValue) ; + PutConst (ReturnVar, Cardinal) ; GenHigh (tok, ReturnVar, 1, OperandT (1)) ; PopN (NoOfParam+1) ; PushTtok (ReturnVar, tok) diff --git a/gcc/testsuite/gm2/pim/pass/highexp.mod b/gcc/testsuite/gm2/pim/pass/highexp.mod new file mode 100644 index 000..f98be7df331 --- /dev/null +++ b/gcc/testsuite/gm2/pim/pass/highexp.mod @@ -0,0 +1,9 @@ +MODULE highexp ; + + +VAR + a: ARRAY [0..9] OF CHAR ; + c: CARDINAL ; +BEGIN + c := 1 + HIGH (a) +END highexp. diff --git a/gcc/testsuite/gm2/pim/pass/log b/gcc/testsuite/gm2/pim/pass/log deleted file mode 100644 index 5bbdc50ab6e..000 --- a/gcc/testsuite/gm2/pim/pass/log +++ /dev/null @@ -1,457 +0,0 @@ -= -Stabs setchar3 -GNU gdb 6.3 -Copyright (C) 2004-2024 Free Software Foundation, Inc. -GDB is free software, covered by the GNU General Public License, and you are -welcome to change it and/or distribute copies of it under certain conditions. -Type "show copying" to see the conditions. -There is absolutely no warranty for GDB. Type "show warranty" for details. -This GDB was configured as "x86_64-unknown-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1". - -Breakpoint 1 at 0x421298: file setchar3.mod, line 30. - -Breakpoint 1, _M2_setchar3_init () at setchar3.mod:30 -30ch := 'z' ; -31s := smallchar{} ; -$1 = {} -type = SET ['A'..'Z'] -= -Dwarf2 setchar3 -GNU gdb 6.3 -Copyright (C) 2004-2024 Free Software Foundation, Inc. -GDB is free software, covered by the GNU General Public License, and you are -welcome to change it and/or distribute copies of it under certain conditions. -Type "show copying" to see the conditions. -There is absolutely no warranty for GDB. Type "show warranty" for details. -This GDB was configured as "x86_64-unknown-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1". - -Breakpoint 1 at 0x421298: file setchar3.mod, line 30. - -Breakpoint 1, _M2_setchar3_init () at setchar3.mod:30 -30ch := 'z' ; -31s := smallchar{} ; -$1 = {} -type = SET ['A'..'Z'] -= -Stabs subrange15 -GNU gdb 6.3 -Copyright (C) 2004-2024 Free Software Foundation, Inc. -GDB is free software, covered by the GNU General Public License, and you are -welcome to change it and/or distribute copies of it under certain conditions. -Type "show copying" to see the conditions. -There is absolutely no warranty for GDB. Type "show warranty" for details. -This GDB was configured as "x86_64-unknown-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1". - -Breakpoint 1 at 0x421298: file subrange15.mod, line 8. - -Breakpoint 1, _M2_subrange15_init () at subrange15.mod:8 -8 s := 20 ; -9 s := 21 ; -$1 = 20 -type = [20..40] -= -Dwarf2 subrange15 -GNU gdb 6.3 -Copyright (C) 2004-2024 Free Software Foundation, Inc. -GDB is free software, covered by the GNU General Public License, and you are -welcome to change it and/or distribute copies of it under certain conditions. -Type "show copying" to see the conditions. -There is absolutely no warranty for GDB. Type "show warranty" for details. -This GDB was configured as "x86_64-unknown-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1". - -Breakpoint 1 at 0x421298: file subrange15.mod, line 8. - -Breakpoint 1, _M2_subrange15_init () at subrange15.mod:8 -8 s := 20 ; -9 s := 21 ; -$1 = 20 -type = [20..40] -
[gcc r14-9484] tree-core: clarify clobber comments
https://gcc.gnu.org/g:efab8c1b692ab080bcee99a6ef7ba6ee43ed commit r14-9484-gefab8c1b692ab080bcee99a6ef7ba6ee43ed Author: Jason Merrill Date: Thu Feb 22 10:06:27 2024 + tree-core: clarify clobber comments It came up on the mailing list that OBJECT_BEGIN/END are described as marking object lifetime, but mark the beginning of the constructor and end of the destructor, whereas the C++ notion of lifetime is between the end of the constructor and beginning of the destructor. So let's fix the comments. gcc/ChangeLog: * tree-core.h (enum clobber_kind): Clarify CLOBBER_OBJECT_* comments. Diff: --- gcc/tree-core.h | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gcc/tree-core.h b/gcc/tree-core.h index d529712306d..a74fbdf75b4 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -993,9 +993,11 @@ enum clobber_kind { CLOBBER_UNDEF, /* Beginning of storage duration, e.g. malloc. */ CLOBBER_STORAGE_BEGIN, - /* Beginning of object lifetime, e.g. C++ constructor. */ + /* Beginning of object data, e.g. start of C++ constructor. This differs + from C++ 'lifetime', which starts when initialization is complete; a + clobber there would discard the initialization. */ CLOBBER_OBJECT_BEGIN, - /* End of object lifetime, e.g. C++ destructor. */ + /* End of object data, e.g. end of C++ destructor. */ CLOBBER_OBJECT_END, /* End of storage duration, e.g. free. */ CLOBBER_STORAGE_END,
[gcc r14-9486] LoongArch: Remove masking process for operand 3 of xvpermi.q.
https://gcc.gnu.org/g:d7d05824ae68da24908d97a10b9ec59d08f75a90 commit r14-9486-gd7d05824ae68da24908d97a10b9ec59d08f75a90 Author: Chenghui Pan Date: Thu Mar 14 09:26:54 2024 +0800 LoongArch: Remove masking process for operand 3 of xvpermi.q. The behavior of non-zero unused bits in xvpermi.q instruction's third operand is undefined on LoongArch, according to our discussion (https://github.com/llvm/llvm-project/pull/83540), we think that keeping original insn operand as unmodified state is better solution. This patch partially reverts 7b158e036a95b1ab40793dd53bed7dbd770ffdaf. gcc/ChangeLog: * config/loongarch/lasx.md (lasx_xvpermi_q_): Remove masking of operand 3. gcc/testsuite/ChangeLog: * gcc.target/loongarch/vector/lasx/lasx-xvpermi_q.c: Reposition operand 3's value into instruction's defined accept range. Diff: --- gcc/config/loongarch/lasx.md| 5 - gcc/testsuite/gcc.target/loongarch/vector/lasx/lasx-xvpermi_q.c | 6 +++--- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/gcc/config/loongarch/lasx.md b/gcc/config/loongarch/lasx.md index ac84db7f0ce..3f25c0c1756 100644 --- a/gcc/config/loongarch/lasx.md +++ b/gcc/config/loongarch/lasx.md @@ -640,8 +640,6 @@ (set_attr "mode" "")]) ;; xvpermi.q -;; Unused bits in operands[3] need be set to 0 to avoid -;; causing undefined behavior on LA464. (define_insn "lasx_xvpermi_q_" [(set (match_operand:LASX 0 "register_operand" "=f") (unspec:LASX @@ -651,9 +649,6 @@ UNSPEC_LASX_XVPERMI_Q))] "ISA_HAS_LASX" { - int mask = 0x33; - mask &= INTVAL (operands[3]); - operands[3] = GEN_INT (mask); return "xvpermi.q\t%u0,%u2,%3"; } [(set_attr "type" "simd_splat") diff --git a/gcc/testsuite/gcc.target/loongarch/vector/lasx/lasx-xvpermi_q.c b/gcc/testsuite/gcc.target/loongarch/vector/lasx/lasx-xvpermi_q.c index dbc29d2fb22..f89dfc31120 100644 --- a/gcc/testsuite/gcc.target/loongarch/vector/lasx/lasx-xvpermi_q.c +++ b/gcc/testsuite/gcc.target/loongarch/vector/lasx/lasx-xvpermi_q.c @@ -27,7 +27,7 @@ main () *((unsigned long*)& __m256i_result[2]) = 0x7fff7fff7fff; *((unsigned long*)& __m256i_result[1]) = 0x7fe37fe3001d001d; *((unsigned long*)& __m256i_result[0]) = 0x7fff7fff7fff; - __m256i_out = __lasx_xvpermi_q (__m256i_op0, __m256i_op1, 0x2a); + __m256i_out = __lasx_xvpermi_q (__m256i_op0, __m256i_op1, 0x22); ASSERTEQ_64 (__LINE__, __m256i_result, __m256i_out); *((unsigned long*)& __m256i_op0[3]) = 0x; @@ -42,7 +42,7 @@ main () *((unsigned long*)& __m256i_result[2]) = 0x0019001c; *((unsigned long*)& __m256i_result[1]) = 0x; *((unsigned long*)& __m256i_result[0]) = 0x01fe; - __m256i_out = __lasx_xvpermi_q (__m256i_op0, __m256i_op1, 0xb9); + __m256i_out = __lasx_xvpermi_q (__m256i_op0, __m256i_op1, 0x31); ASSERTEQ_64 (__LINE__, __m256i_result, __m256i_out); *((unsigned long*)& __m256i_op0[3]) = 0x00ff00ff00ff00ff; @@ -57,7 +57,7 @@ main () *((unsigned long*)& __m256i_result[2]) = 0x; *((unsigned long*)& __m256i_result[1]) = 0x00ff00ff00ff00ff; *((unsigned long*)& __m256i_result[0]) = 0x00ff00ff00ff00ff; - __m256i_out = __lasx_xvpermi_q (__m256i_op0, __m256i_op1, 0xca); + __m256i_out = __lasx_xvpermi_q (__m256i_op0, __m256i_op1, 0x02); ASSERTEQ_64 (__LINE__, __m256i_result, __m256i_out); return 0;
[gcc r14-9487] vect: Call vect_convert_output with the right vecitype [PR114108]
https://gcc.gnu.org/g:81f3d963e05de8b17d4ccc7667ead9ed156193a4 commit r14-9487-g81f3d963e05de8b17d4ccc7667ead9ed156193a4 Author: Tejas Belagod Date: Wed Mar 6 15:30:26 2024 +0530 vect: Call vect_convert_output with the right vecitype [PR114108] This patch fixes a bug where vect_recog_abd_pattern called vect_convert_output with the incorrect vecitype for the corresponding pattern_stmt. vect_convert_output expects vecitype to be the vector form of the scalar type of the LHS of pattern_stmt, but we were passing in the vector form of the LHS of the new impending conversion statement. This caused a skew in ABD's pattern_stmt having the vectype of the following gimple pattern_stmt. 2024-03-06 Tejas Belagod gcc/ChangeLog: PR middle-end/114108 * tree-vect-patterns.cc (vect_recog_abd_pattern): Call vect_convert_output with the correct vecitype. gcc/testsuite/ChangeLog: * gcc.dg/vect/pr114108.c: New test. Diff: --- gcc/testsuite/gcc.dg/vect/pr114108.c | 19 +++ gcc/tree-vect-patterns.cc| 5 ++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/gcc.dg/vect/pr114108.c b/gcc/testsuite/gcc.dg/vect/pr114108.c new file mode 100644 index 000..b3075d41398 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr114108.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ + +#include "tree-vect.h" + +typedef signed char schar; + +__attribute__((noipa, noinline, optimize("O3"))) +void foo(const schar *a, const schar *b, schar *c, int n) +{ + for (int i = 0; i < n; i++) +{ + unsigned u = __builtin_abs (a[i] - b[i]); + c[i] = u <= 7U ? u : 7U; +} +} + + +/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" { target aarch64*-*-* } } } */ +/* { dg-final { scan-tree-dump "vect_recog_abd_pattern: detected" "vect" { target aarch64*-*-* } } } */ diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc index d562f57920f..4f491c6b833 100644 --- a/gcc/tree-vect-patterns.cc +++ b/gcc/tree-vect-patterns.cc @@ -1576,9 +1576,8 @@ vect_recog_abd_pattern (vec_info *vinfo, && !TYPE_UNSIGNED (abd_out_type)) { tree unsign = unsigned_type_for (abd_out_type); - tree unsign_vectype = get_vectype_for_scalar_type (vinfo, unsign); - stmt = vect_convert_output (vinfo, stmt_vinfo, unsign, stmt, - unsign_vectype); + stmt = vect_convert_output (vinfo, stmt_vinfo, unsign, stmt, vectype_out); + vectype_out = get_vectype_for_scalar_type (vinfo, unsign); } return vect_convert_output (vinfo, stmt_vinfo, out_type, stmt, vectype_out);
[gcc r14-9488] MIPS: Add -m(no-)strict-align option
https://gcc.gnu.org/g:acc38ff59976e972ba4b1e39f7653813a05de588 commit r14-9488-gacc38ff59976e972ba4b1e39f7653813a05de588 Author: YunQiang Su Date: Fri Mar 15 14:33:58 2024 +0800 MIPS: Add -m(no-)strict-align option We support options -m(no-)unaligned-access 2 years ago, while currently most of other ports prefer -m(no-)strict-align. Let's support -m(no-)strict-align, and keep -m(no-)unaligned-access as alias. gcc * config/mips/mips.opt: Support -mstrict-align, and use TARGET_STRICT_ALIGN as the flag; keep -m(no-)unaligned-access as alias. * config/mips/mips.h: Use TARGET_STRICT_ALIGN. * config/mips/mips.opt.urls: Regenerate. * doc/invoke.texi: Document -m(no-)strict-algin for MIPSr6. Diff: --- gcc/config/mips/mips.h| 2 +- gcc/config/mips/mips.opt | 12 ++-- gcc/config/mips/mips.opt.urls | 6 ++ gcc/doc/invoke.texi | 18 -- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h index 7145d23c650..6444a68dfd5 100644 --- a/gcc/config/mips/mips.h +++ b/gcc/config/mips/mips.h @@ -251,7 +251,7 @@ struct mips_cpu_info { || ISA_HAS_MSA)) /* ISA load/store instructions can handle unaligned address */ -#define ISA_HAS_UNALIGNED_ACCESS (TARGET_UNALIGNED_ACCESS \ +#define ISA_HAS_UNALIGNED_ACCESS (!TARGET_STRICT_ALIGN \ && (mips_isa_rev >= 6)) /* The ISA compression flags that are currently in effect. */ diff --git a/gcc/config/mips/mips.opt b/gcc/config/mips/mips.opt index ce36942aabe..c1abb36212f 100644 --- a/gcc/config/mips/mips.opt +++ b/gcc/config/mips/mips.opt @@ -429,9 +429,17 @@ mtune= Target RejectNegative Joined Var(mips_tune_option) ToLower Enum(mips_arch_opt_value) -mtune=PROCESSOR Optimize the output for PROCESSOR. +mstrict-align +Target Var(TARGET_STRICT_ALIGN) Init(0) +Don't generate code with unaligned load store, only valid for MIPS R6. + munaligned-access -Target Var(TARGET_UNALIGNED_ACCESS) Init(1) -Generate code with unaligned load store, valid for MIPS R6. +Target RejectNegative Alias(mstrict-align) NegativeAlias +Generate code with unaligned load store for R6 (alias of -mno-strict-align). + +mno-unaligned-access +Target RejectNegative Alias(mstrict-align) +Don't generate code with unaligned load store for R6 (alias of -mstrict-align). muninit-const-in-rodata Target Var(TARGET_UNINIT_CONST_IN_RODATA) diff --git a/gcc/config/mips/mips.opt.urls b/gcc/config/mips/mips.opt.urls index 96aba041026..9d166646d65 100644 --- a/gcc/config/mips/mips.opt.urls +++ b/gcc/config/mips/mips.opt.urls @@ -233,9 +233,15 @@ UrlSuffix(gcc/MIPS-Options.html#index-mmadd4) mtune= UrlSuffix(gcc/MIPS-Options.html#index-mtune-10) +mstrict-align +UrlSuffix(gcc/MIPS-Options.html#index-mstrict-align-3) + munaligned-access UrlSuffix(gcc/MIPS-Options.html#index-munaligned-access-1) +mno-unaligned-access +UrlSuffix(gcc/MIPS-Options.html#index-mno-unaligned-access-1) + muninit-const-in-rodata UrlSuffix(gcc/MIPS-Options.html#index-muninit-const-in-rodata) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 85c938d4a14..864768fd2f4 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1143,7 +1143,8 @@ Objective-C and Objective-C++ Dialects}. -mcheck-zero-division -mno-check-zero-division -mdivide-traps -mdivide-breaks -mload-store-pairs -mno-load-store-pairs --munaligned-access -mno-unaligned-access +-mstrict-align -mno-strict-align +-mno-unaligned-access -munaligned-access -mmemcpy -mno-memcpy -mlong-calls -mno-long-calls -mmad -mno-mad -mimadd -mno-imadd -mfused-madd -mno-fused-madd -nocpp -mfix-24k -mno-fix-24k @@ -28561,14 +28562,19 @@ instructions to enable load/store bonding. This option is enabled by default but only takes effect when the selected architecture is known to support bonding. +@opindex mstrict-align +@opindex mno-strict-align @opindex munaligned-access @opindex mno-unaligned-access -@item -munaligned-access +@item -mstrict-align +@itemx -mno-strict-align +@itemx -munaligned-access @itemx -mno-unaligned-access -Enable (disable) direct unaligned access for MIPS Release 6. -MIPSr6 requires load/store unaligned-access support, -by hardware or trap&emulate. -So @option{-mno-unaligned-access} may be needed by kernel. +Disable (enable) direct unaligned access for MIPS Release 6. +MIPSr6 requires load/store unaligned-access support, by hardware or +trap&emulate. So @option{-mstrict-align} may be needed by kernel. The +options @option{-munaligned-access} and @option{-mno-unaligned-access} +are obsoleted, and only for backward-compatible. @opindex mmemcpy @opindex mno-memcpy
[gcc r14-9489] Fortran: Fix class/derived/complex function associate selectors [PR87477]
https://gcc.gnu.org/g:3fd46d859cda1074125449a4cc680ce59fcebc38 commit r14-9489-g3fd46d859cda1074125449a4cc680ce59fcebc38 Author: Paul Thomas Date: Fri Mar 15 06:52:59 2024 + Fortran: Fix class/derived/complex function associate selectors [PR87477] 2024-03-15 Paul Thomas gcc/fortran PR fortran/87477 PR fortran/89645 PR fortran/99065 PR fortran/114141 PR fortran/114280 * class.cc (gfc_change_class): New function needed for associate names, when rank changes or a derived type is produced by resolution * dump-parse-tree.cc (show_code_node): Make output for SELECT TYPE more comprehensible. * expr.cc (find_inquiry_ref): Do not simplify expressions of an inferred type. * gfortran.h : Add 'gfc_association_list' to structure 'gfc_association_list'. Add prototypes for 'gfc_find_derived_types', 'gfc_fixup_inferred_type_refs' and 'gfc_change_class'. Add macro IS_INFERRED_TYPE. * match.cc (copy_ts_from_selector_to_associate): Add bolean arg 'select_type' with default false. If this is a select type name and the selector is a inferred type, build the class type and apply it to the associate name. (build_associate_name): Pass true to 'select_type' in call to previous. * parse.cc (parse_associate): If the selector is inferred type the associate name is too. Make sure that function selector class and rank, if known, are passed to the associate name. If a function result exists, pass its typespec to the associate name. * primary.cc (resolvable_fcns): New function to check that all the function references are resolvable. (gfc_match_varspec): If a scalar derived type select type temporary has an array reference, match the array reference, treating this in the same way as an equivalence member. Do not set 'inquiry' if applied to an unknown type the inquiry name is ambiguous with the component of an accessible derived type. Check that resolution of the target expression is OK by testing if the symbol is declared or is an operator expression, then using 'resolvable_fcns' recursively. If all is well, resolve the expression. If this is an inferred type with a component reference, call 'gfc_find_derived_types' to find a suitable derived type. If there is an inquiry ref and the symbol either is of unknown type or is inferred to be a derived type, set the primary and symbol TKR appropriately. * resolve.cc (resolve_variable): Call new function below. (gfc_fixup_inferred_type_refs): New function to ensure that the expression references for a inferred type are consistent with the now fixed up selector. (resolve_assoc_var): Ensure that derived type or class function selectors transmit the correct arrayspec to the associate name. (resolve_select_type): If the selector is an associate name of inferred type and has no component references, the associate name should have its typespec. Simplify the conversion of a class array to class scalar by calling 'gfc_change_class'. Make sure that a class, inferred type selector with an array ref transfers the typespec from the symbol to the expression. * symbol.cc (gfc_set_default_type): If an associate name with unknown type has a selector expression, try resolving the expr. (find_derived_types, gfc_find_derived_types): New functions that search for a derived type with a given name. * trans-expr.cc (gfc_conv_variable): Some inferred type exprs escape resolution so call 'gfc_fixup_inferred_type_refs'. * trans-stmt.cc (trans_associate_var): Tidy up expression for 'class_target'. Finalize and free class function results. Correctly handle selectors that are class functions and class array references, passed as derived types. gcc/testsuite/ PR fortran/87477 PR fortran/89645 PR fortran/99065 * gfortran.dg/associate_64.f90 : New test * gfortran.dg/associate_66.f90 : New test * gfortran.dg/associate_67.f90 : New test PR fortran/114141 * gfortran.dg/associate_65.f90 : New test PR fortran/114280 * gfortran.dg/associate_68.f90 : New test Diff: --- gcc/fortran/class.cc | 50 + gcc/fortran/dump-parse-tree.cc | 17 +- gcc/fortran/expr.cc