Most ref-count updates in the COW string are done via the functions in
<ext/atomicity.h>, which will use non-atomic ops when the program is
known to be single-threaded. The _M_is_leaked() and _M_is_shared()
functions use __atomic_load_n directly, because <ext/atomicity.h>
doesn't provide a load operation. Those functions can check the
__is_single_threaded() predicate to avoid using __atomic_load_n when not
needed.
The move constructor for the fully-dynamic-string increments the
ref-count by either 2 or 1, for leaked or non-leaked strings
respectively. That can be changed to use a non-atomic store of 1 for all
non-shared strings. It can be non-atomic because even if the program is
multi-threaded, conflicting access to the rvalue object while it's being
moved from would be data race anyway. It can store 1 directly for all
non-shared strings because it doesn't matter whether the initial
refcount was -1 or 0, it should be 1 after the move constructor creates
a second owner.
libstdc++-v3/ChangeLog:
* include/bits/cow_string.h (basic_string::_M_is_leaked): Use
non-atomic load when __is_single_threaded() is true.
(basic_string::_M_is_shared): Likewise.
(basic_string::(basic_string&&)) [_GLIBCXX_FULLY_DYNAMIC_STRING]:
Use non-atomic store when rvalue is not shared.
When using COW strings, accessing _M_pathname[0] and similar non-const
accessors can cause the string to "leak", meaning it reallocates itself
if it shares ownership with another string object.
This causes test failures for --enable-fully-dynamic-string builds:
/home/jwakely/src/gcc/libstdc++-v3/testsuite/experimental/filesystem/path/construct/90634.cc:62: void test01(): Assertion 'bytes_allocated == 0' failed.
FAIL: experimental/filesystem/path/construct/90634.cc execution test
This FAIL happens because the fully-dynamic move constructor results in
shared ownership, so for path(std::move(std::string("foo"))) the
_M_pathname member shares ownership with the temporary, and the
non-const accesses in _M_split_cmpts() cause a new copy of the string to
be allocated. This un-sharing is wasteful, and entirely unnecessary when
sharing ownership with an rvalue that is about to release its ownership
anyway. Even for lvalues, sharing ownership is not a problem and
reallocating a unique copy of the string is wasteful.
This removes non-const accesses of _M_pathname in the
path::_M_split_cmpts() members.
libstdc++-v3/ChangeLog:
* src/c++17/fs_path.cc (path::_M_split_cmpts()): Remove
micro-optimization for "/" path.
* src/filesystem/path.cc (path::_M_split_cmpts()): Only access
the contents of _M_pathname using const member functions.
When checking for compatible stmts, vect_build_slp_tree_1 did:
&& !(STMT_VINFO_GROUPED_ACCESS (stmt_info)
&& (first_stmt_code == ARRAY_REF
|| first_stmt_code == BIT_FIELD_REF
|| first_stmt_code == INDIRECT_REF
|| first_stmt_code == COMPONENT_REF
|| first_stmt_code == MEM_REF)))
That is, it allowed any rhs_code as long as the first_stmt_code
looked valid. This had the effect of allowing IFN_MASK_LOAD
to be paired with an earlier non-call code (but didn't allow
the reverse).
This patch makes the check symmetrical.
gcc/
PR tree-optimization/103517
* tree-vect-slp.c (vect_build_slp_tree_1): When allowing two
different component references, check the codes of both them,
rather than just the first.
gcc/testsuite/
PR tree-optimization/103517
* gcc.dg/vect/pr103517.c: New test.
gcc/ChangeLog:
* doc/install.texi (Prerequisites): Add note that D front end now
requires GDC installed in order to bootstrap.
(Building): Add D compiler section, referencing prerequisites.
Adds documentation for the following:
- New switch that controls what code is generated on a contract
failure (throw or abort).
- New switch that controls mangling of D types in `extern(C++)`
code, as well as setting the compile-time value of
`__traits(getTargetInfo "cppStd")`
- New switches that generate C++ headers from D source files.
- New switch to save expanded mixins to a file.
- New switches that now distinguish between D language changes that
are either (a) an experimental feature or an upcoming breaking
change, (b) a warning or help on an upcoming change, or (c) revert
of a change for users who don't want to deal with the breaking
change for now.
gcc/d/ChangeLog:
* gdc.texi (Runtime Options): Document -fcheckaction=, -fextern-std=,
-fpreview=, -frevert=.
(Code Generation): Document -fdump-c++-spec=, -fdump-c++-spec-verbose,
-fsave-mixins=.
(Warnings): Update list of supported -ftransitions=.
gcc/ada/
* einfo.ads (E_Decimal_Fixed_Point_Subtype): Fix pasto.
* freeze.adb (Freeze_Fixed_Point_Type): Retrieve the underlying type
of the first subtype and do not use a stale value of Small_Value.
* sem_res.adb (Resolve_Real_Literal): In the case of a fixed-point
type, make sure that the base type is frozen and use its Small_Value
to compute the corresponding integer value of the literal.
gcc/ada/
* doc/gnat_rm/implementation_defined_pragmas.rst: Add
documentation of the new form of formal subprogram default in
the section on language extensions (pragma Extensions_Allowed).
* gnat_rm.texi: Regenerate.
* gen_il-gen-gen_nodes.adb: Add Expression as a syntactic field
of N_Formal_(Abstract|Concrete)_Subprogram_Declaration nodes.
* par-ch12.adb (P_Formal_Subprogram_Declaration): Add parsing
support for the new default of a parenthesized expression for
formal functions. Issue an error when extensions are not
allowed, suggesting use of -gnatX. Update comment with extended
syntax for SUBPROGRAM_DEFAULT.
* sem_ch12.adb (Analyze_Formal_Subprogram_Declaration): Issue an
error when an expression default is given for an abstract formal
function. When a default expression is present for a formal
function, install the function's formals and preanalyze the
expression.
(Instantiate_Formal_Subprogram): Fix typo in RM paragraph in a
comment. When a formal function has a default expression,
create a body for the function that will evaluate the expression
and will be called when the default applies in an instantiation.
The implicit function is marked as inlined and as having
convention Intrinsic.
gcc/ada/
* sem_elab.adb (Previous_Suitable_Construct): New function declared
in the Early_Call_Region_Processor package.
(Find_ECR): Call it to get the previous node at the start.
(Include): Call it to get the previous node during the traversal.
gcc/ada/
* sem_prag.adb (Process_Compile_Time_Warning_Or_Error): Do not
follow the Corresponding_Spec pointer if Acts_As_Spec is True,
because Corresponding_Spec is Empty in that case, so we would
exit the loop prematurely, and incorrectly think we are not
inside a generic unit when we are.
gcc/ada/
* sem_ch12.adb (Freeze_Subprogram_Body): Rename into...
(Freeze_Subprogram_Instance): ...this and change the name of the
first parameter and local variables for the sake of consistency.
(Insert_Freeze_Node_For_Instance): Use local variable Par_Inst.
(Install_Body): Rename into...
(Freeze_Package_Instance): ...this, remove first parameter and
change the name of local variables for the sake of consistency.
Do not deal with the special case of incomplete actual types here
and do not insert the body.
(Instantiate_Package_Body): Deal with the special case of incomplete
actual types here and insert the body. Call Freeze_Package_Instance
only if expansion is done.
(Instantiate_Subprogram_Body): Minor consistency tweak.
gcc/ada/
* sem_case.adb (Check_Bindings): Provide a second strategy for
implementing bindings and choose which strategy to use for a
given binding. The previous approach was to introduce a new
object and assign the bound value to the object. The new
approach is to introduce a renaming of a dereference of an
access value that references the appropriate subcomponent, so no
copies are made. The original strategy is still used if the
type of the object is elementary. When the renaming approach is
used, the initialization of the access value is not generated
until expansion. Until this missing initialization is added, the
tree looks like a known-at-compile-time dereference of a null
access value: Temp : Some_Access_Type; Obj : Designated_Type
renames Temp.all; This leads to problems, so a bogus initial
value is provided here and then later deleted during expansion.
(Check_Composite_Case_Selector): Disallow a case selector
expression that requires finalization. Note that it is ok if the
selector's type requires finalization, as long as the expression
itself doesn't have any "newly constructed" parts.
* exp_ch5.adb (Pattern_Match): Detect the case where analysis of
a general (i.e., composite selector type) case statement chose
to implement a binding as a renaming rather than by making a
copy. In that case, generate the assignments to initialize the
access-valued object whose designated value is later renamed
(and remove the bogus initial value for that object that was
added during analysis).
* sem_util.ads, sem_util.adb: Add new function
Is_Newly_Constructed corresponding to RM 4.4 term.
gcc/ada/
* frontend.adb (Frontend): Do unnesting after ignored ghost code
has been removed.
* inline.adb (Analyze_Inlined_Bodies): Don't put ignored ghost
entities on inlined subprogram list.
gcc/ada/
* sprint.ads (Source_Dump): Fix typo in comment.
* sprint.adb (Source_Dump): Set Dump_Freeze_Null for both -gnatG
and -gnatD.
* switch-c.adb (Scan_Front_End_Switches) <'D'>: Remove obsolete
kludge.
gcc/ada/
* einfo.ads (Direct_Primitive_Operations): Update the doc to
indicate that this field is used for all types now.
* sem_ch4.adb (Try_Object_Operation): Add parameter
Allow_Extensions set to True to pretend that extensions are
allowed.
* sem_ch4.ads: Same.
* sem_ch6.adb: Do not require Extensions_Allowed.
* sem_ch8.adb (Find_Selected_Component): Remove duplicate
"where" in comment. Improve the error messages regarding use of
prefixed calls.
gcc/ada/
* sem_ch10.adb (Is_Private_Library_Unit): Move query to
Sem_Util for sharing.
* sem_ch7.adb (Analyze_Package_Body_Helper): Add continuation
message.
* sem_prag.adb (Analyze_Part_Of): Call new function
Is_Private_Library_Unit.
(Check_Valid_Library_Unit_Pragma): Specialize error messages on
misplaced pragmas.
(Analyze_Refined_State_In_Decl_Part): Recognize missing Part_Of
on object in private part.
* sem_util.adb (Check_State_Refinements): Add continuation
message.
(Find_Placement_In_State_Space): Fix detection of placement,
which relied wrongly on queries In_Package_Body/In_Private_Part
which do not provide the right information here for all cases.
(Is_Private_Library_Unit): Move query here for sharing.
* sem_util.ads (Is_Private_Library_Unit): Move query here for
sharing.
gcc/ada/
* sem_ch3.adb (Analyze_Full_Type_Declaration): If the full type
has a primitives list but its base type doesn't, set the base
type's list to the full type's list (covers certain constrained
cases, such as for arrays).
(Analyze_Incomplete_Type_Decl): Unconditionally initialize an
incomplete type's primitives list.
(Analyze_Subtype_Declaration): Unconditionally set a subtype's
primitives list to the base type's list, so the lists are
shared.
(Build_Derived_Private_Type): Unconditionally initialize a
derived private type's list to a new empty list.
(Build_Derived_Record_Type): Unconditionally initialize a
derived record type's list to a new empty list (now a single
call for tagged and untagged cases).
(Derived_Type_Declaration): Unconditionally initialize a derived
type's list to a new empty list in error cases (when Parent_Type
is undefined or illegal).
(Process_Full_View): Unconditionally copy the primitive
operations from the private view to the full view (rather than
conditioning it on whether extensions are enabled).
* sem_ch7.adb (New_Private_Type): Unconditionally initialize an
untagged private type's primitives list to a new empty list.
gcc/ada/
* libgnat/a-cbhase.adb, libgnat/a-cborse.adb,
libgnat/a-cihase.adb, libgnat/a-ciorse.adb,
libgnat/a-cohase.adb, libgnat/a-coorse.adb
(Constant_Reference,Reference_Preserving_Key): Refactor using
the equivalence stated in the RM.
gcc/ada/
* exp_ch3.adb (Make_Eq_Body): Refactor to avoid appending to an
empty list; also, when exiting early we will not create any
list; fix style in comment.
While looking at a proposed vendor backport, I've noticed some
formatting issues in x86-tune.def. Also, in all spots m_GENERIC
comes last, except one recently changed, I think it is useful to have
m_GENERIC always last for consistency.
2021-12-01 Jakub Jelinek <jakub@redhat.com>
* config/i386/x86-tune.def (X86_TUNE_SCHEDULE,
X86_TUNE_SSE_PARTIAL_REG_FP_CONVERTS_DEPENDENCY,
X86_TUNE_MISALIGNED_MOVE_STRING_PRO_EPILOGUES): Formatting fixes.
(X86_TUNE_USE_GATHER): Put m_GENERIC last for consistency.
On Mon, Nov 29, 2021 at 05:53:58PM -0500, Jason Merrill wrote:
> I'm inclined to go ahead and change C++98 as well; I doubt anyone is relying
> on the particular C++98 extended character set rules, and we already accept
> the union of the different sets when not pedantic.
Ok, here is an incremental patch to do that also for -std={c,gnu}++98.
2021-12-01 Jakub Jelinek <jakub@redhat.com>
PR c++/100977
* init.c (struct lang_flags): Remove cxx23_identifiers.
(lang_defaults): Remove cxx23_identifiers initializers.
(cpp_set_lang): Don't copy cxx23_identifiers.
* include/cpplib.h (struct cpp_options): Adjust comment about
c11_identifiers. Remove cxx23_identifiers field.
* lex.c (warn_about_normalization): Use cplusplus instead of
cxx23_identifiers.
* charset.c (ucn_valid_in_identifier): Likewise.
* g++.dg/cpp/ucnid-1.C: Adjust expected diagnostics.
* g++.dg/cpp/ucnid-1-utf8.C: Likewise.
Seems simplify_associate_operation is quadratic, which isn't a big deal
for use during combine and other similar RTL passes, because those never
try to combine expressions from more than a few instructions and because
those instructions need to be recognized the machine description also bounds
how many expressions can appear in there.
var-tracking has depth limits only for some cases and unlimited depth
for the vt_expand_loc though:
/* This is the value used during expansion of locations. We want it
to be unbounded, so that variables expanded deep in a recursion
nest are fully evaluated, so that their values are cached
correctly. We avoid recursion cycles through other means, and we
don't unshare RTL, so excess complexity is not a problem. */
#define EXPR_DEPTH (INT_MAX)
/* We use this to keep too-complex expressions from being emitted as
location notes, and then to debug information. Users can trade
compile time for ridiculously complex expressions, although they're
seldom useful, and they may often have to be discarded as not
representable anyway. */
#define EXPR_USE_DEPTH (param_max_vartrack_expr_depth)
IMO for very large expressions it isn't worth trying to reassociate though,
in fact e.g. for the new testcase below keeping it as is has bigger chance
of generating smaller debug info which the dwarf2out.c part of the change
tries to achieve - if a binary operation has the same operands, we can
use DW_OP_dup and not bother computing the possibly large operand again.
The patch fixes it by adding a counter to simplify_context and counting
how many times simplify_associative_operation has been called during
a single outermost simplify_* call, and once it reaches some maximum
(currently 64), it stops reassociating.
Another possibility to deal with the power expressions in debug info
would be to introduce some new RTL operation for the pow{,i} (x, n)
case, allow that solely in debug insns and expand those into DWARF
using a loop. But that seems like quite a lot of work for something rarely
used (especially when powi for larger n is only useful for 0 and 1 inputs
because anything else overflows).
2021-12-01 Jakub Jelinek <jakub@redhat.com>
PR rtl-optimization/102356
* rtl.h (simplify_context): Add assoc_count member and
max_assoc_count static member.
* simplify-rtx.c (simplify_associative_operation): Don't reassociate
more than max_assoc_count times within one outermost simplify_* call.
* dwarf2out.c (mem_loc_descriptor): Optimize binary operation
with both operands the same using DW_OP_dup.
* gcc.dg/pr102356.c: New test.
stringify_arg uses pfile->u_buff to create the string literal.
Unfortunately, paste_tokens -> _cpp_lex_direct -> lex_number -> _cpp_unaligned_alloc
can in some cases use pfile->u_buff too, which results in losing everything
prepared for the string literal until the token pasting.
The following patch fixes that by not calling paste_token during the
construction of the string literal, but doing that before. All the tokens
we are processing have been pushed into a token buffer using
tokens_buff_add_token so it is fine if we paste some of them in that buffer
(successful pasting creates a new token in that buffer), move following
tokens if any to make it contiguous, pop (throw away) the extra tokens at
the end and then do stringify_arg.
Also, paste_tokens now copies over PREV_WHITE and PREV_FALLTHROUGH flags
from the original lhs token to the replacement token. Copying that way
the PREV_WHITE flag is needed for the #__VA_OPT__ handling and copying
over PREV_FALLTHROUGH fixes the new Wimplicit-fallthrough-38.c test.
2021-12-01 Jakub Jelinek <jakub@redhat.com>
PR preprocessor/103415
libcpp/
* macro.c (stringify_arg): Remove va_opt argument and va_opt handling.
(paste_tokens): On successful paste or in PREV_WHITE and
PREV_FALLTHROUGH flags from the *plhs token to the new token.
(replace_args): Adjust stringify_arg callers. For #__VA_OPT__,
perform token pasting in a separate loop before stringify_arg call.
gcc/testsuite/
* c-c++-common/cpp/va-opt-8.c: New test.
* c-c++-common/Wimplicit-fallthrough-38.c: New test.
Following the previous bugfix this addresses the cosmetic and test issues.
The vector tests are moved to vect and the scalar are left where they are.
gcc/ChangeLog:
* match.pd: Move below pattern that rewrites to EQ, NE.
* tree.c (bitmask_inv_cst_vector_p): Correct do .. while indentation.
gcc/testsuite/ChangeLog:
* gcc.dg/bic-bitmask-10.c: Moved to gcc.dg/vect/vect-bic-bitmask-10.c.
* gcc.dg/bic-bitmask-11.c: Moved to gcc.dg/vect/vect-bic-bitmask-11.c.
* gcc.dg/bic-bitmask-12.c: Moved to gcc.dg/vect/vect-bic-bitmask-12.c.
* gcc.dg/bic-bitmask-3.c: Moved to gcc.dg/vect/vect-bic-bitmask-3.c.
* gcc.dg/bic-bitmask-23.c: Moved to gcc.dg/vect/vect-bic-bitmask-23.c.
* gcc.dg/bic-bitmask-2.c: Moved to gcc.dg/vect/vect-bic-bitmask-2.c.
* gcc.dg/bic-bitmask-4.c: Moved to gcc.dg/vect/vect-bic-bitmask-4.c.
* gcc.dg/bic-bitmask-5.c: Moved to gcc.dg/vect/vect-bic-bitmask-5.c.
* gcc.dg/bic-bitmask-6.c: Moved to gcc.dg/vect/vect-bic-bitmask-6.c.
* gcc.dg/bic-bitmask-8.c: Moved to gcc.dg/vect/vect-bic-bitmask-8.c.
* gcc.dg/bic-bitmask-9.c: Moved to gcc.dg/vect/vect-bic-bitmask-9.c.
Avoid overwriting osi->changed if object_sizes_set does not update the
size, so that a previous success in the same pass is not overwritten.
This fixes the bootstrap-ubsan build config, which was failing due to
incorrect object size.
gcc/ChangeLog:
PR tree-optimization/103456
* tree-object-size.c (merge_object_sizes): Update osi->changed
only if object_sizes_set succeeded.
gcc/testsuite/ChangeLog:
PR tree-optimization/103456
* gcc.dg/ubsan/pr103456.c: New test.
Co-authored-by: Martin Liška <mliska@suse.cz>
Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
ix86_attr_length_immediate_default assume TYPE ishift only have 1
constant operand,
but *x86_64_shld_1/*x86_shld_1/*x86_64_shrd_1/*x86_shrd_1 has 2, with
condition: INTVAL (operands[3]) == 32 - INTVAL (operands[2]) or
INTVAL (operands[3]) == 64 - INTVAL (operands[2]), and hit
gcc_assert.
Explicitly set_attr length_immediate for these patterns.
gcc/ChangeLog:
PR target/103463
PR target/103484
* config/i386/i386.md (*x86_64_shld_1): Set_attr
length_immediate to 1.
(*x86_shld_1): Ditto.
(*x86_64_shrd_1): Ditto.
(*x86_shrd_1): Ditto.
gcc/testsuite/ChangeLog:
* gcc.target/i386/pr103463.c: New test.
* gcc.target/i386/pr103463-2.c: New test.
When a built-in function required by an overloaded function name is not
currently enabled, the diagnostic message is not as clear as it should be.
Saying that one built-in "requires" another is somewhat misleading. It is
better to explicitly state that the overloaded builtin is implemented by the
missing builtin.
2021-11-23 Bill Schmidt <wschmidt@linux.ibm.com>
gcc/
* config/rs6000/rs6000-c.c (altivec_resolve_overloaded_builtin):
Clarify diagnostic.
(altivec_resolve_new_overloaded_builtin): Likewise.
Fix some tests that assume that a moved-from string is empty, or that
default constructing a string doesn't allocate.
libstdc++-v3/ChangeLog:
* testsuite/21_strings/basic_string/cons/char/moveable.cc: Allow
moved-from string to be non-empty.
* testsuite/21_strings/basic_string/cons/char/moveable2.cc:
Likewise.
* testsuite/21_strings/basic_string/cons/char/moveable2_c++17.cc:
Likewise.
* testsuite/21_strings/basic_string/cons/wchar_t/moveable.cc:
Likewise.
* testsuite/21_strings/basic_string/cons/wchar_t/moveable2.cc:
Likewise.
* testsuite/21_strings/basic_string/cons/wchar_t/moveable2_c++17.cc:
Likewise.
* testsuite/21_strings/basic_string/modifiers/assign/char/87749.cc:
Construct empty string before setting oom flag.
* testsuite/21_strings/basic_string/modifiers/assign/wchar_t/87749.cc:
Likewise.
My last change to the fully-dynamic-string actually broke it. This fixes
the move constructor so it builds, and simplifies it slightly so that
more code is common between the fully-dynamic enabled/disabled cases.
libstdc++-v3/ChangeLog:
* include/bits/cow_string.h (basic_string(basic_string&&)): Fix
mem-initializer for _GLIBCXX_FULLY_DYNAMIC_STRING==0 case.
* testsuite/21_strings/basic_string/cons/char/noexcept_move_construct.cc:
Remove outdated comment.
* testsuite/21_strings/basic_string/cons/wchar_t/noexcept_move_construct.cc:
Likewise.
The definitions of the new C++20 members of std::stringstream etc are
missing when --with-default-libstdcxx-abi=gcc4-compatible is used,
because all the explicit instantiations in src/c++20/sstream-inst.cc are
skipped.
This ensures the contents of that file are compiled with the new ABI, so
the same set of symbols are exported regardless of which ABI is active
by default.
libstdc++-v3/ChangeLog:
* src/c++20/sstream-inst.cc (_GLIBCXX_USE_CXX11_ABI): Define to
select new ABI.