[gcc r15-7786] PR modula2/119088 ICE when for loop accesses an unknown variable as the iterator
https://gcc.gnu.org/g:585aa4065f1028c2fbfab55462e5e5e6b3c208c4 commit r15-7786-g585aa4065f1028c2fbfab55462e5e5e6b3c208c4 Author: Gaius Mulley Date: Sun Mar 2 19:04:37 2025 + PR modula2/119088 ICE when for loop accesses an unknown variable as the iterator This patch fixes an ICE which occurs when a FOR statement attempts to use an undeclared variable as its iterator. gcc/m2/ChangeLog: PR modula2/119088 * gm2-compiler/M2SymInit.mod (ConfigSymInit): Reimplement to defensively check for NulSym type. gcc/testsuite/ChangeLog: PR modula2/119088 * gm2/pim/fail/tinyfor4.mod: New test. Signed-off-by: Gaius Mulley Diff: --- gcc/m2/gm2-compiler/M2SymInit.mod | 21 ++--- gcc/testsuite/gm2/pim/fail/tinyfor4.mod | 7 +++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/gcc/m2/gm2-compiler/M2SymInit.mod b/gcc/m2/gm2-compiler/M2SymInit.mod index ffe1f9b8da33..6c8912f2c4c0 100644 --- a/gcc/m2/gm2-compiler/M2SymInit.mod +++ b/gcc/m2/gm2-compiler/M2SymInit.mod @@ -202,16 +202,23 @@ BEGIN desc^.sym := sym ; desc^.type := GetSType (sym) ; desc^.initialized := FALSE ; - IF IsRecord (desc^.type) + (* An unknown symbol will have no type. *) + IF desc^.type = NulSym THEN - desc^.kind := record ; - desc^.rec.fieldDesc := Indexing.InitIndex (1) ; - PopulateFields (desc, desc^.type) - ELSE desc^.kind := scalar ; - IF IsArray (desc^.type) + desc^.initialized := TRUE (* For now we don't attempt to handle array types. *) + ELSE + IF IsRecord (desc^.type) THEN -desc^.initialized := TRUE (* For now we don't attempt to handle array types. *) +desc^.kind := record ; +desc^.rec.fieldDesc := Indexing.InitIndex (1) ; +PopulateFields (desc, desc^.type) + ELSE +desc^.kind := scalar ; +IF IsArray (desc^.type) +THEN + desc^.initialized := TRUE (* For now we don't attempt to handle array types. *) +END END END END diff --git a/gcc/testsuite/gm2/pim/fail/tinyfor4.mod b/gcc/testsuite/gm2/pim/fail/tinyfor4.mod new file mode 100644 index ..155b72565da0 --- /dev/null +++ b/gcc/testsuite/gm2/pim/fail/tinyfor4.mod @@ -0,0 +1,7 @@ +MODULE tinyfor4 ; + +VAR + v: INTEGER; +BEGIN + FOR i := 0 TO v DO END +END tinyfor4.
[gcc r14-11371] [PR target/116720] Fix test for valid mempair operands
https://gcc.gnu.org/g:c1535f242f703d3142bef1ca7c31d1ee17633696 commit r14-11371-gc1535f242f703d3142bef1ca7c31d1ee17633696 Author: Jeff Law Date: Sun Dec 29 08:27:30 2024 -0700 [PR target/116720] Fix test for valid mempair operands So this BZ is a case where we incorrectly indicated that the operand array was suitable for the t-head load/store pair instructions. In particular there's a test which checks alignment, but that happens *before* we know if the operands are going to be reversed. So the routine reported the operands are suitable. At a later point the operands have been reversed into the proper order and we realize the alignment test should have failed, resulting in the unrecognized insn. This fixes the code by moving the reversal check earlier and actually swapping the local variables with the operands. That in turn allows for simpler testing of alignments, ordering, etc. I've tested this on rv32 and rv64 in my tester. I don't offhand know if the patch from Filip that's been causing headaches for the RISC-V port has been reverted/fixed. So there's a nonzero chance the pre-commit CI tester will fail. I'll keep an eye on it and act appropriately. PR target/116720 gcc/ * config/riscv/thead.cc (th_mempair_operands_p): Test for aligned memory after swapping operands. Simplify test for first memory access as well. gcc/testsuite/ * gcc.target/riscv/pr116720.c: New test. (cherry picked from commit 0b06abe027a78681d29a5e91daa74bf8dba39826) Diff: --- gcc/config/riscv/thead.cc | 20 ++-- gcc/testsuite/gcc.target/riscv/pr116720.c | 12 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/gcc/config/riscv/thead.cc b/gcc/config/riscv/thead.cc index 6f5edeb7e0ac..0be5e4aceb8b 100644 --- a/gcc/config/riscv/thead.cc +++ b/gcc/config/riscv/thead.cc @@ -285,19 +285,27 @@ th_mempair_operands_p (rtx operands[4], bool load_p, if (MEM_VOLATILE_P (mem_1) || MEM_VOLATILE_P (mem_2)) return false; - /* If we have slow unaligned access, we only accept aligned memory. */ - if (riscv_slow_unaligned_access_p - && known_lt (MEM_ALIGN (mem_1), GET_MODE_SIZE (mode) * BITS_PER_UNIT)) -return false; /* Check if the addresses are in the form of [base+offset]. */ bool reversed = false; if (!th_mempair_check_consecutive_mems (mode, &mem_1, &mem_2, &reversed)) return false; + /* If necessary, reverse the local copy of the operands to simplify + testing of alignments and mempair operand. */ + if (reversed) +{ + std::swap (mem_1, mem_2); + std::swap (reg_1, reg_2); +} + + /* If we have slow unaligned access, we only accept aligned memory. */ + if (riscv_slow_unaligned_access_p + && known_lt (MEM_ALIGN (mem_1), GET_MODE_SIZE (mode) * BITS_PER_UNIT)) +return false; + /* The first memory accesses must be a mempair operand. */ - if ((!reversed && !th_mempair_operand_p (mem_1, mode)) - || (reversed && !th_mempair_operand_p (mem_2, mode))) + if (!th_mempair_operand_p (mem_1, mode)) return false; /* The operands must be of the same size. */ diff --git a/gcc/testsuite/gcc.target/riscv/pr116720.c b/gcc/testsuite/gcc.target/riscv/pr116720.c new file mode 100644 index ..0f795aba0bf1 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr116720.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -march=rv32ixtheadmempair -mabi=ilp32 -mno-strict-align" } */ + +struct a { + signed : 22; +}; +volatile short b; +int *c; +void d(int e, struct a) { + b; + c = &e; +}
[gcc r13-9406] [PR target/116720] Fix test for valid mempair operands
https://gcc.gnu.org/g:e00c33df5d64990197b2382399a2a8b80b994176 commit r13-9406-ge00c33df5d64990197b2382399a2a8b80b994176 Author: Jeff Law Date: Sun Dec 29 08:27:30 2024 -0700 [PR target/116720] Fix test for valid mempair operands So this BZ is a case where we incorrectly indicated that the operand array was suitable for the t-head load/store pair instructions. In particular there's a test which checks alignment, but that happens *before* we know if the operands are going to be reversed. So the routine reported the operands are suitable. At a later point the operands have been reversed into the proper order and we realize the alignment test should have failed, resulting in the unrecognized insn. This fixes the code by moving the reversal check earlier and actually swapping the local variables with the operands. That in turn allows for simpler testing of alignments, ordering, etc. I've tested this on rv32 and rv64 in my tester. I don't offhand know if the patch from Filip that's been causing headaches for the RISC-V port has been reverted/fixed. So there's a nonzero chance the pre-commit CI tester will fail. I'll keep an eye on it and act appropriately. PR target/116720 gcc/ * config/riscv/thead.cc (th_mempair_operands_p): Test for aligned memory after swapping operands. Simplify test for first memory access as well. gcc/testsuite/ * gcc.target/riscv/pr116720.c: New test. Diff: --- gcc/config/riscv/thead.cc | 20 ++-- gcc/testsuite/gcc.target/riscv/pr116720.c | 12 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/gcc/config/riscv/thead.cc b/gcc/config/riscv/thead.cc index d7e3cf80d9b8..fbd276fe8d28 100644 --- a/gcc/config/riscv/thead.cc +++ b/gcc/config/riscv/thead.cc @@ -313,19 +313,27 @@ th_mempair_operands_p (rtx operands[4], bool load_p, if (MEM_VOLATILE_P (mem_1) || MEM_VOLATILE_P (mem_2)) return false; - /* If we have slow unaligned access, we only accept aligned memory. */ - if (riscv_slow_unaligned_access_p - && known_lt (MEM_ALIGN (mem_1), GET_MODE_SIZE (mode) * BITS_PER_UNIT)) -return false; /* Check if the addresses are in the form of [base+offset]. */ bool reversed = false; if (!th_mempair_check_consecutive_mems (mode, &mem_1, &mem_2, &reversed)) return false; + /* If necessary, reverse the local copy of the operands to simplify + testing of alignments and mempair operand. */ + if (reversed) +{ + std::swap (mem_1, mem_2); + std::swap (reg_1, reg_2); +} + + /* If we have slow unaligned access, we only accept aligned memory. */ + if (riscv_slow_unaligned_access_p + && known_lt (MEM_ALIGN (mem_1), GET_MODE_SIZE (mode) * BITS_PER_UNIT)) +return false; + /* The first memory accesses must be a mempair operand. */ - if ((!reversed && !th_mempair_operand_p (mem_1, mode)) - || (reversed && !th_mempair_operand_p (mem_2, mode))) + if (!th_mempair_operand_p (mem_1, mode)) return false; /* The operands must be of the same size. */ diff --git a/gcc/testsuite/gcc.target/riscv/pr116720.c b/gcc/testsuite/gcc.target/riscv/pr116720.c new file mode 100644 index ..0f795aba0bf1 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr116720.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -march=rv32ixtheadmempair -mabi=ilp32 -mno-strict-align" } */ + +struct a { + signed : 22; +}; +volatile short b; +int *c; +void d(int e, struct a) { + b; + c = &e; +}
[gcc r14-11370] d: Fix comparing uninitialized memory in dstruct.d [PR116961]
https://gcc.gnu.org/g:04b5c8b90cd95611d99684282cc321f06a0b49c2 commit r14-11370-g04b5c8b90cd95611d99684282cc321f06a0b49c2 Author: Iain Buclaw Date: Fri Feb 28 19:22:36 2025 +0100 d: Fix comparing uninitialized memory in dstruct.d [PR116961] Floating-point emulation in the D front-end is done via a type named `struct longdouble`, which in GDC is a small interface around the real_value type. Because the D code cannot include gcc/real.h directly, a big enough buffer is used for the data instead. On x86_64, this buffer is actually bigger than real_value itself, so when a new longdouble object is created with longdouble r; real_from_string3 (&r.rv (), buffer, mode); return r; there is uninitialized padding at the end of `r`. This was never a problem when D was implemented in C++ (until GCC 12) as comparing two longdouble objects with `==' would be forwarded to the relevant operator== overload that extracted the underlying real_value. However when the front-end was translated to D, such conditions were instead rewritten into identity comparisons return exp.toReal() is CTFloat.zero The `is` operator gets lowered as a call to `memcmp() == 0', which is where the read of uninitialized memory occurs, as seen by valgrind. ==26778== Conditional jump or move depends on uninitialised value(s) ==26778==at 0x911F41: dmd.dstruct._isZeroInit(dmd.expression.Expression) (dstruct.d:635) ==26778==by 0x9123BE: StructDeclaration::finalizeSize() (dstruct.d:373) ==26778==by 0x86747C: dmd.aggregate.AggregateDeclaration.determineSize(ref const(dmd.location.Loc)) (aggregate.d:226) [...] To avoid accidentally reading uninitialized data, explicitly initialize all `longdouble` variables with an empty constructor on C++ side of the implementation before initializing underlying real_value type it holds. PR d/116961 gcc/d/ChangeLog: * d-codegen.cc (build_float_cst): Change new_value type from real_t to real_value. * d-ctfloat.cc (CTFloat::fabs): Default initialize the return value. (CTFloat::ldexp): Likewise. (CTFloat::parse): Likewise. * d-longdouble.cc (longdouble::add): Likewise. (longdouble::sub): Likewise. (longdouble::mul): Likewise. (longdouble::div): Likewise. (longdouble::mod): Likewise. (longdouble::neg): Likewise. * d-port.cc (Port::isFloat32LiteralOutOfRange): Likewise. (Port::isFloat64LiteralOutOfRange): Likewise. gcc/testsuite/ChangeLog: * gdc.dg/pr116961.d: New test. (cherry picked from commit f7bc17ebc9ef89700672ed7125da719f3558f3b7) Diff: --- gcc/d/d-codegen.cc | 6 +++--- gcc/d/d-ctfloat.cc | 6 +++--- gcc/d/d-longdouble.cc | 12 ++-- gcc/d/d-port.cc | 4 ++-- gcc/testsuite/gdc.dg/pr116961.d | 7 +++ 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 2b3089b5f6dd..3b616930fe01 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -246,15 +246,15 @@ build_integer_cst (dinteger_t value, tree type) tree build_float_cst (const real_t &value, Type *totype) { - real_t new_value; + real_value new_value; TypeBasic *tb = totype->isTypeBasic (); gcc_assert (tb != NULL); tree type_node = build_ctype (tb); - real_convert (&new_value.rv (), TYPE_MODE (type_node), &value.rv ()); + real_convert (&new_value, TYPE_MODE (type_node), &value.rv ()); - return build_real (type_node, new_value.rv ()); + return build_real (type_node, new_value); } /* Returns the .length component from the D dynamic array EXP. */ diff --git a/gcc/d/d-ctfloat.cc b/gcc/d/d-ctfloat.cc index e77365ad0484..2393c47bbbf6 100644 --- a/gcc/d/d-ctfloat.cc +++ b/gcc/d/d-ctfloat.cc @@ -33,7 +33,7 @@ along with GCC; see the file COPYING3. If not see real_t CTFloat::fabs (real_t r) { - real_t x; + real_t x = {}; real_arithmetic (&x.rv (), ABS_EXPR, &r.rv (), NULL); return x.normalize (); } @@ -43,7 +43,7 @@ CTFloat::fabs (real_t r) real_t CTFloat::ldexp (real_t r, int exp) { - real_t x; + real_t x = {}; real_ldexp (&x.rv (), &r.rv (), exp); return x.normalize (); } @@ -87,7 +87,7 @@ CTFloat::isInfinity (real_t r) real_t CTFloat::parse (const char *buffer, bool &overflow) { - real_t r; + real_t r = {}; real_from_string3 (&r.rv (), buffer, TYPE_MODE (long_double_type_node)); /* Front-end checks overflow to see if the value is representable. */ diff --git a/gcc/d/d-longdouble.cc b/gcc/d/d-longdouble.cc index e4c8c5e6eb06..212689d1280a 100644 --- a/gcc/d/d-longdouble.cc +++ b/gcc/d/d-longdouble.cc @@ -113,7 +113,7 @@ longdouble::to_bool (void) const longdouble longdouble::add
[gcc r13-9405] d: Fix comparing uninitialized memory in dstruct.d [PR116961]
https://gcc.gnu.org/g:21b3e23bd972544c1e2f704e8b05dd9252a288ce commit r13-9405-g21b3e23bd972544c1e2f704e8b05dd9252a288ce Author: Iain Buclaw Date: Fri Feb 28 19:22:36 2025 +0100 d: Fix comparing uninitialized memory in dstruct.d [PR116961] Floating-point emulation in the D front-end is done via a type named `struct longdouble`, which in GDC is a small interface around the real_value type. Because the D code cannot include gcc/real.h directly, a big enough buffer is used for the data instead. On x86_64, this buffer is actually bigger than real_value itself, so when a new longdouble object is created with longdouble r; real_from_string3 (&r.rv (), buffer, mode); return r; there is uninitialized padding at the end of `r`. This was never a problem when D was implemented in C++ (until GCC 12) as comparing two longdouble objects with `==' would be forwarded to the relevant operator== overload that extracted the underlying real_value. However when the front-end was translated to D, such conditions were instead rewritten into identity comparisons return exp.toReal() is CTFloat.zero The `is` operator gets lowered as a call to `memcmp() == 0', which is where the read of uninitialized memory occurs, as seen by valgrind. ==26778== Conditional jump or move depends on uninitialised value(s) ==26778==at 0x911F41: dmd.dstruct._isZeroInit(dmd.expression.Expression) (dstruct.d:635) ==26778==by 0x9123BE: StructDeclaration::finalizeSize() (dstruct.d:373) ==26778==by 0x86747C: dmd.aggregate.AggregateDeclaration.determineSize(ref const(dmd.location.Loc)) (aggregate.d:226) [...] To avoid accidentally reading uninitialized data, explicitly initialize all `longdouble` variables with an empty constructor on C++ side of the implementation before initializing underlying real_value type it holds. PR d/116961 gcc/d/ChangeLog: * d-codegen.cc (build_float_cst): Change new_value type from real_t to real_value. * d-ctfloat.cc (CTFloat::fabs): Default initialize the return value. (CTFloat::ldexp): Likewise. (CTFloat::parse): Likewise. * d-longdouble.cc (longdouble::add): Likewise. (longdouble::sub): Likewise. (longdouble::mul): Likewise. (longdouble::div): Likewise. (longdouble::mod): Likewise. (longdouble::neg): Likewise. * d-port.cc (Port::isFloat32LiteralOutOfRange): Likewise. (Port::isFloat64LiteralOutOfRange): Likewise. gcc/testsuite/ChangeLog: * gdc.dg/pr116961.d: New test. (cherry picked from commit f7bc17ebc9ef89700672ed7125da719f3558f3b7) Diff: --- gcc/d/d-codegen.cc | 6 +++--- gcc/d/d-ctfloat.cc | 6 +++--- gcc/d/d-longdouble.cc | 12 ++-- gcc/d/d-port.cc | 4 ++-- gcc/testsuite/gdc.dg/pr116961.d | 7 +++ 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 60784928d41f..f6a46fad2b0a 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -246,15 +246,15 @@ build_integer_cst (dinteger_t value, tree type) tree build_float_cst (const real_t &value, Type *totype) { - real_t new_value; + real_value new_value; TypeBasic *tb = totype->isTypeBasic (); gcc_assert (tb != NULL); tree type_node = build_ctype (tb); - real_convert (&new_value.rv (), TYPE_MODE (type_node), &value.rv ()); + real_convert (&new_value, TYPE_MODE (type_node), &value.rv ()); - return build_real (type_node, new_value.rv ()); + return build_real (type_node, new_value); } /* Returns the .length component from the D dynamic array EXP. */ diff --git a/gcc/d/d-ctfloat.cc b/gcc/d/d-ctfloat.cc index 15d02b6de760..b716caf96f1c 100644 --- a/gcc/d/d-ctfloat.cc +++ b/gcc/d/d-ctfloat.cc @@ -33,7 +33,7 @@ along with GCC; see the file COPYING3. If not see real_t CTFloat::fabs (real_t r) { - real_t x; + real_t x = {}; real_arithmetic (&x.rv (), ABS_EXPR, &r.rv (), NULL); return x.normalize (); } @@ -43,7 +43,7 @@ CTFloat::fabs (real_t r) real_t CTFloat::ldexp (real_t r, int exp) { - real_t x; + real_t x = {}; real_ldexp (&x.rv (), &r.rv (), exp); return x.normalize (); } @@ -87,7 +87,7 @@ CTFloat::isInfinity (real_t r) real_t CTFloat::parse (const char *buffer, bool &overflow) { - real_t r; + real_t r = {}; real_from_string3 (&r.rv (), buffer, TYPE_MODE (long_double_type_node)); /* Front-end checks overflow to see if the value is representable. */ diff --git a/gcc/d/d-longdouble.cc b/gcc/d/d-longdouble.cc index c00208b47269..5a7afdab4d7a 100644 --- a/gcc/d/d-longdouble.cc +++ b/gcc/d/d-longdouble.cc @@ -113,7 +113,7 @@ longdouble::to_bool (void) const longdouble longdouble::add
[gcc r15-7787] [RISC-V][PR target/118934] Fix ICE in RISC-V long branch support
https://gcc.gnu.org/g:67e824c2497176980cb0c5d14bc730fa4ce2e1ad commit r15-7787-g67e824c2497176980cb0c5d14bc730fa4ce2e1ad Author: Jeff Law Date: Sun Mar 2 12:08:34 2025 -0700 [RISC-V][PR target/118934] Fix ICE in RISC-V long branch support I'm not sure if I goof'd this or if I merely upstreamed someone else's goof. Either way the long branch code isn't working correctly. We were using 'n' as the output modifier to negate the condition. But 'n' has a special meaning elsewhere, so when presented with a condition rather than what was expected, boom, the compiler ICE'd. Thankfully there's only a few places where we were using %n which I turned into %r. The BZ entry includes a good testcase, it just takes a long time to compile as it's trying to create the out-of-range scenario. I'm not including the testcase due to how long it takes, but I did test it locally to ensure it's working properly now. I'm sure that with a little bit of work I could create at testcase that worked before and fails with the trunk (by taking advantage of the fuzzyness in length computations). So I'm going to consider this a regression. Will push to the trunk after pre-commit testing does its thing. PR target/118934 gcc/ * config/riscv/corev.md (cv_branch): Adjust output template. (branch): Likewise. * config/riscv/riscv.md (branch): Likewise. * config/riscv/riscv.cc (riscv_asm_output_opcode): Handle 'r' rather than 'n'. Diff: --- gcc/config/riscv/corev.md | 4 ++-- gcc/config/riscv/riscv.cc | 4 ++-- gcc/config/riscv/riscv.md | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gcc/config/riscv/corev.md b/gcc/config/riscv/corev.md index e44fdc1129dd..1d4eb84c3e70 100644 --- a/gcc/config/riscv/corev.md +++ b/gcc/config/riscv/corev.md @@ -2627,7 +2627,7 @@ "TARGET_XCVBI" { if (get_attr_length (insn) == 12) -return "cv.b%n1\t%2,%z3,1f; jump\t%l0,ra; 1:"; +return "cv.b%r1\t%2,%z3,1f; jump\t%l0,ra; 1:"; return "cv.b%C1imm\t%2,%3,%0"; } @@ -2645,7 +2645,7 @@ "TARGET_XCVBI" { if (get_attr_length (insn) == 12) -return "b%n1\t%2,%z3,1f; jump\t%l0,ra; 1:"; +return "b%r1\t%2,%z3,1f; jump\t%l0,ra; 1:"; return "b%C1\t%2,%z3,%l0"; } diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 89aa25d5da92..38f3ae7cd840 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -6868,7 +6868,7 @@ riscv_asm_output_opcode (FILE *asm_out_file, const char *p) any outermost HIGH. 'R' Print the low-part relocation associated with OP. 'C' Print the integer branch condition for comparison OP. - 'n' Print the inverse of the integer branch condition for comparison OP. + 'r' Print the inverse of the integer branch condition for comparison OP. 'A' Print the atomic operation suffix for memory model OP. 'I' Print the LR suffix for memory model OP. 'J' Print the SC suffix for memory model OP. @@ -7027,7 +7027,7 @@ riscv_print_operand (FILE *file, rtx op, int letter) fputs (GET_RTX_NAME (code), file); break; -case 'n': +case 'r': /* The RTL names match the instruction names. */ fputs (GET_RTX_NAME (reverse_condition (code)), file); break; diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index f7070766783e..95951605fb46 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -3252,7 +3252,7 @@ "!TARGET_XCVBI" { if (get_attr_length (insn) == 12) -return "b%n1\t%2,%z3,1f; jump\t%l0,ra; 1:"; +return "b%r1\t%2,%z3,1f; jump\t%l0,ra; 1:"; return "b%C1\t%2,%z3,%l0"; }
[gcc r15-7780] avr: Fix up avr_print_operand diagnostics [PR118991]
https://gcc.gnu.org/g:047b7f9a5665a5cb1267861deece3e5d6ce5c5fb commit r15-7780-g047b7f9a5665a5cb1267861deece3e5d6ce5c5fb Author: Jakub Jelinek Date: Sun Mar 2 11:30:35 2025 +0100 avr: Fix up avr_print_operand diagnostics [PR118991] As can be seen in gcc/po/gcc.pot: #: config/avr/avr.cc:2754 #, c-format msgid "bad I/O address 0x" msgstr "" exgettext couldn't retrieve the whole format string in this case, because it uses a macro in the middle. output_operand_lossage is c-format function though, so we can't use %wx to print HOST_WIDE_INT, and HOST_WIDE_INT_PRINT_HEX_PURE is on some hosts %lx, on others %llx and on others %I64x so isn't really translatable that way. As Joseph mentioned in the PR, there is no easy way around this but go through a temporary buffer, which the following patch does. 2025-03-02 Jakub Jelinek PR translation/118991 * config/avr/avr.cc (avr_print_operand): Print ival into a temporary buffer and use %s in output_operand_lossage to make the diagnostics translatable. Diff: --- gcc/config/avr/avr.cc | 17 + 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc index d53453e25fdf..71c03b421489 100644 --- a/gcc/config/avr/avr.cc +++ b/gcc/config/avr/avr.cc @@ -2750,10 +2750,19 @@ avr_print_operand (FILE *file, rtx x, int code) fprintf (file, HOST_WIDE_INT_PRINT_HEX, ival - sfr0); } else - output_operand_lossage - ("bad I/O address 0x" HOST_WIDE_INT_PRINT_HEX_PURE -" outside of valid range [0x%x, 0x%x] for %%i operand", -ival, sfr0, sfr0 + 0x3f); + { + char buf[17]; + /* Printed indirectly through buffer, as + output_operand_lossage is translatable but uses printf + format strings, so HOST_WIDE_INT_PRINT_HEX_PURE macro can't + be used there to make translation possible and how exactly + can be HOST_WIDE_INT printed is host dependent. */ + snprintf (buf, sizeof buf, HOST_WIDE_INT_PRINT_HEX_PURE, + ival); + output_operand_lossage ("bad I/O address 0x%s outside of " + "valid range [0x%x, 0x%x] for %%i " + "operand", buf, sfr0, sfr0 + 0x3f); + } } break; // CONST_INT
[gcc r12-10972] d: Fix comparing uninitialized memory in dstruct.d [PR116961]
https://gcc.gnu.org/g:f6be26657c8b974a5caf39350e4965cfb2c4b936 commit r12-10972-gf6be26657c8b974a5caf39350e4965cfb2c4b936 Author: Iain Buclaw Date: Fri Feb 28 19:22:36 2025 +0100 d: Fix comparing uninitialized memory in dstruct.d [PR116961] Floating-point emulation in the D front-end is done via a type named `struct longdouble`, which in GDC is a small interface around the real_value type. Because the D code cannot include gcc/real.h directly, a big enough buffer is used for the data instead. On x86_64, this buffer is actually bigger than real_value itself, so when a new longdouble object is created with longdouble r; real_from_string3 (&r.rv (), buffer, mode); return r; there is uninitialized padding at the end of `r`. This was never a problem when D was implemented in C++ (until GCC 12) as comparing two longdouble objects with `==' would be forwarded to the relevant operator== overload that extracted the underlying real_value. However when the front-end was translated to D, such conditions were instead rewritten into identity comparisons return exp.toReal() is CTFloat.zero The `is` operator gets lowered as a call to `memcmp() == 0', which is where the read of uninitialized memory occurs, as seen by valgrind. ==26778== Conditional jump or move depends on uninitialised value(s) ==26778==at 0x911F41: dmd.dstruct._isZeroInit(dmd.expression.Expression) (dstruct.d:635) ==26778==by 0x9123BE: StructDeclaration::finalizeSize() (dstruct.d:373) ==26778==by 0x86747C: dmd.aggregate.AggregateDeclaration.determineSize(ref const(dmd.location.Loc)) (aggregate.d:226) [...] To avoid accidentally reading uninitialized data, explicitly initialize all `longdouble` variables with an empty constructor on C++ side of the implementation before initializing underlying real_value type it holds. PR d/116961 gcc/d/ChangeLog: * d-codegen.cc (build_float_cst): Change new_value type from real_t to real_value. * d-ctfloat.cc (CTFloat::fabs): Default initialize the return value. (CTFloat::ldexp): Likewise. (CTFloat::parse): Likewise. * d-longdouble.cc (longdouble::add): Likewise. (longdouble::sub): Likewise. (longdouble::mul): Likewise. (longdouble::div): Likewise. (longdouble::mod): Likewise. (longdouble::neg): Likewise. * d-port.cc (Port::isFloat32LiteralOutOfRange): Likewise. (Port::isFloat64LiteralOutOfRange): Likewise. gcc/testsuite/ChangeLog: * gdc.dg/pr116961.d: New test. (cherry picked from commit f7bc17ebc9ef89700672ed7125da719f3558f3b7) Diff: --- gcc/d/d-codegen.cc | 6 +++--- gcc/d/d-ctfloat.cc | 6 +++--- gcc/d/d-longdouble.cc | 12 ++-- gcc/d/d-port.cc | 4 ++-- gcc/testsuite/gdc.dg/pr116961.d | 7 +++ 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 31d593ca7fde..4f20d063c904 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -244,15 +244,15 @@ build_integer_cst (dinteger_t value, tree type) tree build_float_cst (const real_t &value, Type *totype) { - real_t new_value; + real_value new_value; TypeBasic *tb = totype->isTypeBasic (); gcc_assert (tb != NULL); tree type_node = build_ctype (tb); - real_convert (&new_value.rv (), TYPE_MODE (type_node), &value.rv ()); + real_convert (&new_value, TYPE_MODE (type_node), &value.rv ()); - return build_real (type_node, new_value.rv ()); + return build_real (type_node, new_value); } /* Returns the .length component from the D dynamic array EXP. */ diff --git a/gcc/d/d-ctfloat.cc b/gcc/d/d-ctfloat.cc index c4d9a44c59ba..3afddc8fe1a6 100644 --- a/gcc/d/d-ctfloat.cc +++ b/gcc/d/d-ctfloat.cc @@ -33,7 +33,7 @@ along with GCC; see the file COPYING3. If not see real_t CTFloat::fabs (real_t r) { - real_t x; + real_t x = {}; real_arithmetic (&x.rv (), ABS_EXPR, &r.rv (), NULL); return x.normalize (); } @@ -43,7 +43,7 @@ CTFloat::fabs (real_t r) real_t CTFloat::ldexp (real_t r, int exp) { - real_t x; + real_t x = {}; real_ldexp (&x.rv (), &r.rv (), exp); return x.normalize (); } @@ -87,7 +87,7 @@ CTFloat::isInfinity (real_t r) real_t CTFloat::parse (const char *buffer, bool *overflow) { - real_t r; + real_t r = {}; real_from_string3 (&r.rv (), buffer, TYPE_MODE (long_double_type_node)); /* Front-end checks overflow to see if the value is representable. */ diff --git a/gcc/d/d-longdouble.cc b/gcc/d/d-longdouble.cc index cf0b68b2f2da..2fb48e2722f2 100644 --- a/gcc/d/d-longdouble.cc +++ b/gcc/d/d-longdouble.cc @@ -113,7 +113,7 @@ longdouble::to_bool (void) const longdouble longdouble::add
[gcc r15-7781] Fortran: Tidy subheadings in Fortran documentation [PR47928]
https://gcc.gnu.org/g:d8f5e1b0ba01ac65dbae98daa065109f18b87751 commit r15-7781-gd8f5e1b0ba01ac65dbae98daa065109f18b87751 Author: Sandra Loosemore Date: Tue Feb 25 01:03:52 2025 + Fortran: Tidy subheadings in Fortran documentation [PR47928] This is a preparatory patch for the main documentation changes requested in the issue. gcc/fortran/ChangeLog PR fortran/47928 * gfortran.texi: Consistently use "@emph{Notes}:" instead of other spellings. * intrinsic.texi: Likewise. Also fix an inconsistent capitalization and remove a redundant "Standard" entry. Diff: --- gcc/fortran/gfortran.texi | 57 +++--- gcc/fortran/intrinsic.texi | 40 2 files changed, 48 insertions(+), 49 deletions(-) diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi index ba3c3771c43c..b45ea484f457 100644 --- a/gcc/fortran/gfortran.texi +++ b/gcc/fortran/gfortran.texi @@ -4173,7 +4173,7 @@ The references make up a single linked list of reference operations. The the chain. Component and array refs can be arbitrarily mixed as long as they comply to the Fortran standard. -@emph{NOTES} +@emph{Notes}: The member @code{STATIC_ARRAY_TYPE} is used only when the @code{TYPE} is @code{CAF_REF_STATIC_ARRAY}. The member gives the type of the data referenced. Because no array descriptor is available for a descriptorless array and @@ -4256,7 +4256,7 @@ arguments passed to the program or @code{NULL}. command-line arguments or @code{NULL}. @end multitable -@item @emph{NOTES} +@item @emph{Notes}: The function is modelled after the initialization function of the Message Passing Interface (MPI) specification. Due to the way coarray registration works, it might not be the first call to the library. If the main program is @@ -4278,7 +4278,7 @@ been compiled with the @option{-fcoarray=lib} option. @item @emph{Syntax}: @code{void _gfortran_caf_finish (void)} -@item @emph{NOTES} +@item @emph{Notes}: For non-Fortran programs, it is recommended to call the function at the end of the main program. To ensure that the shutdown is also performed for programs where this function is not explicitly invoked, for instance @@ -4305,7 +4305,7 @@ This function returns the current image number, which is a positive number. in TS18508. Shall be a nonnegative number. @end multitable -@item @emph{NOTES} +@item @emph{Notes}: If the Fortran intrinsic @code{this_image} is invoked without an argument, which is the only permitted form in Fortran 2008, GCC passes @code{0} as first argument. @@ -4334,7 +4334,7 @@ Shall be positive. @item @var{failed} @tab shall be -1, 0, or 1 @end multitable -@item @emph{NOTES} +@item @emph{Notes}: This function follows TS18508. If the num_image intrinsic has no arguments, then the compiler passes @code{distance=0} and @code{failed=-1} to the function. @end table @@ -4362,7 +4362,7 @@ has executed a @code{FAIL IMAGE} statement. performed. @end multitable -@item @emph{NOTES} +@item @emph{Notes}: This function follows TS18508. Because team-functionality is not yet implemented a null pointer is passed for the @var{team} argument at the moment. @end table @@ -4390,7 +4390,7 @@ performed. @item @var{image} @tab optional; the kind of the resulting integer array. @end multitable -@item @emph{NOTES} +@item @emph{Notes}: This function follows TS18508. Because team-functionality is not yet implemented a null pointer is passed for the @var{team} argument at the moment. @end table @@ -4418,7 +4418,7 @@ performed. @item @var{image} @tab optional; the kind of the resulting integer array. @end multitable -@item @emph{NOTES} +@item @emph{Notes}: This function follows TS18508. Because team-functionality is not yet implemented a null pointer is passed for the @var{team} argument at the moment. @end table @@ -4478,7 +4478,7 @@ an error message; may be @code{NULL} @item @var{errmsg_len} @tab the buffer size of errmsg. @end multitable -@item @emph{NOTES} +@item @emph{Notes}: Nonallocatable coarrays have to be registered prior use from remote images. In order to guarantee this, they have to be registered before the main program. This can be achieved by creating constructor functions. That is what @@ -4529,7 +4529,7 @@ to an error message; may be NULL @item @var{errmsg_len} @tab the buffer size of errmsg. @end multitable -@item @emph{NOTES} +@item @emph{Notes}: For nonallocatable coarrays this function is never called. If a cleanup is required, it has to be handled via the finish, stop and error stop functions, and via destructors. @@ -4564,7 +4564,7 @@ size_t *opt_dst_charlen)}. GFortran ensures that functions provided to @code{_gfortran_caf_register_accessor} adhere to this interface. @end multitable -@item @emph{NOTES} +@item @emph{Notes}: This function is required to have a nearly constant runtime complex
[gcc r15-7782] Fortran: Whitespace cleanup in documentation [PR47928]
https://gcc.gnu.org/g:1f458cfc17775903ab85bda127d0454014f70906 commit r15-7782-g1f458cfc17775903ab85bda127d0454014f70906 Author: Sandra Loosemore Date: Tue Feb 25 18:40:06 2025 + Fortran: Whitespace cleanup in documentation [PR47928] This is a preparatory patch for the main changes requested in the issue. gcc/fortran/ChangeLog PR fortran/47928 * intrinsic.texi: Put a blank line between "@item @emph{}" subheadings, but not more than one. Diff: --- gcc/fortran/intrinsic.texi | 34 +++--- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/gcc/fortran/intrinsic.texi b/gcc/fortran/intrinsic.texi index 21da3ff34fa1..c965aef9d426 100644 --- a/gcc/fortran/intrinsic.texi +++ b/gcc/fortran/intrinsic.texi @@ -2355,7 +2355,6 @@ coindexed @var{ATOM}, if the remote image has stopped, it is assigned the value of @code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote image has failed, the value @code{STAT_FAILED_IMAGE}. - @item @emph{Standard}: Fortran 2008 and later; with @var{STAT}, TS 18508 or later @@ -4587,7 +4586,6 @@ and may not start with @code{0.0}. For @code{CPU_TIME}, the absolute value is meaningless; only differences between subsequent calls to this subroutine, as shown in the example below, should be used. - @item @emph{Standard}: Fortran 95 and later @@ -4644,7 +4642,6 @@ shifted out one end of each rank one section are shifted back in the other end. @item @emph{Standard}: Fortran 90 and later - @item @emph{Class}: Transformational function @@ -5791,7 +5788,6 @@ dependent. In particular, on POSIX-compliant systems, the @code{SIGINT} and such, if the parent process is terminated, the child process might not be terminated alongside. - @item @emph{See also}: @ref{SYSTEM} @end table @@ -5967,7 +5963,6 @@ unlimited polymorphic. The return value is a scalar of type default logical. It is true if and only if the dynamic type of A is an extension type of the dynamic type of MOLD. - @item @emph{See also}: @ref{SAME_TYPE_AS} @end table @@ -6193,7 +6188,6 @@ for that row is zero. @item @emph{Standard}: Fortran 2008 and later - @item @emph{Class}: Transformational function @@ -7248,7 +7242,6 @@ Function The return value of @code{GETGID} is an @code{INTEGER} of the default kind. - @item @emph{Example}: See @code{GETPID} for an example. @@ -7327,7 +7320,6 @@ Function The return value of @code{GETPID} is an @code{INTEGER} of the default kind. - @item @emph{Example}: @smallexample program info @@ -7367,7 +7359,6 @@ Function The return value of @code{GETUID} is an @code{INTEGER} of the default kind. - @item @emph{Example}: See @code{GETPID} for an example. @@ -8271,7 +8262,6 @@ Inquiry function. the corank of @var{COARRAY}. @end multitable - @item @emph{Return value}: Scalar default integer with the value of the image index that corresponds to the cosubscripts. For invalid cosubscripts the result is zero. @@ -8838,6 +8828,7 @@ PROGRAM test_isatty END DO END PROGRAM @end smallexample + @item @emph{See also}: @ref{TTYNAM} @end table @@ -8965,6 +8956,7 @@ The return value is of the same type as @var{I}. @item @emph{Description}: @code{ISNAN} tests whether a floating-point value is an IEEE Not-a-Number (NaN). + @item @emph{Standard}: GNU extension @@ -9034,7 +9026,6 @@ and the kind shall be the default integer kind. @item @emph{Return value}: Does not return anything. - @item @emph{Example}: @smallexample program test_itime @@ -9147,6 +9138,7 @@ end program test_kind @item @emph{Description}: Returns the lower bounds of an array, or a single lower bound along the @var{DIM} dimension. + @item @emph{Standard}: Fortran 90 and later, with @var{KIND} argument Fortran 2003 and later @@ -9190,6 +9182,7 @@ dimension, the lower bound is taken to be 1. @item @emph{Description}: Returns the lower bounds of a coarray, or a single lower cobound along the @var{DIM} codimension. + @item @emph{Standard}: Fortran 2008 and later @@ -9298,14 +9291,12 @@ expression indicating the kind parameter of the result. The return value is of type @code{INTEGER} and of kind @var{KIND}. If @var{KIND} is absent, the return value is of default integer kind. - @item @emph{Specific names}: @multitable @columnfractions .20 .23 .20 .33 @headitem Name @tab Argument @tab Return type @tab Standard @item @code{LEN(STRING)} @tab @code{CHARACTER} @tab @code{INTEGER}@tab Fortran 77 and later @end multitable - @item @emph{See also}: @ref{LEN_TRIM}, @* @ref{ADJUSTL}, @* @@ -11387,7 +11378,6 @@ Returns the number of images. Fortran 2008 and later. With @var{DISTANCE} or @var{FAILED} argument, Technical Specification (TS) 18508 or later - @item @emph{Class}: Transformational function @@ -11747,6 +11737,7 @@ program test_population print *, popcnt(huge(0_8)), poppar(huge(0_8)) en
[gcc r15-7785] Fortran: Small fixes in intrinsic.texi.
https://gcc.gnu.org/g:43a9022aa0fa2fbe66bebd51e6e73759501c04cb commit r15-7785-g43a9022aa0fa2fbe66bebd51e6e73759501c04cb Author: Sandra Loosemore Date: Sun Mar 2 01:43:26 2025 + Fortran: Small fixes in intrinsic.texi. gcc/fortran/ChangeLog * intrinsic.texi: Fix inconsistent capitalization of argument names and other minor copy-editing. Diff: --- gcc/fortran/intrinsic.texi | 26 +- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/gcc/fortran/intrinsic.texi b/gcc/fortran/intrinsic.texi index 4e6d2faea31c..8c160e58b00a 100644 --- a/gcc/fortran/intrinsic.texi +++ b/gcc/fortran/intrinsic.texi @@ -1116,8 +1116,8 @@ end program test_allocated @end smallexample @item @emph{Standard}: -Fortran 90 and later. Note, the @code{SCALAR=} keyword and allocatable -scalar entities are available in Fortran 2003 and later. +Fortran 90 and later; for the @code{SCALAR=} keyword and allocatable +scalar entities, Fortran 2003 and later. @end table @@ -2072,7 +2072,7 @@ Fortran 2008 and later; with @var{STAT}, TS 18508 or later @table @asis @item @emph{Synopsis}: -@code{CALL ATOMIC_FETCH_ADD (ATOM, VALUE, old [, STAT])} +@code{CALL ATOMIC_FETCH_ADD (ATOM, VALUE, OLD [, STAT])} @item @emph{Description}: @code{ATOMIC_FETCH_ADD(ATOM, VALUE, OLD)} atomically stores the value of @@ -3075,24 +3075,24 @@ for @code{UNSIGNED} (@pxref{Unsigned integers}) @table @asis @item @emph{Synopsis}: -@code{RESULT = C_ASSOCIATED(c_ptr_1[, c_ptr_2])} +@code{RESULT = C_ASSOCIATED(CPTR1[, CPTR2])} @item @emph{Description}: -@code{C_ASSOCIATED(c_ptr_1[, c_ptr_2])} determines the status of the C pointer -@var{c_ptr_1} or if @var{c_ptr_1} is associated with the target @var{c_ptr_2}. +@code{C_ASSOCIATED(CPTR1[, CPTR2])} determines the status of the C pointer +@var{CPTR1} or if @var{CPTR1} is associated with the target @var{CPTR2}. @item @emph{Class}: Inquiry function @item @emph{Arguments}: @multitable @columnfractions .15 .70 -@item @var{c_ptr_1} @tab Scalar of the type @code{C_PTR} or @code{C_FUNPTR}. -@item @var{c_ptr_2} @tab (Optional) Scalar of the same type as @var{c_ptr_1}. +@item @var{CPTR1} @tab Scalar of the type @code{C_PTR} or @code{C_FUNPTR}. +@item @var{CPTR2} @tab (Optional) Scalar of the same type as @var{CPTR1}. @end multitable @item @emph{Return value}: The return value is of type @code{LOGICAL}; it is @code{.false.} if either -@var{c_ptr_1} is a C NULL pointer or if @var{c_ptr1} and @var{c_ptr_2} +@var{CPTR1} is a C NULL pointer or if @var{CPTR1} and @var{CPTR2} point to different addresses. @item @emph{Example}: @@ -3178,7 +3178,7 @@ Fortran 2003 and later @table @asis @item @emph{Synopsis}: -@code{CALL C_F_PROCPOINTER(cptr, fptr)} +@code{CALL C_F_PROCPOINTER(CPTR, FPTR)} @item @emph{Description}: @code{C_F_PROCPOINTER(CPTR, FPTR)} Assign the target of the C function pointer @@ -3236,17 +3236,17 @@ Fortran 2003 and later @table @asis @item @emph{Synopsis}: -@code{RESULT = C_FUNLOC(x)} +@code{RESULT = C_FUNLOC(X)} @item @emph{Description}: -@code{C_FUNLOC(x)} determines the C address of the argument. +@code{C_FUNLOC(X)} determines the C address of the argument. @item @emph{Class}: Inquiry function @item @emph{Arguments}: @multitable @columnfractions .15 .70 -@item @var{x} @tab Interoperable function or pointer to such function. +@item @var{X} @tab Interoperable function or pointer to such function. @end multitable @item @emph{Return value}: