aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2023-12-10c++: Implement __is_object built-in traitKen Matsui5-0/+42
This patch implements built-in trait for std::is_object. gcc/cp/ChangeLog: * cp-trait.def: Define __is_object. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_OBJECT. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_object. * g++.dg/ext/is_object.C: New test. Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
2023-12-10c++: Implement __is_function built-in traitKen Matsui5-0/+69
This patch implements built-in trait for std::is_function. gcc/cp/ChangeLog: * cp-trait.def: Define __is_function. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_FUNCTION. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_function. * g++.dg/ext/is_function.C: New test. Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
2023-12-10c++: Implement __is_reference built-in traitKen Matsui5-0/+45
This patch implements built-in trait for std::is_reference. gcc/cp/ChangeLog: * cp-trait.def: Define __is_reference. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_REFERENCE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_reference. * g++.dg/ext/is_reference.C: New test. Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
2023-12-10c++: Implement __is_member_object_pointer built-in traitKen Matsui5-0/+41
This patch implements built-in trait for std::is_member_object_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_object_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_OBJECT_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_member_object_pointer. * g++.dg/ext/is_member_object_pointer.C: New test. Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
2023-12-10c++: Implement __is_member_function_pointer built-in traitKen Matsui5-0/+42
This patch implements built-in trait for std::is_member_function_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_function_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_FUNCTION_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_member_function_pointer. * g++.dg/ext/is_member_function_pointer.C: New test. Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
2023-12-10c++: Implement __is_member_pointer built-in traitKen Matsui5-0/+41
This patch implements built-in trait for std::is_member_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_member_pointer. * g++.dg/ext/is_member_pointer.C: New test. Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
2023-12-10c++: Implement __is_scoped_enum built-in traitKen Matsui5-0/+78
This patch implements built-in trait for std::is_scoped_enum. gcc/cp/ChangeLog: * cp-trait.def: Define __is_scoped_enum. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SCOPED_ENUM. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_scoped_enum. * g++.dg/ext/is_scoped_enum.C: New test. Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
2023-12-10c++: Implement __is_bounded_array built-in traitKen Matsui5-0/+49
This patch implements built-in trait for std::is_bounded_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_bounded_array. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_BOUNDED_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_bounded_array. * g++.dg/ext/is_bounded_array.C: New test. Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
2023-12-10c++: Implement __is_array built-in traitKen Matsui5-0/+39
This patch implements built-in trait for std::is_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_array. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_array. * g++.dg/ext/is_array.C: New test. Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
2023-12-10c++: trait patch tweakJason Merrill1-12/+12
As Patrick suggested elsewhere, let's move this into the default case. gcc/cp/ChangeLog: * parser.cc (cp_parser_simple_type_specifier): Move trait handling to default label.
2023-12-10c++: Accept the use of built-in trait identifiersKen Matsui1-19/+34
This patch accepts the use of built-in trait identifiers when they are actually not used as traits. Specifically, we check if the subsequent token is '(' for ordinary built-in traits or is '<' only for the special __type_pack_element built-in trait. If those identifiers are used differently, the parser treats them as normal identifiers. This allows us to accept code like: struct __is_pointer {};. gcc/cp/ChangeLog: * parser.cc (cp_lexer_lookup_trait): Rename to ... (cp_lexer_peek_trait): ... this. Handle a subsequent token for the corresponding built-in trait. (cp_lexer_lookup_trait_expr): Rename to ... (cp_lexer_peek_trait_expr): ... this. (cp_lexer_lookup_trait_type): Rename to ... (cp_lexer_peek_trait_type): ... this. (cp_lexer_next_token_is_decl_specifier_keyword): Call cp_lexer_peek_trait_type. (cp_parser_simple_type_specifier): Likewise. (cp_parser_primary_expression): Call cp_lexer_peek_trait_expr. Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
2023-12-10c-family, c++: Look up built-in traits via identifier nodeKen Matsui6-65/+126
Since RID_MAX soon reaches 255 and all built-in traits are used approximately once in a C++ translation unit, this patch removes all RID values for built-in traits and uses the identifier node to look up the specific trait. Rather than holding traits as keywords, we set all trait identifiers as cik_trait, which is a new cp_identifier_kind. As cik_reserved_for_udlit was unused and cp_identifier_kind is 3 bits, we replaced the unused field with the new cik_trait. Also, the later patch handles a subsequent token to the built-in identifier so that we accept the use of non-function-like built-in trait identifiers. gcc/c-family/ChangeLog: * c-common.cc (c_common_reswords): Remove all mappings of built-in traits. * c-common.h (enum rid): Remove all RID values for built-in traits. gcc/cp/ChangeLog: * cp-objcp-common.cc (names_builtin_p): Remove all RID value cases for built-in traits. Check for built-in traits via the new cik_trait kind. * cp-tree.h (enum cp_trait_kind): Set its underlying type to addr_space_t. (struct cp_trait): New struct to hold trait information. (cp_traits): New array to hold a mapping to all traits. (cik_reserved_for_udlit): Rename to ... (cik_trait): ... this. (IDENTIFIER_ANY_OP_P): Exclude cik_trait. (IDENTIFIER_TRAIT_P): New macro to detect cik_trait. * lex.cc (cp_traits): Define its values, declared in cp-tree.h. (init_cp_traits): New function to set cik_trait and IDENTIFIER_CP_INDEX for all built-in trait identifiers. (cxx_init): Call init_cp_traits function. * parser.cc (cp_lexer_lookup_trait): New function to look up a built-in trait by IDENTIFIER_CP_INDEX. (cp_lexer_lookup_trait_expr): Likewise, look up an expression-yielding built-in trait. (cp_lexer_lookup_trait_type): Likewise, look up a type-yielding built-in trait. (cp_keyword_starts_decl_specifier_p): Remove all RID value cases for built-in traits. (cp_lexer_next_token_is_decl_specifier_keyword): Handle type-yielding built-in traits. (cp_parser_primary_expression): Remove all RID value cases for built-in traits. Handle expression-yielding built-in traits. (cp_parser_trait): Handle cp_trait instead of enum rid. (cp_parser_simple_type_specifier): Remove all RID value cases for built-in traits. Handle type-yielding built-in traits. Co-authored-by: Patrick Palka <ppalka@redhat.com> Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
2023-12-10c++: Sort built-in traits alphabeticallyKen Matsui4-121/+121
This patch sorts built-in traits alphabetically for better code readability. gcc/cp/ChangeLog: * constraint.cc (diagnose_trait_expr): Sort built-in traits alphabetically. * cp-trait.def: Likewise. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. (finish_trait_type): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Sort built-in traits alphabetically. Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
2023-12-10[committed] Support uaddv and usubv on the H8Jeff Law1-0/+77
This patch adds uaddv/usubv support on the H8 port to speed up those pesky builtin-overflow tests. It's a variant of something I'd been running for a while -- the major change between the old approach I'd been using and this patch is this version does not expose the CC register until after reload to be consistent with the rest of the H8 port. The general approach is to first clear the GPR that's going to hold the overflow status, perform the arithmetic operation (add/sub), then use addx to move the overflow indicator (in the C bit) into the GPR holding the overflow status. That's a significant improvement over the mess of logicals that's generated by the generic code. Handling signed overflow is possible and something I'll probably port to this scheme at some point. It's a bit more complex because we can't trivially move the bit from CCR into the right position in a GPR and other quirks of the H8. This has been regression tested on the H8 without problems. Pushing to the trunk. gcc/ * config/h8300/addsub.md (uaddv<mode>4, usubv<mode>4): New expanders. (uaddv): New define_insn_and_split plus post-reload pattern.
2023-12-10[committed] Provide patterns for signed bitfield extractions on H8Jeff Law3-1/+113
Inspired by Roger's work on the ARC port, this patch provides a define_and_split pattern to optimize sign extended bitfields starting at position 0 using an approach that doesn't require shifting. It then builds on that to provide another define_and_split pattern to support arbitrary signed bitfield extractions -- it uses a right logical shift to move the bitfield into position 0, then the specialized pattern above to sign extend the MSB of the field through the rest of the register. This is often, but certainly not always, better than a two shift approach. The code uses the sizes of the sequences to select between the two shift approach and single shift with extension from an arbitrary location approach. There's certainly further improvements that could be made here, but I think we're getting the bulk of the improvements already. Regression tested on the H8 port without errors. Installing on the trunk. gcc/ * config/h8300/h8300-protos.h (use_extvsi): Prototype. * config/h8300/combiner.md: Two new define_insn_and_split patterns to implement signed bitfield extractions. * config/h8300/h8300.cc (use_extvsi): New function.
2023-12-10[committed] Fix length computation of single bit bitfield extraction on H8Jeff Law1-1/+1
Various approaches are used to optimize extracting a sign extended single bit bitfield. The length computation of 10 bytes was conservatively correct, but inaccurate. In particular when the bit we want is in the low half word we don't need the move high half to low half instruction. Account for that in the length computation. This was spotted when looking at regressions in the generalized signed bitfield extraction pattern. This has been regression tested on the H8 port. gcc/ * config/h8300/combiner.md (single bit signed bitfield extraction): Fix length computation when the bit we want is in the low half word.
2023-12-10[committed] Fix length computation for logical shifts on H8Jeff Law1-0/+5
This fixes the length computation for logical shifts on the H8/SX. The H8/SX has a richer set of logical shifts compared to early parts in the H8 family. It has special 2 byte instructions for shifts by power of two immediate values as well as a special 4 byte shift by other immediate values. These were never accounted for (AFIACT) in the length computation for shifts. Until now that's mostly just affected branch shortening. But an upcoming patch uses instruction lengths to select between two potential sequences and getting these lengths wrong will cause it to miss optimization opportunities on the H8/SX. gcc * config/h8300/h8300.cc (compute_a_shift_length): Fix computation of logical shifts on the H8/SX.
2023-12-10Daily bump.GCC Administrator5-1/+80
2023-12-09phiopt: Fix ICE with large --param l1-cache-line-size= [PR112887]Jakub Jelinek2-4/+16
This function is never called when param_l1_cache_line_size is 0, but it uses int and unsigned int variables to hold alignment in bits, so for large param_l1_cache_line_size it is zero and e.g. DECL_ALIGN () % param_align_bits can divide by zero. Looking at the code, the function uses tree_fits_uhwi_p on the trees before converting them using tree_to_uhwi to int variables, which looks just wrong, either it would need to punt if it doesn't fit into those and also check for overflows during the computation, or use unsigned HOST_WIDE_INT for all of this. That also fixes the division by zero, as param_l1_cache_line_size maximum is INT_MAX, that multiplied by 8 will always fit. 2023-12-09 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/112887 * tree-ssa-phiopt.cc (hoist_adjacent_loads): Change type of param_align, param_align_bits, offset1, offset2, size2 and align1 variables from int or unsigned int to unsigned HOST_WIDE_INT. * gcc.dg/pr112887.c: New test.
2023-12-09testsuite: Add testcase for already fixed PR [PR112924]Jakub Jelinek1-0/+26
This testcase got fixed with r14-6132-g50f2a3370d177f8fe9bea0461feb710523e048a2 . I'm just adding a testcase so that it doesn't reappear. 2023-12-09 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/112924 * gcc.dg/pr112924.c: New test.
2023-12-09libstdc++: Fix value of __cpp_lib_format macro [PR111826]Jonathan Wakely3-69/+67
As noted in the PR, we support both features required for the 202110L value, so we should define it with that value. libstdc++-v3/ChangeLog: PR libstdc++/111826 * include/bits/version.def (format): Update value. * include/bits/version.h: Regenerate. * testsuite/std/format/functions/format.cc:
2023-12-09libstdc++: Fix resolution of LWG 4016 for std::ranges::to [PR112876]Jonathan Wakely2-13/+9
What I implemented in r14-6199-g45630fbcf7875b does not match what I proposed for LWG 4016, and it imposes additional, unwanted requirements on the emplace and insert member functions of the container being populated. libstdc++-v3/ChangeLog: PR libstdc++/112876 * include/std/ranges (ranges::to): Do not try to use an iterator returned by the container's emplace or insert member functions. * testsuite/std/ranges/conv/1.cc (Cont4::emplace, Cont4::insert): Use the iterator parameter. Do not return an iterator.
2023-12-09driver: Fix memory leak [PR93019]Jakub Jelinek1-0/+1
driver:finalize used by JIT clears the mdswitches pointer; if it was allocated before, that leaks the memory. 2023-12-09 Costas Argyris <costas.argyris@gmail.com> Jakub Jelinek <jakub@redhat.com> PR driver/93019 * gcc.cc (driver::finalize): Call XDELETEVEC on mdswitches before clearing it. Signed-off-by: Costas Argyris <costas.argyris@gmail.com>
2023-12-09c++: Don't diagnose ignoring of attributes if all ignored attributes are ↵Jakub Jelinek6-9/+75
attribute_ignored_p There is another thing I wonder about: with -Wno-attributes= we are supposed to ignore the attributes altogether, but we are actually still warning about them when we emit these generic warnings about ignoring all attributes which appertain to this and that (perhaps with some exceptions we first remove from the attribute chain), like: void foo () { [[foo::bar]]; } with -Wattributes -Wno-attributes=foo::bar Shouldn't we call some helper function in cases like this and warn not when std_attrs (or how the attribute chain var is called) is non-NULL, but if it is non-NULL and contains at least one non-attribute_ignored_p attribute? I've kept warnings for cases where the C++ standard says explicitly any attributes aren't ok - "If an attribute-specifier-seq appertains to a friend declaration, that declaration shall be a definition." or https://eel.is/c++draft/dcl.type.elab#3 or https://eel.is/c++draft/temp.spec#temp.explicit-3 For some changes I haven't figured out how could I cover it in the testsuite. Note, C uses a different strategy, it has c_warn_unused_attributes function which warns about all the attributes one by one unless they are ignored (or allowed in certain position). Though that is just a single diagnostic wording, while C++ FE just warns that there are some ignored attributes and doesn't name them individually (except for namespace and using namespace) and uses different wordings in different spots. 2023-12-09 Jakub Jelinek <jakub@redhat.com> gcc/ * attribs.h (any_nonignored_attribute_p): Declare. * attribs.cc (any_nonignored_attribute_p): New function. gcc/cp/ * parser.cc (cp_parser_statement, cp_parser_expression_statement, cp_parser_declaration, cp_parser_asm_definition): Don't diagnose ignored attributes if !any_nonignored_attribute_p. * decl.cc (grokdeclarator): Likewise. * name-lookup.cc (handle_namespace_attrs, finish_using_directive): Don't diagnose ignoring of attr_ignored_p attributes. gcc/testsuite/ * g++.dg/warn/Wno-attributes-1.C: New test.
2023-12-09RISC-V: Fix VLS mode movmiaslign bugJuzhe-Zhong3-25/+70
PR112932 let me notice there is a bug of current VLS mode misalign pattern. Adapt it same as VLA mode. Commited as it is obvious fix. PR target/112932 gcc/ChangeLog: * config/riscv/vector.md (movmisalign<mode>): Fix VLSmode bugs. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/vls/misalign-1.c: Ditto. * gcc.target/riscv/rvv/autovec/pr112932.c: New test.
2023-12-09testsuite: Remove gcc.dg/tree-ssa/scev-3.c -4.c and 5.cHans-Peter Nilsson3-137/+0
These tests were recently xfailed on ilp32 targets though passing on almost all ilp32 targets (known exceptions: ia32 and some arm subtargets). They've been changed around too much to remain useful. PR testsuite/112786 * gcc.dg/tree-ssa/scev-3.c, gcc.dg/tree-ssa/scev-4.c, gcc.dg/tree-ssa/scev-5.c: Remove.
2023-12-08strub: skip emutls after strubm errorsAlexandre Oliva1-1/+2
The emutls pass requires PROP_ssa, but if the strubm pass (or any other pre-SSA pass) issues errors, all of the build_ssa_passes are skipped, so the property is not set, but emutls still attempts to run, on targets that use it, despite earlier errors, so it hits the unsatisfied requirement. Adjust emutls to be skipped in case of earlier errors. for gcc/ChangeLog * tree-emutls.cc: Include diagnostic-core.h. (pass_ipa_lower_emutls::gate): Skip if errors were seen.
2023-12-09Daily bump.GCC Administrator8-1/+1059
2023-12-08c++: decltype of (non-captured variable) [PR83167]Patrick Palka2-67/+59
For decltype((x)) within a lambda where x is not captured, we dubiously require that the lambda has a capture default, unlike for decltype(x). But according to [expr.prim.id.unqual]/3 we should just ignore the lambda in this case. This patch narrowly fixes this issue by disabling the capture_decltype handling and falling back to the ordinary handling when the innermost lambda has no capture-default. In fact, we can restrict the special handling to only by-copy lambdas since that's what [expr.prim.id.unqual]/3 is concerned with; for by-ref implicit captures both code paths should give the same result anyway. During review some other issues were discovered which are documented in a new FIXME. PR c++/83167 gcc/cp/ChangeLog: * semantics.cc (capture_decltype): Inline into its only caller ... (finish_decltype_type): ... here. Update nearby comment to refer to recent standard. Add FIXME. Restrict uncaptured variable type transformation to happen only for lambdas with a by-copy capture-default. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/lambda/lambda-decltype4.C: New test.
2023-12-08analyzer: avoid taint for (TAINTED % NON_TAINTED)David Malcolm2-1/+16
gcc/analyzer/ChangeLog: * sm-taint.cc (taint_state_machine::alt_get_inherited_state): Fix handling of TRUNC_MOD_EXPR. gcc/testsuite/ChangeLog: * c-c++-common/analyzer/taint-modulus-1.c: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-12-08analyzer: fix ICE on infoleak with poisoned sizeDavid Malcolm4-13/+66
gcc/analyzer/ChangeLog: * region-model.cc (contains_uninit_p): Only check for svalues that the infoleak warning can handle. gcc/testsuite/ChangeLog: * gcc.dg/plugin/infoleak-uninit-size-1.c: New test. * gcc.dg/plugin/infoleak-uninit-size-2.c: New test. * gcc.dg/plugin/plugin.exp: Add the new tests. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-12-08[PR112875][LRA]: Fix an assert in lra elimination codeVladimir N. Makarov2-0/+37
PR112875 test ran into a wrong assert (gcc_unreachable) in elimination in a debug insn. The insn seems ok. So I change the assertion. To be more accurate I made it the same as analogous reload pass code. gcc/ChangeLog: PR rtl-optimization/112875 * lra-eliminations.cc (lra_eliminate_regs_1): Change an assert. Add ASM_OPERANDS case. gcc/testsuite/ChangeLog: PR rtl-optimization/112875 * gcc.target/i386/pr112875.c: New test.
2023-12-08c++: Fix parsing [[]][[]];Jakub Jelinek2-3/+20
When working on the previous patch I put [[]] [[]] asm (""); into a testcase, but was surprised it wasn't parsed. The problem is that when cp_parser_std_attribute_spec returns NULL, it can mean 2 different things, one is that the next token(s) are neither [[ nor alignas (in that case the caller should break from the loop), or when we parsed something like [[]] - it was valid attribute specifier, but didn't specify any attributes in it. The following patch fixes that by using a magic value of void_list_node for the case where the first tokens are neither [[ nor alignas and so where cp_parser_std_attribute_spec_seq should stop iterating to differentiate it from NULL_TREE which stands for some attribute specifier has been parsed, but it didn't contain any (or any valid) attributes. 2023-12-08 Jakub Jelinek <jakub@redhat.com> * parser.cc (cp_parser_std_attribute_spec): Return void_list_node rather than NULL_TREE if token is neither CPP_OPEN_SQUARE nor RID_ALIGNAS CPP_KEYWORD. (cp_parser_std_attribute_spec_seq): For attr_spec == void_list_node break, for attr_spec == NULL_TREE continue. * g++.dg/cpp0x/gen-attrs-79.C: New test.
2023-12-08c++: Unshare folded SAVE_EXPR arguments during cp_fold [PR112727]Jakub Jelinek2-1/+25
The following testcase is miscompiled because two ubsan instrumentations run into each other. The first one is the shift instrumentation. Before the C++ FE calls it, it wraps the 2 shift arguments with cp_save_expr, so that side-effects in them aren't evaluated multiple times. And, ubsan_instrument_shift itself uses unshare_expr on any uses of the operands to make sure further modifications in them don't affect other copies of them (the only not unshared ones are the one the caller then uses for the actual operation after the instrumentation, which means there is no tree sharing). Now, if there are side-effects in the first operand like say function call, cp_save_expr wraps it into a SAVE_EXPR, and ubsan_instrument_shift in this mode emits something like if (..., SAVE_EXPR <foo ()>, SAVE_EXPR <op1> > const) __ubsan_handle_shift_out_of_bounds (..., SAVE_EXPR <foo ()>, ...); and caller adds SAVE_EXPR <foo ()> << SAVE_EXPR <op1> after it in a COMPOUND_EXPR. So far so good. If there are no side-effects and cp_save_expr doesn't create SAVE_EXPR, everything is ok as well because of the unshare_expr. We have if (..., SAVE_EXPR <op1> > const) __ubsan_handle_shift_out_of_bounds (..., ptr->something[i], ...); and ptr->something[i] << SAVE_EXPR <op1> where ptr->something[i] is unshared. In the testcase below, the !x->s[j] ? 1 : 0 expression is wrapped initially into a SAVE_EXPR though, and unshare_expr doesn't unshare SAVE_EXPRs nor anything used in them for obvious reasons, so we end up with: if (..., SAVE_EXPR <!(bool) VIEW_CONVERT_EXPR<const struct S *>(x)->s[j] ? 1 : 0>, SAVE_EXPR <op1> > const) __ubsan_handle_shift_out_of_bounds (..., SAVE_EXPR <!(bool) VIEW_CONVERT_EXPR<const struct S *>(x)->s[j] ? 1 : 0>, ...); and SAVE_EXPR <!(bool) VIEW_CONVERT_EXPR<const struct S *>(x)->s[j] ? 1 : 0> << SAVE_EXPR <op1> So far good as well. But later during cp_fold of the SAVE_EXPR we find out that VIEW_CONVERT_EXPR<const struct S *>(x)->s[j] ? 0 : 1 is actually invariant (has TREE_READONLY set) and so cp_fold simplifies the above to if (..., SAVE_EXPR <op1> > const) __ubsan_handle_shift_out_of_bounds (..., (bool) VIEW_CONVERT_EXPR<const struct S *>(x)->s[j] ? 0 : 1, ...); and ((bool) VIEW_CONVERT_EXPR<const struct S *>(x)->s[j] ? 0 : 1) << SAVE_EXPR <op1> with the s[j] ARRAY_REFs and other expressions shared in between the two uses (and obviously the expression optimized away from the COMPOUND_EXPR in the if condition. Then comes another ubsan instrumentation at genericization time, this time to instrument the ARRAY_REFs with strict bounds checking, and replaces the s[j] in there with s[.UBSAN_BOUNDS (0B, SAVE_EXPR<j>, 8), SAVE_EXPR<j>] As the trees are shared, it does that just once though. And as the if body is gimplified first, the SAVE_EXPR<j> is evaluated inside of the if body and when it is used again after the if, it uses a potentially uninitialized value of j.1 (always uninitialized if the shift count isn't out of bounds). The following patch fixes that by unshare_expr unsharing the folded argument of a SAVE_EXPR if we've folded the SAVE_EXPR into an invariant and it is used more than once. 2023-12-08 Jakub Jelinek <jakub@redhat.com> PR sanitizer/112727 * cp-gimplify.cc (cp_fold): If SAVE_EXPR has been previously folded, unshare_expr what is returned. * c-c++-common/ubsan/pr112727.c: New test.
2023-12-08c++: Add fixed test [PR88848]Marek Polacek1-0/+35
This one was fixed by r12-7714-g47da5198766256. PR c++/88848 gcc/testsuite/ChangeLog: * g++.dg/inherit/multiple2.C: New test.
2023-12-08c++: guard more against undiagnosed error_mark_node [PR112658]Patrick Palka1-0/+3
This adds a sanity check to cp_parser_expression_statement similar to the one in finish_expr_stmt added by r6-6795-g0fd9d4921f7ba2, which effectively downgrades accepts-invalid/wrong-code bugs like this one into ice-on-invalid/ice-on-valid ones. PR c++/112658 gcc/cp/ChangeLog: * parser.cc (cp_parser_expression_statement): If the statement is error_mark_node, make sure we've seen_error().
2023-12-08c++: undiagnosed error_mark_node from cp_build_c_cast [PR112658]Patrick Palka2-1/+14
When cp_build_c_cast commits to an erroneous const_cast, we neglect to replay errors from build_const_cast_1 which can lead to us incorrectly accepting (and "miscompiling") the cast, or triggering the assert in finish_expr_stmt. This patch fixes this oversight. This was the original fix for the ICE in PR112658 before r14-5941-g305a2686c99bf9 made us accept the testcase there after all. I wasn't able to come up with an alternate testcase for which this fix has an effect anymore, but below is a reduced version of the PR112658 testcase (accepted ever since r14-5941) for good measure. PR c++/112658 PR c++/94264 gcc/cp/ChangeLog: * typeck.cc (cp_build_c_cast): If we're committed to a const_cast and the result is erroneous, call build_const_cast_1 a second time to issue errors. Use complain=tf_none instead of =false. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist-array20.C: New test.
2023-12-08RISC-V: Add vectorized strcmp and strncmp.Robin Dapp7-5/+357
This patch adds vectorized strcmp and strncmp implementations and tests. Similar to strlen, expansion is still guarded by -minline-str(n)cmp. gcc/ChangeLog: PR target/112109 * config/riscv/riscv-protos.h (expand_strcmp): Declare. * config/riscv/riscv-string.cc (riscv_expand_strcmp): Add strategy handling and delegation to scalar and vector expanders. (expand_strcmp): Vectorized implementation. * config/riscv/riscv.md: Add TARGET_VECTOR to strcmp and strncmp expander. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/builtin/strcmp-run.c: New test. * gcc.target/riscv/rvv/autovec/builtin/strcmp.c: New test. * gcc.target/riscv/rvv/autovec/builtin/strncmp-run.c: New test. * gcc.target/riscv/rvv/autovec/builtin/strncmp.c: New test.
2023-12-08RISC-V: Add vectorized strlen.Robin Dapp5-12/+83
This patch implements a vectorized strlen by re-using and slightly adjusting the rawmemchr implementation. Rawmemchr returns the address of the needle while strlen returns the difference between needle address and start address. As before, strlen expansion is guarded by -minline-strlen. While testing with -minline-strlen I encountered a vsetvl problem in memcpy-chk.c where we didn't insert a vsetvl at the proper spot (after a setjmp). This needs to be fixed separately and I figured I'd post this patch as-is. gcc/ChangeLog: PR target/112109 * config/riscv/riscv-protos.h (expand_rawmemchr): Add strlen parameter. * config/riscv/riscv-string.cc (riscv_expand_strlen): Call rawmemchr. (expand_rawmemchr): Add strlen handling. * config/riscv/riscv.md: Add TARGET_VECTOR to strlen expander. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/builtin/strlen-run.c: New test. * gcc.target/riscv/rvv/autovec/builtin/strlen.c: New test.
2023-12-08aarch64: Some tweaks to the early-ra passRichard Sandiford2-20/+184
early-ra's likely_operand_match_p didn't handle relaxed and special memory constraints, which meant that the pass wasn't able to match LD1RQ instructions to their constraints, and so backed out of trying to allocate. This patch fixes that by switching the sense of the match: does the rtx seem appropriate for the constraint?, rather than: does the constraint seem appropriate for the rtx? Also, I came across a case that needed more general equivalence detection. Previously we would only record equivalences after the last definition of the source register, but it's worth trying to handle cases where the destination register's live range is restricted to a block, and the next definition of the source occurs only after the end of the destination register's live range. The patch also fixes a cut-&-pasto that Alex noticed (thanks). gcc/ * config/aarch64/aarch64-early-ra.cc (allocno_info::chain_next): Put into an enum with... (allocno_info::last_def_point): ...new member variable. (allocno_info::m_current_bb_point): New member variable. (likely_operand_match_p): Switch based on get_constraint_type, rather than based on rtx code. Handle relaxed and special memory constraints. (early_ra::record_copy): Allow the source of an equivalence to be assigned to more than once. (early_ra::record_allocno_use): Invalidate any previous equivalence. Initialize last_def_point. (early_ra::record_allocno_def): Set last_def_point. (early_ra::valid_equivalence_p): New function, split out from... (early_ra::record_copy): ...here. Use last_def_point to handle source registers that have a later definition. (make_pass_aarch64_early_ra): Fix comment. gcc/testsuite/ * gcc.target/aarch64/sme/strided_2.c: New test.
2023-12-08Revert "arm: vld1q_types_x2 ACLE intrinsics"Richard Earnshaw7-247/+0
This reverts commit a1a0cdf21bb6a076e98658d815645d8ad1193840.
2023-12-08Revert "arm: vld1q_types_x3 ACLE intrinsics"Richard Earnshaw7-236/+3
This reverts commit 2514a331835e055a963fd059dc5770e5ae500af0.
2023-12-08Revert "arm: vld1q_types_x4 ACLE intrinsics"Richard Earnshaw7-236/+0
This reverts commit ac827ec3e600bcb636f564876b186ee19d384a1e.
2023-12-08Revert "arm: vst1_types_x2 ACLE intrinsics"Richard Earnshaw7-231/+0
This reverts commit a69a7c7b6782c5b6f213f1f34af8dbb6541f27bb.
2023-12-08Revert "arm: vst1_types_x3 ACLE intrinsics"Richard Earnshaw7-202/+7
This reverts commit ef07ae652c25ec04c2e3ef8cec14b0771a809861.
2023-12-08Revert "arm: vst1_types_x4 ACLE intrinsics"Richard Earnshaw7-200/+7
This reverts commit 2f48d846c794ba091b266133f73717361096d454.
2023-12-08Revert "arm: vst1q_types_x2 ACLE intrinsics"Richard Earnshaw8-232/+3
This reverts commit 2cd0d0261ef9d0e13e20407f131f32dcb67fcdd3.
2023-12-08Revert "arm: vst1q_types_x3 ACLE intrinsics"Richard Earnshaw7-217/+0
This reverts commit 2d58d53c9e0eed83faa9254f8d3ec0ddd54812d8.
2023-12-08Revert "arm: vst1q_types_x4 ACLE intrinsics"Richard Earnshaw7-219/+1
This reverts commit 4ad77f883c178679f1dbb3a5603f811e022080bb.
2023-12-08Revert "arm: vld1_types_x2 ACLE intrinsics"Richard Earnshaw7-254/+20
This reverts commit 8fff3f065277f13176c320f22c4ed766a82c5d8e.