aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2024-05-16ada: Fix reference to RM clause in commentRonan Desplanques1-1/+1
gcc/ada/ * sem_util.ads (Check_Function_Writable_Actuals): Fix comment.
2024-05-16ada: Fix missing length checks with case expressionsRonan Desplanques2-4/+17
This fixes an issue where length checks were not generated when the right-hand side of an assigment involved a case expression. gcc/ada/ * sem_res.adb (Resolve_Case_Expression): Add length check insertion. * exp_ch4.adb (Expand_N_Case_Expression): Add handling of nodes known to raise Constraint_Error.
2024-05-16ada: Fix standalone Windows builds of adaint.cSebastian Poeplau1-0/+7
Define PATH_SEPARATOR and HOST_EXECUTABLE_SUFFIX in standalone MinGW builds; the definitions normally come from GCC, and the defaults don't work for native Windows. gcc/ada/ * adaint.c: New defines for STANDALONE mode.
2024-05-16ada: Avoid checking parameters of protected proceduresViljar Indus1-2/+5
The compiler triggers warnings on generated protected procedures if the procedure does not have an explicit spec. Instead check if the body was created for a protected procedure if the spec is not present. gcc/ada/ * sem_ch6.adb (Analyze_Subprogram_Body_Helper): If the spec is not present for a subprogram body then check if the body definiton was created for a protected procedure.
2024-05-16ada: Ignore ghost nodes in call graph information for dispatching callsPiotr Trojanek1-9/+8
When emitting call graph information, we already skipped calls to ignored ghost entities, but this code was causing crashes (in production builds) and assertion failures (in development builds), because the ignored ghost entities are not fully decorated, e.g. when they come from instances of generic units with default subprograms. With this patch we skip call graph information for ignored ghost entities when they are registered, both as explicit calls and as tagged types that will come with internally generated dispatching subprograms. gcc/ada/ * exp_cg.adb (Generate_CG_Output): Remove code for ignored ghost entities that applied to subprogram calls. (Register_CG_Node): Skip ignored ghost entities, both calls and tagged types, when they are registered.
2024-05-16ada: Fix reason code for length checkRonan Desplanques1-5/+8
This patch fixes the reason code used by Apply_Selected_Length_Checks, which was wrong in some cases when the check could be determined to always fail at compile time. gcc/ada/ * checks.adb (Apply_Selected_Length_Checks): Fix reason code.
2024-05-16ada: Propagate Program_Error from failed finalization of collectionEric Botcazou1-6/+6
This aligns finalization collections with finalization masters when it comes to propagating an exception raised by the finalization of a specific object, by always propagating Program_Error instead of the aforementioned exception. gcc/ada/ * libgnat/s-finpri.adb (Raise_From_Controlled_Operation): New declaration of imported procedure moved from... (Finalize_Master): ...there. (Finalize): Call Raise_From_Controlled_Operation instead of Reraise_Occurrence to propagate the exception, if any.
2024-05-16ada: Improve recovery from illegal occurrence of 'Old in if_expressionPiotr Trojanek1-1/+1
Fix assertion failure in developer builds which happened when the THEN expression contains an illegal occurrence of 'Old and the type of the THEN expression is left as Any_Type, but there is no ELSE expression. gcc/ada/ * sem_ch4.adb (Analyze_If_Expression): Add guard for if_expression without an ELSE part.
2024-05-16ada: No need to follow New_Occurrence_Of with Set_EtypePiotr Trojanek2-11/+9
Routine New_Occurrence_Of itself sets the Etype of its result; there is no need to set it explicitly afterwards. Code cleanup related to fix for attribute 'Old; semantics is unaffected. gcc/ada/ * exp_ch13.adb (Expand_N_Free_Statement): After analysis, the new temporary has the type of its Object_Definition and the new occurrence of this temporary has this type as well; simplify. * sem_util.adb (Indirect_Temp_Value): Remove redundant call to Set_Etype; simplify. (Is_Access_Type_For_Indirect_Temp): Add missing body header.
2024-05-16ada: Fix detection of if_expressions that are known on entryPiotr Trojanek1-3/+1
Fix a small glitch in routine Is_Known_On_Entry, which returned False for all if_expressions, regardless whether their conditions or dependent expressions are known on entry. gcc/ada/ * sem_util.adb (Is_Known_On_Entry): Check whether condition and dependent expressions of an if_expression are known on entry.
2024-05-16ada: Fix comments about Get_Ranged_ChecksRonan Desplanques2-3/+3
Checks.Get_Ranged_Checks was onced named Range_Check, and a few comments referred to it by that name before this commit. To avoid confusion with Types.Range_Check, this commits fixes those comments. gcc/ada/ * checks.ads: Fix comments. * checks.adb: Likewise.
2024-05-16ada: Minor performance improvement for dynamically-allocated controlled objectsEric Botcazou2-22/+6
The values returned by Header_Alignment and Header_Size are known at compile time and powers of two on almost all platforms, so inlining them by means of an expression function improves the object code generated for alignment and size calculations involving them. gcc/ada/ * libgnat/s-finpri.ads: Add use type clause for Storage_Offset. (Header_Alignment): Turn into an expression function. (Header_Size): Likewise. * libgnat/s-finpri.adb: Remove use type clause for Storage_Offset. (Header_Alignment): Delete. (Header_Size): Likewise.
2024-05-16ada: Fixup one more pattern of broken scope informationMarc Poulhiès1-10/+56
When an array's initialization contains a `others =>` clause with an expression that involves finalization, the resulting scope information is incorrect and can cause crashes with backend (i.e. gnat-llvm) that also use unnesting. The observable symptom is a nested object declaration (created by the compiler) within a loop wrapped in a procedure created by the unnester that has incoherent scope information: its Scope field points to the scope of the procedure (1 level too high) and is contained in the entity chain of some entity nested in the procedure (correct). The correct solution would be to fix the scope information when it is created, but this revealed too large of a task with many interaction with existing code. This change adds another pattern to the Fixup_Inner_Scopes procedure to detect the problematic case and fix the scope, "after the facts". gcc/ada/ * exp_ch7.adb (Unnest_Loop::Fixup_Inner_Scopes): detect a new problematic pattern and fixup the scope accordingly.
2024-05-16ada: Fix typo in CUDA error messagePiotr Trojanek1-1/+1
Fix typo in error message; semantics is unaffected. gcc/ada/ * gnat_cuda.adb (Remove_CUDA_Device_Entities): Fix typo.
2024-05-16ada: Fix latent alignment issue for dynamically-allocated controlled objectsEric Botcazou4-37/+66
Dynamically-allocated controlled objects are attached to a finalization collection by means of a hidden header placed right before the object, which means that the size effectively allocated must naturally account for the size of this header. But the allocation must also account for the alignment of this header in order to have it properly aligned. gcc/ada/ * libgnat/s-finpri.ads (Header_Alignment): New function. (Header_Size): Adjust description. (Master_Node): Put Finalize_Address as first component. (Collection_Node): Likewise. * libgnat/s-finpri.adb (Header_Alignment): New function. (Header_Size): Return the object size in storage units. * libgnat/s-stposu.ads (Adjust_Controlled_Dereference): Replace collection node with header in description. * libgnat/s-stposu.adb (Adjust_Controlled_Dereference): Likewise. (Allocate_Any_Controlled): Likewise. Pass the maximum of the specified alignment and that of the header to the allocator. (Deallocate_Any_Controlled): Likewise to the deallocator.
2024-05-16ada: Fix resolving tagged operations in array aggregatesViljar Indus1-2/+17
In the Two_Pass_Aggregate_Expansion we were removing all of the entity links in the Iterator_Specification to avoid reusing the same Iterator_Definition in both loops. However this approach was also breaking the links to calls with dot notation that had been transformed to the regular call notation. In order to circumvent this, explicitly create new identifier definitions when copying the Iterator_Specfications for both of the loops. gcc/ada/ * exp_aggr.adb (Two_Pass_Aggregate_Expansion): Explicitly create new Defining_Iterators for both of the loops.
2024-05-16ada: Fix bogus error on function returning noncontrolling result in private partEric Botcazou1-14/+9
This occurs in the additional case of RM 3.9.3(10) in Ada 2012, that is to say the access controlling result, because the implementation does not use the same (correct) conditions as in the original case. This factors out these conditions and uses them in both cases, as well as adjusts the wording of the message in the first case. gcc/ada/ * sem_ch6.adb (Check_Private_Overriding): Implement the second part of RM 3.9.3(10) consistently in both cases.
2024-05-16ada: Fix casing of CUDA in error messagesPiotr Trojanek1-1/+12
Error messages now capitalize CUDA. gcc/ada/ * erroutc.adb (Set_Msg_Insertion_Reserved_Word): Fix casing for CUDA appearing in error message strings. (Set_Msg_Str): Likewise for CUDA being a part of a Name_Id.
2024-05-16ada: Fix crash with -gnatdJ and -gnatw_qRonan Desplanques1-4/+4
This commit makes the emission of -gnatw_q warnings pass node information so as to handle the enclosing subprogram display of -gnatdJ instead of crashing. gcc/ada/ * exp_ch4.adb (Expand_Composite_Equality): Call Error_Msg_N instead of Error_Msg.
2024-05-16ada: Follow up fixes for Put_Image/streaming regressionsSteve Baird1-0/+38
A recent change to reduce duplication of compiler-generated Put_Image and streaming subprograms introduced some regressions. The fix for one of them was incomplete. gcc/ada/ * exp_attr.adb (Build_And_Insert_Type_Attr_Subp): Further tweaking of the point where a compiler-generated Put_Image or streaming subprogram is to be inserted in the tree. If one such subprogram calls another (as is often the case with, for example, Put_Image procedures for composite type and for a component type thereof), then we want to avoid use-before-definition problems that can result from inserting the caller ahead of the callee.
2024-05-16ada: Implement per-finalization-collection spinlocksEric Botcazou2-16/+75
This changes the implementation of finalization collections from using the global task lock to using per-collection spinlocks. Spinlocks are a good fit in this context because they are very cheap and therefore can be taken with a fine granularity only around the portions of code implementing the shuffling of pointers required by attachment and detachment actions. gcc/ada/ * libgnat/s-finpri.ads (Lock_Type): New modular type. (Collection_Node): Add Enclosing_Collection component. (Finalization_Collection): Add Lock component. * libgnat/s-finpri.adb: Add clauses for System.Atomic_Primitives. (Attach_Object_To_Collection): Lock and unlock the collection. Save a pointer to the enclosing collection in the node. (Detach_Object_From_Collection): Lock and unlock the collection. (Finalize): Likewise. (Initialize): Initialize the lock. (Lock_Collection): New procedure. (Unlock_Collection): Likewise.
2024-05-16ada: Formal_Derived_Type'Size is not staticSteve Baird1-0/+10
In deciding whether a Size attribute reference is static, the compiler could get confused about whether an implicitly-declared subtype of a generic formal type is itself a generic formal type, possibly resulting in an assertion failure and then a bugbox. gcc/ada/ * sem_attr.adb (Eval_Attribute): Expand existing checks for generic formal types for which Is_Generic_Type returns False. In that case, mark the attribute reference as nonstatic.
2024-05-16ada: Fix bug in maintaining dimension infoSteve Baird1-0/+3
Copying a node does not automatically propagate its associated dimension information (if any). This must be done explicitly. gcc/ada/ * sem_util.adb (Copy_Node_With_Replacement): Add call to Copy_Dimensions so that any dimension information associated with the copied node is also associated with the resulting copy.
2024-05-16ada: Remove Aspect_Specifications field from N_Procedure_SpecificationPiotr Trojanek1-1/+0
Sync Has_Aspect_Specifications_Flag with the actual flags in the AST. Code cleanup; behavior is unaffected. gcc/ada/ * gen_il-gen-gen_nodes.adb (N_Procedure_Specification): Remove Aspect_Specifications field.
2024-05-16ada: Reuse existing expression when rewriting aspects to pragmasPiotr Trojanek1-5/+5
Code cleanup; semantics is unaffected. gcc/ada/ * sem_ch13.adb (Analyze_Aspect_Specification): Consistently reuse existing constant where possible.
2024-05-16ada: Cleanup reporting locations for Ada 2022 and GNAT extension aspectsPiotr Trojanek1-5/+5
Code cleanup; semantics is unaffected. gcc/ada/ * sem_ch13.adb (Analyze_Aspect_Specification): Consistently reuse existing constant where possible.
2024-05-16ada: Fix alphabetic ordering of aspect identifiersPiotr Trojanek1-2/+2
Code cleanup. gcc/ada/ * aspects.ads (Aspect_Id): Fix ordering.
2024-05-16ada: Fix ordering of code for pragma Preelaborable_InitializationPiotr Trojanek1-80/+80
Code cleanup. gcc/ada/ * sem_prag.adb (Analyze_Pragma): Move case alternative to match to alphabetic order.
2024-05-16ada: Fix casing in error messagesPiotr Trojanek2-2/+2
Error messages should not start with a capital letter. gcc/ada/ * gnat_cuda.adb (Remove_CUDA_Device_Entities): Fix casing (this primarily fixes a style, because the capitalization will not be preserved by the error-reporting machinery anyway). * sem_ch13.adb (Analyze_User_Aspect_Aspect_Specification): Fix casing in error message.
2024-05-16ada: Fix docs and comments about pragmas for Boolean-valued aspectsPiotr Trojanek3-73/+89
Fix various inconsistencies in documentation and comments of Boolean-valued aspects. gcc/ada/ * doc/gnat_rm/implementation_defined_pragmas.rst: Fix documentation. * sem_prag.adb: Fix comments. * gnat_rm.texi: Regenerate.
2024-05-15diagnostics: use unicode art for interprocedural depthDavid Malcolm5-142/+331
gcc/testsuite/ChangeLog: * gcc.dg/analyzer/out-of-bounds-diagram-1-emoji.c: Update expected output to use unicode for depth indication. * gcc.dg/analyzer/out-of-bounds-diagram-1-unicode.c: Likewise. gcc/ChangeLog: * text-art/theme.cc (ascii_theme::get_cppchar): Add cell_kind::INTERPROCEDURAL_*. (unicode_theme::get_cppchar): Likewise. * text-art/theme.h (theme::cell_kind): Likewise. * tree-diagnostic-path.cc: (thread_event_printer::print_swimlane_for_event_range): Use the above to get characters for indicating interprocedural stack depth activity, falling back to ascii. (selftest::test_interprocedural_path_1): Test with both ascii and unicode themes. (selftest::test_interprocedural_path_2): Likewise. (selftest::test_recursion): Likewise. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-05-15diagnostics: add warning emoji to events with VERB_dangerDavid Malcolm3-4/+57
Tweak the printing of -fdiagnostics-path-format=inline-events so that any event with diagnostic_event::VERB_danger gains a warning emoji, provided that the text art theme enables emoji support. VERB_danger is set by the analyzer on the last event in a path, and so this emoji appears at the end of all analyzer execution paths highlighting the location of the problem. gcc/testsuite/ChangeLog: * gcc.dg/analyzer/out-of-bounds-diagram-1-emoji.c: Update expected output to include warning emoji. * gcc.dg/analyzer/warning-emoji.c: New test. gcc/ChangeLog: * tree-diagnostic-path.cc: Include "text-art/theme.h". (path_label::get_text): If the event has diagnostic_event::VERB_danger, and the theme enables emojis, then add a warning emoji between the event number and the event text. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-05-15diagnostics: simplify output of purely intraprocedural execution pathsDavid Malcolm16-877/+799
Diagnostic path printing was added in r10-5901-g4bc1899b2e883f. As of that commit, with -fdiagnostics-path-format=inline-events (the default), we print a vertical line to the left of the source line numbering, visualizing the stack depth and interprocedural calls and returns as indentation changes. For cases where the events on a thread are purely interprocedural, this line does nothing except take up space and complicate the output. This patch adds logic to omit it for such cases, simpifying the output, and, I believe, improving readability. gcc/ChangeLog: * diagnostic-path.h: Update leading comment to reflect intraprocedural cases. Fix typo in comment. * doc/invoke.texi: Update intraprocedural example. gcc/testsuite/ChangeLog: * c-c++-common/analyzer/allocation-size-multiline-1.c: Update expected results for purely intraprocedural path. * c-c++-common/analyzer/allocation-size-multiline-2.c: Likewise. * c-c++-common/analyzer/allocation-size-multiline-3.c: Likewise. * c-c++-common/analyzer/analyzer-verbosity-0.c: Likewise. * c-c++-common/analyzer/analyzer-verbosity-1.c: Likewise. * c-c++-common/analyzer/analyzer-verbosity-2.c: Likewise. * c-c++-common/analyzer/analyzer-verbosity-3.c: Likewise. * c-c++-common/analyzer/malloc-macro-inline-events.c: Likewise. Doing so for this file requires a rewrite since the paths prefixing the "in expansion of macro" lines become the only thing on their line and so are no longer pruned by multiline.exp logic for pruning extra content on non-blank lines. * c-c++-common/analyzer/malloc-paths-9-noexcept.c: Likewise. * c-c++-common/analyzer/setjmp-2.c: Likewise. * gcc.dg/analyzer/malloc-paths-9.c: Likewise. * gcc.dg/analyzer/out-of-bounds-multiline-2.c: Likewise. * gcc.dg/plugin/diagnostic-test-paths-2.c: Likewise. gcc/ChangeLog: * tree-diagnostic-path.cc (per_thread_summary::interprocedural_p): New. (thread_event_printer::print_swimlane_for_event_range): Don't indent and print the stack depth line if this thread's events are purely intraprocedural. (selftest::test_intraprocedural_path): Update expected output. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-05-15diagnostics: handle SGR codes in line_label::m_display_widthDavid Malcolm1-11/+17
gcc/ChangeLog: * diagnostic-show-locus.cc: Define INCLUDE_VECTOR and include "text-art/types.h". (line_label::line_label): Drop "policy" argument. Use styled_string::calc_canvas_width when computing m_display_width, as this skips SGR codes. (layout::print_any_labels): Update for line_label ctor change. (selftest::test_one_liner_labels_utf8): Update expected text to reflect that the labels can fit on one line if we don't get confused by SGR colorization codes. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-05-16RISC-V: Add Zvfbfwma extension to the -march= optionXiao Zeng6-0/+113
This patch would like to add new sub extension (aka Zvfbfwma) to the -march= option. It introduces a new data type BF16. 1 In spec: "Zvfbfwma requires the Zvfbfmin extension and the Zfbfmin extension." 1.1 In Embedded Processor: Zvfbfwma -> Zvfbfmin -> Zve32f 1.2 In Application Processor: Zvfbfwma -> Zvfbfmin -> V 1.3 In both scenarios, there are: Zvfbfwma -> Zfbfmin 2 Zvfbfmin's information is in: <https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=1ddf65c5fc6ba7cf5826e1c02c569c923a541c09> 3 Zfbfmin's formation is in: <https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=35224ead63732a3550ba4b1332c06e9dc7999c31> 4 Depending on different usage scenarios, the Zvfbfwma extension may depend on 'V' or 'Zve32f'. This patch only implements dependencies in scenario of Embedded Processor. This is consistent with the processing strategy in Zvfbfmin. In scenario of Application Processor, it is necessary to explicitly indicate the dependent 'V' extension. 5 You can locate more information about Zvfbfwma from below spec doc: <https://github.com/riscv/riscv-bfloat16/releases/download/v59042fc71c31a9bcb2f1957621c960ed36fac401/riscv-bfloat16.pdf> gcc/ChangeLog: * common/config/riscv/riscv-common.cc: (riscv_implied_info): Add zvfbfwma item. (riscv_ext_version_table): Ditto. (riscv_ext_flag_table): Ditto. * config/riscv/riscv.opt: (MASK_ZVFBFWMA): New macro. (TARGET_ZVFBFWMA): Ditto. gcc/testsuite/ChangeLog: * gcc.target/riscv/arch-37.c: New test. * gcc.target/riscv/arch-38.c: New test. * gcc.target/riscv/predef-36.c: New test. * gcc.target/riscv/predef-37.c: New test.
2024-05-16Set d.one_operand_p to true when TARGET_SSSE3 in ix86_expand_vecop_qihi_partial.liuhongt2-1/+36
pshufb is available under TARGET_SSSE3, so ix86_expand_vec_perm_const_1 must return true when TARGET_SSSE3. With the patch under -march=x86-64-v2 v8qi foo (v8qi a) { return a >> 5; } < pmovsxbw %xmm0, %xmm0 < psraw $5, %xmm0 < pshufb .LC0(%rip), %xmm0 vs. > movdqa %xmm0, %xmm1 > pcmpeqd %xmm0, %xmm0 > pmovsxbw %xmm1, %xmm1 > psrlw $8, %xmm0 > psraw $5, %xmm1 > pand %xmm1, %xmm0 > packuswb %xmm0, %xmm0 Although there's a memory load from constant pool, but it should be better when it's inside a loop. The load from constant pool can be hoist out. it's 1 instruction vs 4 instructions. < pshufb .LC0(%rip), %xmm0 vs. > pcmpeqd %xmm0, %xmm0 > psrlw $8, %xmm0 > pand %xmm1, %xmm0 > packuswb %xmm0, %xmm0 gcc/ChangeLog: PR target/114514 * config/i386/i386-expand.cc (ix86_expand_vecop_qihi_partial): Set d.one_operand_p to true when TARGET_SSSE3. gcc/testsuite/ChangeLog: * gcc.target/i386/pr114514-shufb.c: New test.
2024-05-16Optimize ashift >> 7 to vpcmpgtb for vector int8.liuhongt2-0/+81
Since there is no corresponding instruction, the shift operation for vector int8 is implemented using the instructions for vector int16, but for some special shift counts, it can be transformed into vpcmpgtb. gcc/ChangeLog: PR target/114514 * config/i386/i386-expand.cc (ix86_expand_vec_shift_qihi_constant): Optimize ashift >> 7 to vpcmpgtb. (ix86_expand_vecop_qihi_partial): Ditto. gcc/testsuite/ChangeLog: * gcc.target/i386/pr114514-shift.c: New test.
2024-05-16Daily bump.GCC Administrator9-1/+346
2024-05-15Add missing hunk in recent change.Jeff Law1-0/+177
gcc/ * config/riscv/riscv-string.cc: Add missing hunk from last change.
2024-05-15analyzer: fix ICE seen with -fsanitize=undefined [PR114899]David Malcolm2-1/+17
gcc/analyzer/ChangeLog: PR analyzer/114899 * access-diagram.cc (written_svalue_spatial_item::get_label_string): Bulletproof against SSA_NAME_VAR being null. gcc/testsuite/ChangeLog: PR analyzer/114899 * c-c++-common/analyzer/out-of-bounds-diagram-pr114899.c: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-05-15[v2,2/2] RISC-V: strcmp expansion: Use adjust_address() for address calculationChristoph Müllner1-6/+4
We have an arch-independent routine to generate an address with an offset. Let's use that instead of doing the calculation in the backend. gcc/ChangeLog: * config/riscv/riscv-string.cc (emit_strcmp_scalar_load_and_compare): Use adjust_address() to calculate MEM-PLUS pattern.
2024-05-15[v2,1/2] RISC-V: Add cmpmemsi expansionChristoph Müllner7-14/+155
GCC has a generic cmpmemsi expansion via the by-pieces framework, which shows some room for target-specific optimizations. E.g. for comparing two aligned memory blocks of 15 bytes we get the following sequence: my_mem_cmp_aligned_15: li a4,0 j .L2 .L8: bgeu a4,a7,.L7 .L2: add a2,a0,a4 add a3,a1,a4 lbu a5,0(a2) lbu a6,0(a3) addi a4,a4,1 li a7,15 // missed hoisting subw a5,a5,a6 andi a5,a5,0xff // useless beq a5,zero,.L8 lbu a0,0(a2) // loading again! lbu a5,0(a3) // loading again! subw a0,a0,a5 ret .L7: li a0,0 ret Diff first byte: 15 insns Diff second byte: 25 insns No diff: 25 insns Possible improvements: * unroll the loop and use load-with-displacement to avoid offset increments * load and compare multiple (aligned) bytes at once * Use the bitmanip/strcmp result calculation (reverse words and synthesize (a2 >= a3) ? 1 : -1 in a branchless sequence) When applying these improvements we get the following sequence: my_mem_cmp_aligned_15: ld a5,0(a0) ld a4,0(a1) bne a5,a4,.L2 ld a5,8(a0) ld a4,8(a1) slli a5,a5,8 slli a4,a4,8 bne a5,a4,.L2 li a0,0 .L3: sext.w a0,a0 ret .L2: rev8 a5,a5 rev8 a4,a4 sltu a5,a5,a4 neg a5,a5 ori a0,a5,1 j .L3 Diff first byte: 11 insns Diff second byte: 16 insns No diff: 11 insns This patch implements this improvements. The tests consist of a execution test (similar to gcc/testsuite/gcc.dg/torture/inline-mem-cmp-1.c) and a few tests that test the expansion conditions (known length and alignment). Similar to the cpymemsi expansion this patch does not introduce any gating for the cmpmemsi expansion (on top of requiring the known length, alignment and Zbb). Bootstrapped and SPEC CPU 2017 tested. gcc/ChangeLog: * config/riscv/riscv-protos.h (riscv_expand_block_compare): New prototype. * config/riscv/riscv-string.cc (GEN_EMIT_HELPER2): New helper for zero_extendhi. (do_load_from_addr): Add support for HI and SI/64 modes. (do_load): Add helper for zero-extended loads. (emit_memcmp_scalar_load_and_compare): New helper to emit memcmp. (emit_memcmp_scalar_result_calculation): Likewise. (riscv_expand_block_compare_scalar): Likewise. (riscv_expand_block_compare): New RISC-V expander for memory compare. * config/riscv/riscv.md (cmpmemsi): New cmpmem expansion. gcc/testsuite/ChangeLog: * gcc.target/riscv/cmpmemsi-1.c: New test. * gcc.target/riscv/cmpmemsi-2.c: New test. * gcc.target/riscv/cmpmemsi-3.c: New test. * gcc.target/riscv/cmpmemsi.c: New test.
2024-05-15c++: ICE with reference NSDMI [PR114854]Marek Polacek2-5/+13
Here we crash on a cp_gimplify_expr/TARGET_EXPR assert: /* A TARGET_EXPR that expresses direct-initialization should have been elided by cp_gimplify_init_expr. */ gcc_checking_assert (!TARGET_EXPR_DIRECT_INIT_P (*expr_p)); the TARGET_EXPR in question is created for the NSDMI in: class Vector { int m_size; }; struct S { const Vector &vec{}; }; where we first need to create a Vector{} temporary, and then bind the vec reference to it. The temporary is represented by a TARGET_EXPR and it cannot be elided. When we create an object of type S, we get D.2848 = {.vec=(const struct Vector &) &TARGET_EXPR <D.2840, {.m_size=0}>} where the TARGET_EXPR is no longer direct-initializing anything. Fixed by not setting TARGET_EXPR_DIRECT_INIT_P in convert_like_internal/ck_user. PR c++/114854 gcc/cp/ChangeLog: * call.cc (convert_like_internal) <case ck_user>: Don't set TARGET_EXPR_DIRECT_INIT_P. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/nsdmi-aggr22.C: New test.
2024-05-15c++: DR 569, DR 1693: fun with semicolons [PR113760]Marek Polacek20-19/+480
Prompted by c++/113760, I started looking into a bogus "extra ;" warning in C++11. It quickly turned out that if I want to fix this for good, the fix will not be so small. This patch touches on DR 569, an extra ; at namespace scope should be allowed since C++11: struct S { }; ; // pedwarn in C++98 It also touches on DR 1693, which allows superfluous semicolons in class definitions since C++11: struct S { int a; ; // pedwarn in C++98 }; Note that a single semicolon is valid after a member function definition: struct S { void foo () {}; // only warns with -Wextra-semi }; There's a new function maybe_warn_extra_semi to handle all of the above in a single place. So now they all get a fix-it hint. -Wextra-semi turns on all "extra ;" diagnostics. Currently, options like -Wc++11-compat or -Wc++11-extensions are not considered. DR 1693 PR c++/113760 DR 569 gcc/c-family/ChangeLog: * c.opt (Wextra-semi): Initialize to -1. gcc/cp/ChangeLog: * parser.cc (extra_semi_kind): New. (maybe_warn_extra_semi): New. (cp_parser_declaration): Call maybe_warn_extra_semi. (cp_parser_member_declaration): Likewise. gcc/ChangeLog: * doc/invoke.texi: Update -Wextra-semi documentation. gcc/testsuite/ChangeLog: * g++.dg/diagnostic/semicolon1.C: New test. * g++.dg/diagnostic/semicolon10.C: New test. * g++.dg/diagnostic/semicolon11.C: New test. * g++.dg/diagnostic/semicolon12.C: New test. * g++.dg/diagnostic/semicolon13.C: New test. * g++.dg/diagnostic/semicolon14.C: New test. * g++.dg/diagnostic/semicolon15.C: New test. * g++.dg/diagnostic/semicolon16.C: New test. * g++.dg/diagnostic/semicolon17.C: New test. * g++.dg/diagnostic/semicolon2.C: New test. * g++.dg/diagnostic/semicolon3.C: New test. * g++.dg/diagnostic/semicolon4.C: New test. * g++.dg/diagnostic/semicolon5.C: New test. * g++.dg/diagnostic/semicolon6.C: New test. * g++.dg/diagnostic/semicolon7.C: New test. * g++.dg/diagnostic/semicolon8.C: New test. * g++.dg/diagnostic/semicolon9.C: New test.
2024-05-15c++: Optimize in maybe_clone_body aliases even when not at_eof [PR113208]Jakub Jelinek6-75/+78
This patch reworks the cdtor alias optimization, such that we can create aliases even when maybe_clone_body is called not at at_eof time, without trying to repeat it in maybe_optimize_cdtor. 2024-05-15 Jakub Jelinek <jakub@redhat.com> Jason Merrill <jason@redhat.com> PR lto/113208 * cp-tree.h (maybe_optimize_cdtor): Remove. * decl2.cc (tentative_decl_linkage): Call maybe_make_one_only for implicit instantiations of maybe in charge ctors/dtors declared inline. (import_export_decl): Don't call maybe_optimize_cdtor. (c_parse_final_cleanups): Formatting fixes. * optimize.cc (can_alias_cdtor): Adjust condition, for HAVE_COMDAT_GROUP && DECL_ONE_ONLY && DECL_WEAK return true even if not DECL_INTERFACE_KNOWN. (maybe_clone_body): Don't clear DECL_SAVED_TREE, instead set it to void_node. (maybe_clone_body): Remove. * decl.cc (cxx_comdat_group): For DECL_CLONED_FUNCTION_P functions if SUPPORTS_ONE_ONLY return DECL_COMDAT_GROUP if already set. * g++.dg/abi/comdat3.C: New test. * g++.dg/abi/comdat4.C: New test.
2024-05-15combine: Fix up simplify_compare_const [PR115092]Jakub Jelinek3-2/+43
The following testcases are miscompiled (with tons of GIMPLE optimization disabled) because combine sees GE comparison of 1-bit sign_extract (i.e. something with [-1, 0] value range) with (const_int -1) (which is always true) and optimizes it into NE comparison of 1-bit zero_extract ([0, 1] value range) against (const_int 0). The reason is that simplify_compare_const first (correctly) simplifies the comparison to GE (ashift:SI something (const_int 31)) (const_int -2147483648) and then an optimization for when the second operand is power of 2 triggers. That optimization is fine for power of 2s which aren't the signed minimum of the mode, or if it is NE, EQ, GEU or LTU against the signed minimum of the mode, but for GE or LT optimizing it into NE (or EQ) against const0_rtx is wrong, those cases are always true or always false (but the function doesn't have a standardized way to tell callers the comparison is now unconditional). The following patch just disables the optimization in that case. 2024-05-15 Jakub Jelinek <jakub@redhat.com> PR rtl-optimization/114902 PR rtl-optimization/115092 * combine.cc (simplify_compare_const): Don't optimize GE op0 SIGNED_MIN or LT op0 SIGNED_MIN into NE op0 const0_rtx or EQ op0 const0_rtx. * gcc.dg/pr114902.c: New test. * gcc.dg/pr115092.c: New test.
2024-05-15openmp: Diagnose using grainsize+num_tasks clauses together [PR115103]Jakub Jelinek5-4/+59
I've noticed that while we diagnose many other OpenMP exclusive clauses, we don't diagnose grainsize together with num_tasks on taskloop construct in all of C, C++ and Fortran (the implementation simply ignored grainsize in that case) and for Fortran also don't diagnose mixing nogroup clause with reduction clause(s). Fixed thusly. 2024-05-15 Jakub Jelinek <jakub@redhat.com> PR c/115103 gcc/c/ * c-typeck.cc (c_finish_omp_clauses): Diagnose grainsize used together with num_tasks. gcc/cp/ * semantics.cc (finish_omp_clauses): Diagnose grainsize used together with num_tasks. gcc/fortran/ * openmp.cc (resolve_omp_clauses): Diagnose grainsize used together with num_tasks or nogroup used together with reduction. gcc/testsuite/ * c-c++-common/gomp/clause-dups-1.c: Add 2 further expected errors. * gfortran.dg/gomp/pr115103.f90: New test.
2024-05-15tree-optimization/114589 - remove profile based sink heuristicsRichard Biener3-43/+42
The following removes the profile based heuristic limiting sinking and instead uses post-dominators to avoid sinking to places that are executed under the same conditions as the earlier location which the profile based heuristic should have guaranteed as well. To avoid regressing this moves the empty-latch check to cover all sink cases. It also stream-lines the resulting select_best_block a bit but avoids adjusting heuristics more with this change. gfortran.dg/streamio_9.f90 starts execute failing with this on x86_64 with -m32 because the (float)i * 9.9999...e-7 compute is sunk across a STOP causing it to be no longer spilled and thus the compare failing due to excess precision. The patch adds -ffloat-store to avoid this, following other similar testcases. This change fixes the testcase in the PR only when using -fno-ivopts as otherwise VRP is confused. PR tree-optimization/114589 * tree-ssa-sink.cc (select_best_block): Remove profile-based heuristics. Instead reject sink locations that sink to post-dominators. Move empty latch check here from statement_sink_location. Also consider early_bb for the loop depth check. (statement_sink_location): Remove superfluous check. Remove empty latch check. (pass_sink_code::execute): Compute/release post-dominators. * gfortran.dg/streamio_9.f90: Use -ffloat-store to avoid excess precision when not spilling. * g++.dg/tree-ssa/pr114589.C: New testcase.
2024-05-15middle-end/111422 - wrong stack var coalescing, handle PHIsRichard Biener1-4/+15
The gcc.c-torture/execute/pr111422.c testcase after installing the sink pass improvement reveals that we also need to handle _65 = &g + _58; _44 = &g + _43; # _59 = PHI <_65, _44> *_59 = 8; g = {v} {CLOBBER(eos)}; ... n[0] = &f; *_59 = 8; g = {v} {CLOBBER(eos)}; where we fail to see the conflict between n and g after the first clobber of g. Before the sinking improvement there was a conflict recorded on a path where _65/_44 are unused, so the real conflict was missed but the fake one avoided the miscompile. The following handles PHI defs in add_scope_conflicts_2 which fixes the issue. PR middle-end/111422 * cfgexpand.cc (add_scope_conflicts_2): Handle PHIs by recursing to their arguments.
2024-05-15PR modula2/115057 TextIO.ReadRestLine raises an exception when buffer is ↵Gaius Mulley6-7/+71
exceeded TextIO.ReadRestLine will raise an "attempting to read beyond end of file" exception if the buffer is exceeded. This bug is caused by the TextIO.ReadRestLine calling IOChan.Skip without a preceeding IOChan.Look. The Look procedure will update the status result whereas Skip always sets read result to allRight. gcc/m2/ChangeLog: PR modula2/115057 * gm2-libs-iso/TextIO.mod (ReadRestLine): Use ReadChar to skip unwanted characters as this calls IOChan.Look and updates the cid result status. A Skip without a Look does not update the status. Skip always sets read result to allRight. * gm2-libs-iso/TextUtil.def (SkipSpaces): Improve comments. (CharAvailable): Improve comments. * gm2-libs-iso/TextUtil.mod (SkipSpaces): Improve comments. (CharAvailable): Improve comments. gcc/testsuite/ChangeLog: PR modula2/115057 * gm2/isolib/run/pass/testrestline.mod: New test. * gm2/isolib/run/pass/testrestline2.mod: New test. * gm2/isolib/run/pass/testrestline3.mod: New test. Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>