Patrick Palka [Sun, 6 Nov 2022 16:09:26 +0000 (11:09 -0500)]
c++: correct __has_attribute(init_priority)
Currently __has_attribute(init_priority) always returns true, even on
targets that don't actually support init priorities, and when using the
attribute on such targets we just get a hard error about them being
unsupported. This makes it impossible to conditionally use the attribute
by querying __has_attribute.
This patch fixes this by including init_priority in the attribute table
only if the target supports init priorities. Thus on such targets
__has_attribute(init_priority) will now return false and we'll treat it
as just another unrecognized attribute (e.g. using it gives a -Wattribute
warning instead of a hard error).
gcc/cp/ChangeLog:
* tree.cc (cxx_attribute_table): Include init_priority entry
only if SUPPORTS_INIT_PRIORITY.
(handle_init_priority_attribute): Add ATTRIBUTE_UNUSED. Assert
SUPPORTS_INIT_PRIORITY is true.
This commit caused failure of update_version_git due to the removal of
liboffloadmic with ChangeLog in it, so I had to blacklist that commit
and here I'm adding ChangeLog entries manually.
Iain Buclaw [Sat, 5 Nov 2022 18:45:05 +0000 (19:45 +0100)]
d: Adjust test to pass when compiling with -m32
Noticed when running on x86_64-linux-gnu with `-m32', this test
triggered other errors. Adjusted the test to use a different register
that is common between x86 and x86_64.
Iain Buclaw [Sat, 5 Nov 2022 18:32:17 +0000 (19:32 +0100)]
d: Add support for vector comparison operators
The front-end added semantic support to permit comparing two vector
expressions. This removes the restriction in the code generator, as
well as the intrisics that previously exposed the same operation.
Lewis Hyatt [Wed, 15 Jun 2022 22:06:53 +0000 (18:06 -0400)]
c++: libcpp: Support raw strings with newlines in directives [PR55971]
It's not currently possible to use a C++11 raw string containing a newline as
part of the definition of a macro, or in any other preprocessing directive,
such as:
#define X R"(two
lines)"
#error R"(this error has
two lines)"
Add support for that by relaxing the conditions under which
_cpp_get_fresh_line() refuses to get a new line. For the case of lexing a raw
string, it's OK to do so as long as there is another line within the current
buffer. The code in cpp_get_fresh_line() was refactored into a new function
get_fresh_line_impl(), so that the new logic is applied only when processing a
raw string and not any other times.
libcpp/ChangeLog:
PR preprocessor/55971
* lex.cc (get_fresh_line_impl): New function refactoring the code
from...
(_cpp_get_fresh_line): ...here.
(lex_raw_string): Use the new version of get_fresh_line_impl() to
support raw strings containing new lines when processing a directive.
gcc/testsuite/ChangeLog:
PR preprocessor/55971
* c-c++-common/raw-string-directive-1.c: New test.
* c-c++-common/raw-string-directive-2.c: New test.
Jakob Hasse [Tue, 26 Apr 2022 04:03:47 +0000 (12:03 +0800)]
libstdc++: fix pointer type exception catch (no RTTI) [PR105387]
__pbase_type_info::__do_catch(), used to catch pointer type exceptions,
did not check if the type info object to compare against is a pointer
type info object before doing a static down-cast to a pointer type info
object. If RTTI is disabled, this leads to the following situation:
Since a pointer type info object has additional fields, they would
end up being undefined if the actual type info object was not a pointer
type info object.
A simple check has been added before the down-cast happens.
Note that a consequence of this check is that exceptions of type
pointer-to-member cannot be caught anymore.
In case RTTI is enabled, this does not seem to be a problem because
RTTI-based checks would run before and prevent running into the bad
down-cast. Hence, the fix is disabled if RTTI is enabled and exceptions
of type pointer-to-member can still be caught.
libstdc++-v3/ChangeLog:
PR libstdc++/105387
* libsupc++/pbase_type_info.cc (__do_catch) [!__cpp_rtti]: Add
check that the thrown type is actually a pointer.
* testsuite/18_support/105387.cc: New test.
* testsuite/18_support/105387_memptr.cc: New test.
Signed-off-by: Jakob Hasse <jakob.hasse@espressif.com>
Jonathan Wakely [Fri, 4 Nov 2022 15:05:41 +0000 (15:05 +0000)]
libstdc++: Do not use SFINAE for propagate_const conversions [PR107525]
As the PR notes, the current conversion operators are defined as
function templates so that we can use SFINAE. But this changes how they
are considered for overload resolution. This moves those operators into
base classes that can be specialized so the operators are obsent unless
the constraints are satisfied.
libstdc++-v3/ChangeLog:
PR libstdc++/107525
* include/experimental/propagate_const (operator element_type*()):
Move into base class that can be partially specilized to iompose
constraints.
(operator const element_type*()): Likewise.
* testsuite/experimental/propagate_const/observers/107525.cc: New test.
Alexandre Oliva [Sat, 5 Nov 2022 06:14:33 +0000 (03:14 -0300)]
Support multilib-aware target lib flags self-specs overriding
This patch introduces -fmultiflags, short for multilib TFLAGS, as an
option that does nothing by default, but that can be added to TFLAGS
and mapped to useful options by driver self-specs.
for gcc/ChangeLog
* common.opt (fmultiflags): New.
* doc/invoke.texi: Document it.
* gcc.cc (driver_self_specs): Discard it.
* opts.cc (common_handle_option): Ignore it in the driver.
Jakub Jelinek [Fri, 4 Nov 2022 17:20:36 +0000 (18:20 +0100)]
testsuite: Add testcase from C++23 P2314R4 - Character sets and encodings
I've read the paper and I believe we just implement it with no changes
needed (at least since PR67224 and similar libcpp changes in GCC 10),
but I could be wrong.
The following patch at least adds a testcase from the start of the paper.
2022-11-04 Jakub Jelinek <jakub@redhat.com>
* g++.dg/cpp23/charset1.C: New testcase from C++23 P2314R4.
Jakub Jelinek [Fri, 4 Nov 2022 17:18:42 +0000 (18:18 +0100)]
libcpp: Update to Unicode 15
The following pseudo-patch regenerates the libcpp tables with Unicode 15.0.0
which added 4489 new characters.
As mentioned previously, this isn't just a matter of running the
two libcpp/make*.cc programs on the new Unicode files, but one needs
to manually update a table inside of makeuname2c.cc according to
a table in Unicode text (which is partially reflected in the text
files, but e.g. in Unicode 14.0.0 not 100% accurately, in 15.0.0
actually accurately).
I've also added some randomly chosen subset of those 4489 new
characters to a testcase.
2022-11-04 Jakub Jelinek <jakub@redhat.com>
gcc/testsuite/
* c-c++-common/cpp/named-universal-char-escape-1.c: Add tests for some
characters newly added in Unicode 15.0.0.
libcpp/
* makeuname2c.cc (struct generated): Update from Unicode 15.0.0
table 4-8.
* ucnid.h: Regenerated for Unicode 15.0.0.
* uname2c.h: Likewise.
Aldy Hernandez [Fri, 4 Nov 2022 09:20:46 +0000 (10:20 +0100)]
Set nonzero bits for multiplication and divisions by a power of 2.
We're missing a lot of TLC in keeping track of nonzero bits across
range-ops. It isn't an oversight, but just limited amount of hours to
implement stuff.
This patch keeps better track of the nonzero mask (really
maybe_nonzero bits as discussed) across multiplication and division
when the RHS is a power of 2.
It fixes PR107342 and also touches on PR55157. In the latter, the
nonzero mask is being set quite late (CCP2) but could be set by evrp
time if we enhanced range-ops. I have added tests from both PRs.
Eric Botcazou [Fri, 4 Nov 2022 10:23:12 +0000 (11:23 +0100)]
Fix recent thinko in operand_equal_p
There is a thinko in a recent improvement made to operand_equal_p where
the code just looks at operand 2 of COMPONENT_REF, if it is present, to
compare addresses. That's wrong because operand 2 contains the number of
DECL_OFFSET_ALIGN-bit-sized words so, when DECL_OFFSET_ALIGN > 8, not all
the bytes are included and some of them are in DECL_FIELD_BIT_OFFSET, see
get_inner_reference for the model computation.
In other words, you would need to compare operand 2 and DECL_OFFSET_ALIGN
and DECL_FIELD_BIT_OFFSET in this situation, but I'm not sure this is worth
the hassle in practice so the fix just removes this alternate handling.
gcc/
* fold-const.cc (operand_compare::operand_equal_p) <COMPONENT_REF>:
Do not take into account operand 2.
(operand_compare::hash_operand) <COMPONENT_REF>: Likewise.
gcc/testsuite/
* gnat.dg/opt99.adb: New test.
* gnat.dg/opt99_pkg1.ads, gnat.dg/opt99_pkg1.adb: New helper.
* gnat.dg/opt99_pkg2.ads: Likewise.
Jonathan Wakely [Thu, 3 Nov 2022 11:44:47 +0000 (11:44 +0000)]
libstdc++: Define _GNU_SOURCE for secure_getenv on Cygwin [PR107511]
As in r12-6867-ge20486d508afdf we need to define _GNU_SOURCE explicitly
for Cygwin, because configure finds it in libc but it isn't declared
unless we request it.
Justin Squirek [Wed, 12 Oct 2022 09:53:04 +0000 (11:53 +0200)]
ada: Fix for validity checks combined with aliasing checks
Attribute Overlaps_Storage, which can appear implicitly in expansion of
aliasing checks, is now excluded from operand validity checks. Likewise
for attribute Has_Same_Storage.
gcc/ada/
* exp_attr.adb (Expand_N_Attribute_Reference): Skip operand
validity checks for attributes Has_Same_Storage and
Overlaps_Storage.
Eric Botcazou [Wed, 12 Oct 2022 10:41:49 +0000 (12:41 +0200)]
ada: Fix couple of issues with arrays indexed by enumeration type
The first one is that Remove_Warning_Messages reinstates the Original_Node
of an N_Raise_Constraint_Error node in the tree for no clear reasons, and
the Original_Node may contain constructs whose expansion has been stopped
when the Constraint_Error was asserted, eventually causing gigi to stop.
The second one is that a path in Build_Array_Aggr_Code.Gen_Loop does not
copy the loop bounds, unlike other paths, thus triggering a sharing issue.
gcc/ada/
* errout.adb (Remove_Warning_Messages.Check_For_Warning): Do not
reinstate the Original_Node in the tree.
* exp_aggr.adb (Build_Array_Aggr_Code.Gen_Loop): Copy the bounds
on all paths.
Piotr Trojanek [Tue, 23 Aug 2022 10:57:35 +0000 (12:57 +0200)]
ada: Cleanup code for warnings about unset references
Cleanup related to new checks for unset references.
gcc/ada/
* sem_util.adb
(In_Pragma_Expression): Add standard guard against searching too
far.
(In_Quantified_Expression): Likewise.
* sem_warn.adb
(May_Need_Initialized_Actual): Remove redundant parens.
(Check_References): Remove guard that duplicates a condition from
the enclosing if-statement; only assign E1T variable when
necessary.
(Within_Postcondition): Fix layout.
(No_Warn_On_In_Out): Balance parens in comment.
Steve Baird [Sat, 8 Oct 2022 00:20:31 +0000 (17:20 -0700)]
ada: Static intrinsic functions are a core language extension.
GNAT-defined Ada extensions are divided into two categories: those that are
enabled by either -gnatX or -gnatX0 and those which require -gnatX0.
Move static intrinsic functions from the second category into the first.
gcc/ada/
* doc/gnat_rm/implementation_defined_pragmas.rst: Add the standard
'... "On" enables this extension.' sentence to the description of
static intrinsic functions.
* sem_ch13.adb
(Analyze_Aspect_Spec): In the call to Error_Msg_GNAT_Extension for
a Static aspect specification for an intrinsic function, specify
Is_Core_Extension => True.
* sem_eval.adb
(Eval_Intrinsic_Call): Test Core_Extensions_Allowed instead of
testing All_Extensions_Allowed.
* gnat_rm.texi: Regenerate.
Javier Miranda [Fri, 7 Oct 2022 18:43:46 +0000 (18:43 +0000)]
ada: Flag unsupported dispatching constructor calls
gcc/ada/
* exp_intr.adb
(Expand_Dispatching_Constructor_Call): Report an error on
unsupported dispatching constructor calls and report a warning on
calls that may fail at run time.
gcc/testsuite/
* gnat.dg/abstract1.ads: Cleanup whitespaces.
* gnat.dg/abstract1.adb: Likewise and add -gnatws to silence new
warning.
Piotr Trojanek [Thu, 1 Sep 2022 08:19:09 +0000 (10:19 +0200)]
ada: Avoid repeated iteration over private protected components
The First_Entity/Next_Entity chain includes private entities, so there
it no need to iterate starting both from First_Entity and
First_Private_Entity.
Code cleanup related to improved detection of references to
uninitialized objects; behavior is unaffected.
gcc/ada/
* sem_util.adb
(Check_Components): Iterate using
First/Next_Component_Or_Discriminant.
(Has_Preelaborable_Initialization): Avoid repeated iteration with
calls to Check_Components with First_Entity and
First_Private_Entity.
(Is_Independent_Object_Entity): Tune indentation.
Piotr Trojanek [Tue, 23 Aug 2022 15:16:44 +0000 (17:16 +0200)]
ada: Cleanup clearing flags on package variables
When killing flags on assignable entities we iterated from First_Entity
and then again from First_Private_Entity. This second iteration was
unnecessary, because the entity chain that starts with First_Entity
contains all entities, including the private ones.
This is just a performance improvement; the behavior is unchanged.
gcc/ada/
* sem_ch7.adb (Clear_Constants): Only iterate from First_Entity
through Next_Entity; only examine variables because packages have
no assignable formal parameters.
Marc Poulhiès [Thu, 22 Sep 2022 08:59:42 +0000 (10:59 +0200)]
ada: Fix loop unnesting issue.
During loop unnesting, when the loop statements are wrapped in a code
block, the newly created block's scope must be set to the loop
scope (instead of the previous 'Current_Scope' that would point to an
upper scope).
gcc/ada/
* sem_util.ads (Add_Block_Identifier): Add new extra Scope
argument.
* sem_util.adb (Add_Block_Identifier): Likewise and use this scope
variable instead of Current_Scope.
* exp_util.adb (Wrap_Statements_In_Block): Add new scope argument
to Add_Block_Identifier call.
Piotr Trojanek [Fri, 7 Oct 2022 10:55:14 +0000 (12:55 +0200)]
ada: Fix repeated killing of private entity values
When killing known values of assignable entities we iterated from
First_Entity and then again from First_Private_Entity. This second
iteration was unnecessary, because the entity chain that starts with
First_Entity contains all entities, including the private ones.
This is just a performance improvement; the behavior is unchanged.
gcc/ada/
* sem_util.adb (Kill_Current_Values): Only iterate from
First_Entity through Next_Entity.
Javier Miranda [Thu, 6 Oct 2022 21:44:43 +0000 (21:44 +0000)]
ada: Skip dynamic interface conversion under configurable runtime
gcc/ada/
* exp_disp.adb
(Expand_Interface_Conversion): Under configurable runtime, when
the target type is an interface that is an ancestor of the operand
type, skip generating code to displace the pointer to reference
the target dispatch table.
* sem_disp.adb
(Propagate_Tag): Handle class-wide types when checking for the
addition of an implicit interface conversion.
Piotr Trojanek [Thu, 6 Oct 2022 21:42:46 +0000 (23:42 +0200)]
ada: Improve efficiency of scope stack restoration
We save/restore visibility by setting the Is_Immediately_Visible flag
and appending entities to / removing them from the tail of an element
list.
However, the Is_Immediately_Visible flag can be restored in any order,
while the element list is singly-linked and removal from the tail is
inefficient. This change removes a performance hot spot, which accounted
for up to 10% of compilation time of complex applications (e.g. QGen),
at least as measured on GNAT built with profiling support.
gcc/ada/
* sem_ch8.adb (Restore_Scope_Stack): Remove elements from the head
and not the tail of an element list.
Steve Baird [Fri, 30 Sep 2022 22:27:00 +0000 (15:27 -0700)]
ada: Allow enabling a restricted set of language extensions.
The -gnatX switch (and the related Extensions_Allowed pragma) is currently a
two-valued all-or-nothing option. Add support for enabling a curated subset
of language extensions without enabling others via the -gnatX switch
and for enabling all language extensions via the new -gnatX0 switch.
Similarly, the existing "ON" argument for the Extensions_Allowed pragma
now only enables the curated subset; the new argument "ALL" enables all
language extensions. The subset of language extensions currently includes
prefixed-view notation with an untagged prefix, fixed-low-bound array
subtypes, and casing on composite values.
gcc/ada/
* opt.ads: Replace Ada_Version_Type enumeration literal
Ada_With_Extensions with two literals, Ada_With_Core_Extensions
and Ada_With_All_Extensions. Update uses of the deleted literal.
Replace Extensions_Allowed function with two functions:
All_Extensions_Allowed and Core_Extensions_Allowed.
* errout.ads, errout.adb: Add Boolean parameter to
Error_Msg_GNAT_Extension to indicate whether the construct in
question belongs to the curated subset.
* exp_ch5.adb, par-ch4.adb, sem_case.adb, sem_ch3.adb:
* sem_ch4.adb, sem_ch5.adb, sem_ch8.adb: Replace calls to
Extensions_Allowed with calls to Core_Extensions_Allowed for
constructs that are in the curated subset.
* sem_attr.adb, sem_ch13.adb, sem_eval.adb, sem_util.adb: Replace
calls to Extensions_Allowed with calls to All_Extensions_Allowed
for constructs that are not in the curated subset.
* par-ch3.adb: Override default for new parameter in calls to
Error_Msg_GNAT_Extension for constructs in the curated subset.
* par-prag.adb: Add Boolean parameter to Check_Arg_Is_On_Or_Off to
also allow ALL. Set Opt.Ada_Version appropriately for ALL or ON
arguments.
* sem_prag.adb: Allowed ALL argument for an Extensions_Allowed
pragma. Set Opt.Ada_Version appropriately for ALL or ON arguments.
* switch-c.adb: The -gnatX switch now enables only the curated
subset of language extensions (formerly it enabled all of them);
the new -gnatX0 switch enables all of them.
* doc/gnat_ugn/building_executable_programs_with_gnat.rst:
Document new "-gnatX0" switch and update documentation for
"-gnatX" switch.
* doc/gnat_rm/implementation_defined_pragmas.rst: Document new ALL
argument for pragma Extensions_Allowed and update documentation
for the ON argument. Delete mention of Ada 2022 Reduce attribute
as an extension.
* gnat_rm.texi, gnat_ugn.texi: Regenerate.
Steve Baird [Wed, 5 Oct 2022 22:16:26 +0000 (15:16 -0700)]
ada: Generate missing object decls for adainit/adafinal registration calls
A previous change on this ticket introduced calls to CUDA_Register_Function
for adainit and adafinal, but failed to introduce declarations for the
C string variables that are initialized and then passed as actual parameters
in this call. Provide the missing declarations (and, incidentally, change
the names of the two variables).
gcc/ada/
* bindgen.adb: Introduce two new string constants for the names of
the C-String variables that are assigned the names for adainit and
adafinal. Replace string literals in Gen_CUDA_Init with references
to these constants. In Gen_CUDA_Defs, generate C-String variable
declarations where these constants are the names of the variables.
Piotr Trojanek [Mon, 3 Oct 2022 20:03:20 +0000 (22:03 +0200)]
ada: Support lock-free protected objects with pragma Initialize_Scalars
In general, protected subprograms are only eligible for a lock-free
expansion if they do not reference global assignable objects.
However, it seems reasonable to ignore references to variables in
System.Scalar_Values, which are generated when pragma Initialize_Scalars
is active. Such references appear, for example, when protected
subprogram has formal parameters of mode out.
gcc/ada/
* sem_ch9.adb (Satisfies_Lock_Free_Requirements): Ignore
references to global variables inserted due to pragma
Initialize_Scalars.
Piotr Trojanek [Mon, 3 Oct 2022 21:16:19 +0000 (23:16 +0200)]
ada: Reject expanded global names in lock-free protected objects
Lock-free expansion of protected subprograms is only possible when there
are no references to global assignable objects. We only detected such
references when they appeared as direct names, but we must similarly
detect expanded names.
gcc/ada/
* sem_ch9.adb (Satisfies_Lock_Free_Requirements): Detect
references via expanded names.
Steve Baird [Tue, 4 Oct 2022 21:42:56 +0000 (14:42 -0700)]
ada: Generate host-side CUDA_Register_Function calls for device's adainit/adafinal
To invoke a device-side subprogram from the host (via a CUDA_execute pragma),
the subprogram also has to be registered by calling CUDA_Register_Function.
The host-side adainit and adafinal procedures need to invoke the corresponding
device-side procedures, so corresponding CUDA_Register_Function calls need
to be generated.
gcc/ada/
* bindgen.adb
(Gen_CUDA_Init): Move existing loop body into a new local
procedure, Gen_CUDA_Register_Function_Call, and replace that loop
body with a call to this procedure. This first part is just
semantics-preserving refactoring. The second part is to add
Gen_CUDA_Register_Function_Call calls after the loop for the
device-side adainit and adafinal procedures.
Florian Weimer [Fri, 4 Nov 2022 09:18:03 +0000 (10:18 +0100)]
libgcc: Special-case BFD ld unwind table encodings in find_fde_tail
BFD ld (and the other linkers) only produce one encoding of these
values. It is not necessary to use the general
read_encoded_value_with_base decoding routine. This avoids the
data-dependent branches in its implementation.
libgcc/
* unwind-dw2-fde-dip.c (find_fde_tail): Special-case encoding
values actually used by BFD ld.
Previously, if a back end was not 'USE_COLLECT2', nor manually defined
'TARGET_ASM_CONSTRUCTOR', 'TARGET_ASM_DESTRUCTOR', or got pointed to the
respective 'default_[...]' functions due to 'CTORS_SECTION_ASM_OP',
'DTORS_SECTION_ASM_OP', or 'TARGET_ASM_NAMED_SECTION', it got pointed to
'default_stabs_asm_out_constructor', 'default_stabs_asm_out_destructor'.
These would emit 'sorry' for any global constructor/destructor they're
run into.
This is now gone, and thus in such a back end configuration case
'TARGET_ASM_CONSTRUCTOR', 'TARGET_ASM_DESTRUCTOR' don't get defined
anymore, and thus the subsequently following:
... simply does nothing anymore for a 'DECL_STATIC_CONSTRUCTOR',
'DECL_STATIC_DESTRUCTOR'.
This, effectively, means that GCC/nvptx now suddenly appears to "support"
global constructors/destructors, which means that a ton of test cases now
erroneously PASS that previously used to FAIL:
sorry, unimplemented: global constructors not supported on this target
Of course, such support didn't magically happen due to
"STABS: remove -gstabs and -gxcoff functionality", so this is bad. And,
corresponding execution testing then regularly FAILs (due to the global
constructor/destructor functions never being invoked), for example:
[-UNSUPPORTED:-]{+PASS:+} gcc.dg/initpri1.c {+(test for excess errors)+}
{+FAIL: gcc.dg/initpri1.c execution test+}
[-UNSUPPORTED:-]{+PASS:+} g++.dg/special/conpr-1.C {+(test for excess errors)+}
{+FAIL: g++.dg/special/conpr-1.C execution test+}
To restore the previous GCC/nvptx behavior, for traceability, this simply
restores the previous code, stripped down to the bare minimum.
arm: Allow to override location of .gnu.sgstubs section
Depending on the DejaGNU board definition, the .gnu.sgstubs section
might be placed on different locations in order to suit the target.
With this patch, the start location of the section is overrideable
from the board definition with the fallback of the previously
hardcoded location.
Marek Polacek [Tue, 1 Nov 2022 21:05:52 +0000 (17:05 -0400)]
c++: Quash -Wdangling-reference for member operator* [PR107488]
-Wdangling-reference complains here:
std::vector<int> v = ...;
std::vector<int>::const_iterator it = v.begin();
while (it != v.end()) {
const int &r = *it++; // warning
}
because it sees a call to
__gnu_cxx::__normal_iterator<const int*, std::vector<int> >::operator*
which returns a reference and its argument is a TARGET_EXPR representing
the result of
__gnu_cxx::__normal_iterator<const int*, std::vector<int> >::operator++
But 'r' above refers to one of the int elements of the vector 'v', not
to a temporary object. Therefore the warning is a false positive.
I suppose code like the above is relatively common (the warning broke
cppunit-1.15.1 and a few other projects), so presumably it makes sense
to suppress the warning when it comes to member operator*. In this case
it's defined as
and I'm guessing a lot of member operator* are like that, at least when
it comes to iterators. I've looked at _Fwd_list_iterator,
_Fwd_list_const_iterator, __shared_ptr_access, _Deque_iterator,
istream_iterator, etc, and they're all like that, so adding #pragmas
would be quite tedious. :/
PR c++/107488
gcc/cp/ChangeLog:
* call.cc (do_warn_dangling_reference): Quash -Wdangling-reference
for member operator*.
Patrick Palka [Thu, 3 Nov 2022 19:35:18 +0000 (15:35 -0400)]
c++: requires-expr and access checking [PR107179]
Like during satisfaction, we also need to avoid deferring access checks
during substitution of a requires-expr because the outcome of an access
check can determine the value of the requires-expr. Otherwise (in
deferred access checking contexts such as within a base-clause), the
requires-expr may evaluate to the wrong result, and along the way a
failed access check may leak out from it into a non-SFINAE context and
cause a hard error (as in the below testcase).
PR c++/107179
gcc/cp/ChangeLog:
* constraint.cc (tsubst_requires_expr): Make sure we're not
deferring access checks.
Jason Merrill [Thu, 3 Nov 2022 14:51:40 +0000 (10:51 -0400)]
c++: change -fconcepts to mean C++20 concepts
It was always weird that -fconcepts in C++17 mode meant the same thing as
-fconcepts-ts in C++20 mode; this patch harmonizes the flags so that for TS
concepts you always need to write -fconcepts-ts.
In the unlikely event anyone is still using -fconcepts in C++17 mode, they
can either fix their code to work with C++20 concepts or adjust the compiler
flag.
gcc/c-family/ChangeLog:
* c-opts.cc (c_common_post_options): -fconcepts no longer implies
-fconcepts-ts before C++20.
gcc/ChangeLog:
* doc/invoke.texi: -fconcepts no longer implies
-fconcepts-ts before C++20.
Patrick Palka [Thu, 3 Nov 2022 18:55:35 +0000 (14:55 -0400)]
c++: constexpr error with defaulted virtual dtor [PR93413]
We're rejecting the below testcase with
error: 'virtual constexpr Base::~Base()' used before its definition
error: 'virtual constexpr Derived::~Derived()' used before its definition
due to special handling in mark_used added by r181272 to defer synthesis
of virtual destructors until EOF (where we can set their linkage), which
in turn makes them effectively unusable during constexpr evaluation.
Fortunately it seems this special handling is unnecessary ever since
r208030 enabled us to tentatively set linkage of all defaulted virtual
destructors, including templated ones. So this patch gets rid of this
special handling.
PR c++/93413
gcc/cp/ChangeLog:
* decl2.cc (mark_used): Don't defer synthesis of virtual
functions.
amdgcn: Fix instruction generation for exp2 and log2 operations
The GCN instructions for the exp2 and log2 operations are v_exp_* and v_log_*
respectively, which unfortunately do not line up with the RTL naming
convention. To deal with this, a new set of int attributes is now used when
generating the assembly for these instructions.
David Malcolm [Thu, 3 Nov 2022 17:47:02 +0000 (13:47 -0400)]
analyzer: use std::unique_ptr for known functions
gcc/analyzer/ChangeLog:
* analyzer.h: Use std::unique_ptr for known functions.
* engine.cc: Likewise.
* known-function-manager.cc: Likewise.
* known-function-manager.h: Likewise.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_kernel_plugin.c: Use std::unique_ptr for
known functions.
* gcc.dg/plugin/analyzer_known_fns_plugin.c: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
David Malcolm [Thu, 3 Nov 2022 17:47:02 +0000 (13:47 -0400)]
analyzer: use std::unique_ptr during bifurcation
gcc/analyzer/ChangeLog:
* analysis-plan.cc: Define INCLUDE_MEMORY before including
system.h.
* analyzer-pass.cc: Likewise.
* analyzer-selftests.cc: Likewise.
* analyzer.cc: Likewise.
* analyzer.h: Use std::unique_ptr in bifurcation code.
* call-string.cc: Define INCLUDE_MEMORY before including system.h.
* complexity.cc: Likewise.
* engine.cc: Use std::unique_ptr in bifurcation code.
* exploded-graph.h: Likewise.
* known-function-manager.cc: Define INCLUDE_MEMORY before
including system.h.
* region-model-impl-calls.cc: Use std::unique_ptr in bifurcation
code.
* region-model.cc: Likewise.
* region-model.h: Likewise.
* supergraph.cc: Define INCLUDE_MEMORY before including system.h.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_kernel_plugin.c: Include "make-unique.h".
Use std::unique_ptr in bifurcation code.
* gcc.dg/plugin/analyzer_known_fns_plugin.c: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
David Malcolm [Thu, 3 Nov 2022 17:47:01 +0000 (13:47 -0400)]
analyzer: use std::unique_ptr for pending_diagnostic/note
gcc/analyzer/ChangeLog:
* call-info.cc: Add define of INCLUDE_MEMORY.
* call-summary.cc: Likewise.
* checker-path.cc: Likewise.
* constraint-manager.cc: Likewise.
* diagnostic-manager.cc: Likewise.
(saved_diagnostic::saved_diagnostic): Use std::unique_ptr for
param d and field m_d.
(saved_diagnostic::~saved_diagnostic): Remove explicit delete of m_d.
(saved_diagnostic::add_note): Use std::unique_ptr for
param pn.
(saved_diagnostic::get_pending_diagnostic): Update for conversion
of m_sd.m_d to unique_ptr.
(diagnostic_manager::add_diagnostic): Use std::unique_ptr for
param d. Remove explicit deletion.
(diagnostic_manager::add_note): Use std::unique_ptr for param pn.
(diagnostic_manager::emit_saved_diagnostic): Update for conversion
of m_sd.m_d to unique_ptr.
(null_assignment_sm_context::warn): Use std::unique_ptr for
param d. Remove explicit deletion.
* diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Use
std::unique_ptr for param d.
(saved_diagnostic::add_note): Likewise for param pn.
(saved_diagnostic::m_d): Likewise.
(diagnostic_manager::add_diagnostic): Use std::unique_ptr for
param d.
(diagnostic_manager::add_note): Use std::unique_ptr for param pn.
* engine.cc: Include "make-unique.h".
(impl_region_model_context::warn): Update to use std::unique_ptr
for param, removing explicit deletion.
(impl_region_model_context::add_note): Likewise.
(impl_sm_context::warn): Update to use std::unique_ptr
for param.
(impl_region_model_context::on_state_leak): Likewise for result of
on_leak.
(exploded_node::on_longjmp): Use make_unique when creating
pending_diagnostic.
(exploded_graph::process_node): Likewise.
* exploded-graph.h (impl_region_model_context::warn): Update to
use std::unique_ptr for param.
(impl_region_model_context::add_note): Likewise.
* feasible-graph.cc: Add define of INCLUDE_MEMORY.
* pending-diagnostic.cc: Likewise.
* pending-diagnostic.h: Include analyzer.sm.h"
* program-point.cc: Add define of INCLUDE_MEMORY.
* program-state.cc: Likewise.
* region-model-asm.cc: Likewise.
* region-model-impl-calls.cc: Likewise. Include "make-unique.h".
(region_model::impl_call_putenv): Use make_unique when creating
pending_diagnostic.
* region-model-manager.cc: Add define of INCLUDE_MEMORY.
* region-model-reachability.cc: Likewise.
* region-model.cc: Likewise. Include "make-unique.h".
(region_model::get_gassign_result): Use make_unique when creating
pending_diagnostic.
(region_model::check_for_poison): Likewise.
(region_model::on_stmt_pre): Likewise.
(region_model::check_symbolic_bounds): Likewise.
(region_model::check_region_bounds): Likewise.
(annotating_ctxt: make_note): Use std::unique_ptr for result.
(region_model::deref_rvalue): Use make_unique when creating
pending_diagnostic.
(region_model::check_for_writable_region): Likewise.
(region_model::check_region_size): Likewise.
(region_model::check_dynamic_size_for_floats): Likewise.
(region_model::maybe_complain_about_infoleak): Likewise.
(noop_region_model_context::add_note): Use std::unique_ptr for
param. Remove explicit deletion.
* region-model.h: Include "analyzer/pending-diagnostic.h".
(region_model_context::warn): Convert param to std::unique_ptr.
(region_model_context::add_note): Likewise.
(noop_region_model_context::warn): Likewise.
(noop_region_model_context::add_note): Likewise.
(region_model_context_decorator::warn): Likewise.
(region_model_context_decorator::add_note): Likewise.
(note_adding_context::warn): Likewise.
(note_adding_context::make_note): Likewise for return type.
(test_region_model_context::warn): Convert param to
std::unique_ptr.
* region.cc: Add define of INCLUDE_MEMORY.
* sm-fd.cc: Likewise. Include "make-unique.h".
(fd_state_machine::check_for_fd_attrs): Use make_unique when
creating pending_diagnostics.
(fd_state_machine::on_open): Likewise.
(fd_state_machine::on_creat): Likewise.
(fd_state_machine::check_for_dup): Likewise.
(fd_state_machine::on_close): Likewise.
(fd_state_machine::check_for_open_fd): Likewise.
(fd_state_machine::on_leak): Likewise, converting return type to
std::unique_ptr.
* sm-file.cc: Add define of INCLUDE_MEMORY. Include
"make-unique.h".
(fileptr_state_machine::on_stmt): Use make_unique when creating
pending_diagnostic.
(fileptr_state_machine::on_leak): Likewise, converting return type
to std::unique_ptr.
* sm-malloc.cc: Add define of INCLUDE_MEMORY. Include
"make-unique.h".
(malloc_state_machine::on_stmt): Use make_unique when creating
pending_diagnostic.
(malloc_state_machine::handle_free_of_non_heap): Likewise.
(malloc_state_machine::on_deallocator_call): Likewise.
(malloc_state_machine::on_realloc_call): Likewise.
(malloc_state_machine::on_leak): Likewise, converting return type
to std::unique_ptr.
* sm-pattern-test.cc: Add define of INCLUDE_MEMORY. Include
"make-unique.h".
(pattern_test_state_machine::on_condition): Use make_unique when
creating pending_diagnostic.
* sm-sensitive.cc: Add define of INCLUDE_MEMORY. Include
"make-unique.h".
(sensitive_state_machine::warn_for_any_exposure): Use make_unique
when creating pending_diagnostic.
* sm-signal.cc: Add define of INCLUDE_MEMORY. Include
"make-unique.h".
(signal_state_machine::on_stmt): Use make_unique when creating
pending_diagnostic.
* sm-taint.cc: Add define of INCLUDE_MEMORY. Include
"make-unique.h".
(taint_state_machine::check_for_tainted_size_arg): Use make_unique
when creating pending_diagnostic.
(taint_state_machine::check_for_tainted_divisor): Likewise.
(region_model::check_region_for_taint): Likewise.
(region_model::check_dynamic_size_for_taint): Likewise.
* sm.cc: Add define of INCLUDE_MEMORY. Include
"analyzer/pending-diagnostic.h".
(state_machine::on_leak): Move here from sm.h, changing return
type to std::unique_ptr.
* sm.h (state_machine::on_leak): Change return type to
std::unique_ptr. Move defn of base impl to sm.cc
(sm_context::warn): Convert param d to std_unique_ptr.
* state-purge.cc: Add define of INCLUDE_MEMORY.
* store.cc: Likewise.
* svalue.cc: Likewise.
* trimmed-graph.cc: Likewise.
* varargs.cc: Likewise. Include "make-unique.h".
(va_list_state_machine::check_for_ended_va_list): Use make_unique
when creating pending_diagnostic.
(va_list_state_machine::on_leak): Likewise, converting return type
to std::unique_ptr.
(region_model::impl_call_va_arg): Use make_unique when creating
pending_diagnostic.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_gil_plugin.c: Add define of
INCLUDE_MEMORY. Include "make-unique.h".
(gil_state_machine::check_for_pyobject_in_call): Use make_unique
when creating pending_diagnostic.
(gil_state_machine::on_stmt): Likewise.
(gil_state_machine::check_for_pyobject_usage_without_gil): Likewise.
* gcc.dg/plugin/analyzer_kernel_plugin.c: : Add define of
INCLUDE_MEMORY.
* gcc.dg/plugin/analyzer_known_fns_plugin.c: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Tobias Burnus [Thu, 3 Nov 2022 14:03:52 +0000 (15:03 +0100)]
OpenMP/Fortran: 'target update' with DT components
OpenMP 5.0 permits to use arrays with derived type components for the list
items to the 'from'/'to' clauses of the 'target update' directive.
gcc/fortran/ChangeLog:
* openmp.cc (gfc_match_omp_clauses): Permit derived types for
the 'to' and 'from' clauses of 'target update'.
* trans-openmp.cc (gfc_trans_omp_clauses): Fixes for
derived-type changes; fix size for scalars.
libgomp/ChangeLog:
* testsuite/libgomp.fortran/target-11.f90: New test.
* testsuite/libgomp.fortran/target-13.f90: New test.
Please note that(insn 1110) uses register BX, but its
initialization was eliminated.
Avoid conversion if eliminated move intialized a register, used
in the moved instruction.
2022-11-03 Uroš Bizjak <ubizjak@gmail.com>
gcc/ChangeLog:
PR target/107404
* config/i386/i386.md (eliminate reg-reg move by inverting the
condition of a cmove #2 peephole2): Check if eliminated move
initialized a register, used in the moved instruction.
gcc/testsuite/ChangeLog:
PR target/107404
* g++.target/i386/pr107404.C: New test.
Kewen Lin [Thu, 3 Nov 2022 06:22:45 +0000 (01:22 -0500)]
testsuite: Fix gen-vect-34.c with vect_masked_load [PR106806]
This is to fix the failure on powerpc as reported in PR106806,
the test case requires tree ifcvt pass to perform on that loop,
and it relies on masked_load support. The fix is to guard the
expected scan with vect_masked_load effective target.
As tested on powerpc64{,le}-linux-gnu and aarch64-linux-gnu
(cfarm machine), the failures were gone. But on
x86_64-redhat-linux (cfarm machine) the result becomes from
PASS to N/A. I think it's expected since that machine doesn't
support AVX by default so both check_avx_available and
vect_masked_load fail, it should work fine on machines with
default AVX support, or if we adjust the current
check_avx_available with current_compiler_flags.
PR testsuite/106806
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/gen-vect-34.c: Adjust with vect_masked_load
effective target.
Joseph Myers [Thu, 3 Nov 2022 02:53:41 +0000 (02:53 +0000)]
c: C2x auto
Implement C2x auto, a more restricted version of the C++ feature
(closer to GNU C __auto_type in terms of what's supported).
Since the feature is very close to GNU C __auto_type, much of the
implementation can be shared. The main differences are:
* Any prior declaration of the identifier in an outer scope is
shadowed during the initializer (whereas __auto_type leaves any such
declaration visible until the initializer ends and the scope of the
__auto_type declaration itself starts). (A prior declaration in the
same scope is undefined behavior.)
* The standard feature supports braced initializers (containing a
single expression, optionally followed by a comma).
* The standard feature disallows the declaration from declaring
anything that's not an ordinary identifier (thus, the initializer
cannot declare a tag or the members of a structure or union), while
making it undefined behavior for it to declare more than one
ordinary identifier. (For the latter, while I keep the existing
error from __auto_type in the case of more than one declarator, I
don't restrict other ordinary identifiers from being declared in
inner scopes such as GNU statement expressions. I do however
disallow defining the members of an enumeration inside the
initializer (if the enum definition has no tag, that doesn't
actually violate a constraint), to avoid an enum type becoming
accessible beyond where it would have been without auto.
(Preventing new types from escaping the initializer - thus, ensuring
that anything written with auto corresponds to something that could
have been written without auto, modulo multiple evaluation of VLA
size expressions when not using auto - is a key motivation for some
restrictions on what can be declared in the initializer.)
The rule on shadowing and restrictions on other declarations in the
initializer are actually general rules for what C2x calls
underspecified declarations, a description that covers constexpr as
well as auto (in particular, this disallows a constexpr initializer
from referencing the variable being initialized). Thus, some of the
code added for those restrictions will also be of use in implementing
C2x constexpr.
auto with a type specifier remains a storage class specifier with the
same meaning as before (i.e. a redundant storage class specifier for
use at block scope).
Note that the feature is only enabled in C2x mode (-std=c2x or
-std=gnu2x); in older modes, a declaration with auto and no type is
treated as a case of implicit int (only accepted at block scope).
Since many of the restrictions on C2x auto are specified as undefined
behavior rather than constraint violations, it would be possible to
support more features from C++ auto without requiring diagnostics (but
maybe not a good idea, if it isn't clear exactly what semantics might
be given to such a feature in a future revision of C; and
-Wc23-c2y-compat should arguably warn for any such future feature
anyway). For now the features are limited to something close to
what's supported with __auto_type, with the differences as discussed
above between the two features.
Bootstrapped with no regressions for x86_64-pc-linux-gnu.
gcc/c/
* c-decl.cc (in_underspecified_init, start_underspecified_init)
(finish_underspecified_init): New.
(shadow_tag_warned, parser_xref_tag, start_struct, start_enum):
Give errors inside initializers of underspecified declarations.
(grokdeclarator): Handle (erroneous) case of C2X auto on a
parameter.
(declspecs_add_type): Handle c2x_auto_p case.
(declspecs_add_scspec): Handle auto possibly setting c2x_auto_p in
C2X mode.
(finish_declspecs): Handle c2x_auto_p.
* c-parser.cc (c_parser_declaration_or_fndef): Handle C2X auto.
* c-tree.h (C_DECL_UNDERSPECIFIED): New macro.
(struct c_declspecs): Add c2x_auto_p.
(start_underspecified_init, finish_underspecified_init): New
prototypes.
* c-typeck.cc (build_external_ref): Give error for underspecified
declaration referenced in its initializer.
gcc/testsuite/
* gcc.dg/c2x-auto-1.c, gcc.dg/c2x-auto-2.c, gcc.dg/c2x-auto-3.c,
gcc.dg/c2x-auto-4.c, gcc.dg/gnu2x-auto-1.c: New tests.
... which is 'libgomp.oacc-fortran/declare-allocatable-1.f90' adjusted
for missing support for OpenACC "Changes from Version 2.0 to 2.5":
"The 'declare create' directive with a Fortran 'allocatable' has new behavior".
Thus, after 'allocate'/before 'deallocate', call 'acc_create'/'acc_delete'
manually.
gcc: honour -ffile-prefix-map in ASM_MAP [PR93371]
-ffile-prefix-map is supposed to be a superset of -fmacro-prefix-map
and -fdebug-prefix-map. However, when building .S or .s files, gas is
not called with the appropriate --debug-prefix-map option when
-ffile-prefix-map is used.
While the user can specify -fdebug-prefix-map when building assembly
files via gcc, it's more ergonomic to also support -ffile-prefix-map;
especially since for .S files that could contain the __FILE__ macro,
one would then also have to specify -fmacro-prefix-map.
Patrick Palka [Wed, 2 Nov 2022 12:56:59 +0000 (08:56 -0400)]
libstdc++: Improve ERANGE behavior for fallback FP std::from_chars
The fallback implementation of floating-point std::from_chars (used for
formats other than binary32/64) just calls the C library's strtod family
of functions. In case of overflow, the behavior of these functions is
rigidly specified:
If the correct value overflows and default rounding is in effect, plus
or minus HUGE_VAL, HUGE_VALF, or HUGE_VALL is returned (according to
the return type and sign of the value), and the value of the macro
ERANGE is stored in errno.
But in case of underflow, implementations are given more leeway:
If the result underflows the functions return a value whose magnitude
is no greater than the smallest normalized positive number in the
return type; whether errno acquires the value ERANGE is
implementation-defined.
Thus the fallback implementation can (and does) portably detect overflow,
but it can't portably detect underflow. However, glibc (and presumably
other high-quality C library implementations) will reliably set errno to
ERANGE in case of underflow as well, and it'll also return the nearest
denormal number to the correct value (zero in case of true underflow),
which allows callers to succesfully parse denormal numbers.
So since we can't be perfect here, this patch takes the best effort
approach of assuming a high quality C library implementation with
respect to this underflow behavior, and refines our implementation
to try to distiguish between a denormal result and true underflow
by inspecting strtod's return value.
libstdc++-v3/ChangeLog:
* src/c++17/floating_from_chars.cc (from_chars_impl): In the
ERANGE case, distinguish between a denormal result and true
underflow by checking if the return value is 0.
Jonathan Wakely [Tue, 1 Nov 2022 13:47:24 +0000 (13:47 +0000)]
libstdc++: Remove unnecessary variant member in std::expected
Hui Xie pointed out that we don't need a dummy member in the union,
because all constructors always initialize either _M_val or _M_unex.
We still need the _M_void member of the expected<void, E>
specialization, because the constructor has to initialize something when
not using the _M_unex member.