1. 31 Jan, 2020 7 commits
    • Zero-initialise masked load destinations · 95607c12
      Fixes an execution failure in testcase gfortran.dg/assumed_rank_1.f90.
      
      2020-01-30  Andrew Stubbs  <ams@codesourcery.com>
      
      	gcc/
      	* config/gcn/gcn-valu.md (gather<mode>_exec): Move contents ...
      	(mask_gather_load<mode>): ... here, and zero-initialize the
      	destination.
      	(maskload<mode>di): Zero-initialize the destination.
      	* config/gcn/gcn.c:
      Andrew Stubbs committed
    • analyzer: add extrinsic_state::dump · 42f36563
      gcc/analyzer/ChangeLog:
      	* program-state.cc (extrinsic_state::dump_to_pp): New.
      	(extrinsic_state::dump_to_file): New.
      	(extrinsic_state::dump): New.
      	* program-state.h (extrinsic_state::dump_to_pp): New decl.
      	(extrinsic_state::dump_to_file): New decl.
      	(extrinsic_state::dump): New decl.
      	* sm.cc: Include "pretty-print.h".
      	(state_machine::dump_to_pp): New.
      	* sm.h (state_machine::dump_to_pp): New decl.
      David Malcolm committed
    • analyzer: make extrinsic_state field private · ebe9174e
      gcc/analyzer/ChangeLog:
      	* diagnostic-manager.cc (for_each_state_change): Use
      	extrinsic_state::get_num_checkers rather than accessing m_checkers
      	directly.
      	* program-state.cc (program_state::program_state): Likewise.
      	* program-state.h (extrinsic_state::m_checkers): Make private.
      David Malcolm committed
    • Daily bump. · bba54d62
      GCC Administrator committed
    • analyzer: avoid using <string.h> in malloc-1.c · 3e990d79
      This test assumes that memset and strlen have been marked with
      __attribute__((nonnull)), which isn't necessarily the case for an
      arbitrary <string.h>.  This likely explains these failures:
        FAIL: gcc.dg/analyzer/malloc-1.c  (test for warnings, line 417)
        FAIL: gcc.dg/analyzer/malloc-1.c  (test for warnings, line 418)
        FAIL: gcc.dg/analyzer/malloc-1.c  (test for warnings, line 425)
        FAIL: gcc.dg/analyzer/malloc-1.c  (test for warnings, line 429)
      seen in https://gcc.gnu.org/ml/gcc-testresults/2020-01/msg01608.html
      on x86_64-apple-darwin18.
      
      Fix it by using the __builtin_ forms.
      
      gcc/testsuite/ChangeLog:
      	* gcc.dg/analyzer/malloc-1.c: Remove include of <string.h>.
      	Use __builtin_ forms of memset and strlen throughout.
      David Malcolm committed
    • analyzer: convert conditionals-2.c to a torture test · e34ad101
      gcc/testsuite/ChangeLog:
      	* gcc.dg/analyzer/conditionals-2.c: Move to...
      	* gcc.dg/analyzer/torture/conditionals-2.c: ...here, converting
      	to a torture test.  Remove redundant include.
      David Malcolm committed
    • analyzer: fix ICE in __builtin_isnan (PR 93356) · e978955d
      PR analyzer/93356 reports an ICE handling __builtin_isnan due to a
      failing assertion:
        674     gcc_assert (lhs_ec_id != rhs_ec_id);
      with op=UNORDERED_EXPR.
      when attempting to add an UNORDERED_EXPR constraint.
      
      This is an overzealous assertion, but underlying it are various forms of
      sloppiness regarding NaN within the analyzer:
      
        (a) the assumption in the constraint_manager that equivalence classes
        are reflexive (X == X), which isn't the case for NaN.
      
        (b) Hardcoding the "honor_nans" param to false when calling
        invert_tree_comparison throughout the analyzer.
      
        (c) Ignoring ORDERED_EXPR, UNORDERED_EXPR, and the UN-prefixed
        comparison codes.
      
      I wrote a patch for this which tracks the NaN-ness of floating-point
      values and uses this to address all of the above.
      
      However, to minimize changes in gcc 10 stage 4, here's a simpler patch
      which rejects attempts to query or add constraints on floating-point
      values, instead treating any floating-point comparison as "unknown", and
      silently dropping the constraints at edges.
      
      gcc/analyzer/ChangeLog:
      	PR analyzer/93356
      	* region-model.cc (region_model::eval_condition): In both
      	overloads, bail out immediately on floating-point types.
      	(region_model::eval_condition_without_cm): Likewise.
      	(region_model::add_constraint): Likewise.
      
      gcc/testsuite/ChangeLog:
      	PR analyzer/93356
      	* gcc.dg/analyzer/conditionals-notrans.c (test_float_selfcmp):
      	Add.
      	* gcc.dg/analyzer/conditionals-trans.c: Mark floating point
      	comparison test as failing.
      	(test_float_selfcmp): Add.
      	* gcc.dg/analyzer/data-model-1.c: Mark floating point comparison
      	tests as failing.
      	* gcc.dg/analyzer/torture/pr93356.c: New test.
      
      gcc/ChangeLog:
      	PR analyzer/93356
      	* doc/analyzer.texi (Limitations): Note that constraints on
      	floating-point values are currently ignored.
      David Malcolm committed
  2. 30 Jan, 2020 25 commits
    • Mark switch expression as used to avoid bogus warning · f9eb0973
              PR c/88660
              * c-parser.c (c_parser_switch_statement): Make sure to request
              marking the switch expr as used.
      
              PR c/88660
              * gcc.dg/pr88660.c: New test.
      Jeff Law committed
    • cgraph: Avoid creating multiple *.localalias aliases with the same name [PR93384] · 5fb07870
      The following testcase FAILs on powerpc64le-linux with assembler errors, as we
      emit a call to bar.localalias, then .set bar.localalias, bar twice and then
      another call to bar.localalias.  The problem is that bar.localalias can be created
      at various stages and e.g. ipa-pure-const can slightly adjust the original decl,
      so that the existing bar.localalias isn't considered usable (different
      flags_from_decl_or_type).  In that case, we'd create another bar.localalias, which
      clashes with the existing name.
      
      Fixed by retrying with another name if it is already present.  The various localalias
      aliases shouldn't be that many, from different partitions they would be lto_priv
      suffixed and in most cases they would already have the same type/flags/attributes.
      
      2020-01-30  Jakub Jelinek  <jakub@redhat.com>
      
      	PR lto/93384
      	* symtab.c (symtab_node::noninterposable_alias): If localalias
      	already exists, but is not usable, append numbers after it until
      	a unique name is found.  Formatting fix.
      
      	* gcc.dg/lto/pr93384_0.c: New test.
      	* gcc.dg/lto/pr93384_1.c: New file.
      Jakub Jelinek committed
    • combine: Punt on out of range rotate counts [PR93505] · 56b92750
      What happens on this testcase is with the out of bounds rotate we get:
      Trying 13 -> 16:
         13: r129:SI=r132:DI#0<-<0x20
            REG_DEAD r132:DI
         16: r123:DI=r129:SI<0
            REG_DEAD r129:SI
      Successfully matched this instruction:
      (set (reg/v:DI 123 [ <retval> ])
          (const_int 0 [0]))
      during combine.  So, perhaps we could also change simplify-rtx.c to punt
      if it is out of bounds rather than trying to optimize anything.
      Or, but probably GCC11 material, if we decide that ROTATE/ROTATERT doesn't
      have out of bounds counts or introduce targetm.rotate_truncation_mask,
      we should truncate the argument instead of punting.
      Punting is better for backports though.
      
      2020-01-30  Jakub Jelinek  <jakub@redhat.com>
      
      	PR middle-end/93505
      	* combine.c (simplify_comparison) <case ROTATE>: Punt on out of range
      	rotate counts.
      
      	* gcc.c-torture/compile/pr93505.c: New test.
      Jakub Jelinek committed
    • c++: Fix -Wtype-limits in templates. · 4dd468a0
      When instantiating a template tsubst_copy_and_build suppresses -Wtype-limits
      warnings about e.g. == always being false because it might not always be
      false for an instantiation with other template arguments.  But we should
      warn if the operands don't depend on template arguments.
      
      	PR c++/82521
      	* pt.c (tsubst_copy_and_build) [EQ_EXPR]: Only suppress warnings if
      	the expression was dependent before substitution.
      Jason Merrill committed
    • Remove check for maximum symbol name length. · 004ac7b7
              PR fortran/87103
              * expr.c (gfc_check_conformance): Check vsnprintf for truncation.
              * iresolve.c (gfc_get_string): Likewise.
              * symbol.c (gfc_new_symbol): Remove check for maximum symbol
              name length.  Remove redundant 0 setting of new calloc()ed
              gfc_symbol.
      Andrew Benson committed
    • Add LTGT operator support for amdgcn · 59e6d62b
      Fixes ICE in testcase gcc.dg/pr81228.c
      
      2020-01-30  Andrew Stubbs  <ams@codesourcery.com>
      
      	gcc/
      	* config/gcn/gcn.c (print_operand): Handle LTGT.
      	* config/gcn/predicates.md (gcn_fp_compare_operator): Allow ltgt.
      Andrew Stubbs committed
    • Fix "regression" reported by c6x testing. · e0678350
      	* gcc.dg/tree-ssa/ssa-dse-26.c: Make existing dg-final scan
      	conditional on !c6x.  Add dg-final scan pattern for c6x.
      Jeff Law committed
    • PR middle-end/92323 - bogus -Warray-bounds after unrolling despite __builtin_unreachable · 97b40c39
      gcc/testsuite/ChangeLog:
      	* gcc.dg/Warray-bounds-57.c: New test.
      Martin Sebor committed
    • dump CTORs properly wrapped with _Literal with -gimple · bba18325
      This wraps { ... } in _Literal (type) for consumption by the GIMPLE FE.
      
      2020-01-30  Richard Biener  <rguenther@suse.de>
      
      	* tree-pretty-print.c (dump_generic_node): Wrap VECTOR_CST
      	and CONSTRUCTOR in _Literal (type) with TDF_GIMPLE.
      Richard Biener committed
    • analyzer: avoid comparisons between uncomparable types (PR 93450) · d177c49c
      PR analyzer/93450 reports an ICE trying to fold an EQ_EXPR comparison
      of (int)0 with (float)Inf.
      
      Most comparisons inside the analyzer come from gimple conditions, for
      which the necessary casts have already been added.
      
      This one is done inside constant_svalue::eval_condition as part of
      purging sm-state for an unknown function call, and fails to check
      the types being compared, leading to the ICE.
      
      sm_state_map::set_state calls region_model::eval_condition_without_cm in
      order to handle pointer equality (so that e.g. (void *)&r and (foo *)&r
      transition together), which leads to this code generating a bogus query
      to see if the two constants are equal.
      
      This patch fixes the ICE in two ways:
      
      - It avoids generating comparisons within
        constant_svalue::eval_condition unless the types are equal (thus for
        constants, but not for pointer values, which are handled by
        region_svalue).
      
      - It updates sm_state_map::set_state to bail immediately if the new
        state is the same as the old one, thus avoiding the above for the
        common case where an svalue_id has no sm-state (such as for the int
        and float constants in the reproducer), for which the above becomes a
        no-op.
      
      gcc/analyzer/ChangeLog:
      	PR analyzer/93450
      	* program-state.cc (sm_state_map::set_state): For the overload
      	taking an svalue_id, bail out if the set_state on the ec does
      	nothing.  Convert the latter's return type from void to bool,
      	returning true if anything changed.
      	(sm_state_map::impl_set_state): Convert the return type from void
      	to bool, returning true if the state changed.
      	* program-state.h (sm_state_map::set_state): Convert return type
      	from void to bool.
      	(sm_state_map::impl_set_state): Likewise.
      	* region-model.cc (constant_svalue::eval_condition): Only call
      	fold_build2 if the types are the same.
      
      gcc/testsuite/ChangeLog:
      	PR analyzer/93450
      	* gcc.dg/analyzer/torture/pr93450.c: New test.
      David Malcolm committed
    • Fix ICE in pa_elf_select_rtx_section. · 64464e5f
      	2020-01-30  John David Anglin  <danglin@gcc.gnu.org>
      
      	* config/pa/pa.c (pa_elf_select_rtx_section): Place function pointers
      	without a DECL in .data.rel.ro.local.
      John David Anglin committed
    • arm: Fix uaddvdi4 expander [PR93494] · efd26bbc
      uaddvdi4 expander has an optimization for the low 32-bits of the 2nd input
      operand known to be 0.  Unfortunately, in that case it only emits copying of
      the low 32 bits to the low 32 bits of the destination, but doesn't emit the
      addition with overflow detection for the high 64 bits.
      Well, to be precise, it emits it, but into an RTL sequence returned by
      gen_uaddvsi4, but that sequence isn't emitted anywhere.
      
      2020-01-30  Jakub Jelinek  <jakub@redhat.com>
      
      	PR target/93494
      	* config/arm/arm.md (uaddvdi4): Actually emit what gen_uaddvsi4
      	returned.
      
      	* gcc.c-torture/execute/pr93494.c: New test.
      Jakub Jelinek committed
    • Skip plugin-{gcn,hsa} for (-m)x32 (PR bootstrap/93409) · 5ab5d81b
              PR bootstrap/93409
              * plugin/configfrag.ac (enable_offload_targets): Skip
              HSA and GCN plugin besides -m32 also for -mx32.
              * configure: Regenerate.
      Tobias Burnus committed
    • Add testcase of PR c++/90338, already fixed in trunk. · b0e9b18e
      	PR c++/90338
      	* g++.dg/pr90338.C: New.
      Paolo Carlini committed
    • i386: Optimize {,v}{,p}movmsk{b,ps,pd} followed by sign extension [PR91824] · d37c81f4
      Some time ago, patterns were added to optimize move mask followed by zero
      extension from 32 bits to 64 bit.  As the testcase shows, the intrinsics
      actually return int, not unsigned int, so it will happen quite often that
      one actually needs sign extension instead of zero extension.  Except for
      vpmovmskb with 256-bit operand, sign vs. zero extension doesn't make a
      difference, as we know the bit 31 will not be set (the source will have 2 or
      4 doubles, 4 or 8 floats or 16 or 32 chars).
      So, for the floating point patterns, this patch just uses a code iterator
      so that we handle both zero extend and sign extend, and for the byte one
      adds a separate pattern for the 128-bit operand.
      
      2020-01-30  Jakub Jelinek  <jakub@redhat.com>
      
      	PR target/91824
      	* config/i386/sse.md
      	(*<sse>_movmsk<ssemodesuffix><avxsizesuffix>_zext): Renamed to ...
      	(*<sse>_movmsk<ssemodesuffix><avxsizesuffix>_<u>ext): ... this.  Use
      	any_extend code iterator instead of always zero_extend.
      	(*<sse>_movmsk<ssemodesuffix><avxsizesuffix>_zext_lt): Renamed to ...
      	(*<sse>_movmsk<ssemodesuffix><avxsizesuffix>_<u>ext_lt): ... this.
      	Use any_extend code iterator instead of always zero_extend.
      	(*<sse>_movmsk<ssemodesuffix><avxsizesuffix>_zext_shift): Renamed to ...
      	(*<sse>_movmsk<ssemodesuffix><avxsizesuffix>_<u>ext_shift): ... this.
      	Use any_extend code iterator instead of always zero_extend.
      	(*sse2_pmovmskb_ext): New define_insn.
      	(*sse2_pmovmskb_ext_lt): New define_insn_and_split.
      
      	* gcc.target/i386/pr91824-2.c: New test.
      Jakub Jelinek committed
    • i386: Optimize popcnt followed by zero/sign extension [PR91824] · b285bebe
      Like any other instruction with 32-bit GPR destination operand in 64-bit
      mode, popcntl also clears the upper 32 bits of the register (and other bits
      too, it can return only 0 to 32 inclusive).
      
      During combine, the zero or sign extensions of it show up as paradoxical
      subreg of the popcount & 63, there 63 is the smallest power of two - 1 mask
      that can represent all the 0 to 32 inclusive values.
      
      2020-01-30  Jakub Jelinek  <jakub@redhat.com>
      
      	PR target/91824
      	* config/i386/i386.md (*popcountsi2_zext): New define_insn_and_split.
      	(*popcountsi2_zext_falsedep): New define_insn.
      
      	* gcc.target/i386/pr91824-1.c: New test.
      Jakub Jelinek committed
    • fortran: Fix up ISO_Fortran_binding_15.f90 failures [PR92123] · 2595f25c
      This is something that has been discussed already a few months ago, but
      seems to have stalled.  Here is Paul's patch from the PR except for the
      TREE_STATIC hunk which is wrong, and does the most conservative fn spec
      tweak for the problematic two builtins we are aware of (to repeat what is in
      the PR, both .wR and .ww are wrong for these builtins that transform one
      layout of an descriptor to another one; while the first pointer is properly
      marked that we only store to what it points to, from the second pointer
      we copy and reshuffle the content and store into the first one; if there
      wouldn't be any pointers, ".wr" would be just fine, but as there is a
      pointer and that pointer is copied to the area pointed by first argument,
      the pointer effectively leaks that way, so we e.g. can't optimize stores
      into what the data pointer in the descriptor points to).  I haven't
      analyzed other fn spec attributes in the FE, but think it is better to
      fix at least this one we have analyzed.
      
      2020-01-30  Paul Thomas  <pault@gcc.gnu.org>
      	    Jakub Jelinek  <jakub@redhat.com>
      
      	PR fortran/92123
      	* trans-decl.c (gfc_get_symbol_decl): Call gfc_defer_symbol_init for
      	CFI descs.
      	(gfc_build_builtin_function_decls): Use ".w." instead of ".ww" or ".wR"
      	for gfor_fndecl_{cfi_to_gfc,gfc_to_cfi}.
      	(convert_CFI_desc): Handle references to CFI descriptors.
      
      Co-authored-by: Paul Thomas <pault@gcc.gnu.org>
      Jakub Jelinek committed
    • Regenerate configure for 54b3d52c · e0332517
      Commit 54b3d52c ("Emit .note.GNU-stack for hard-float linux targets.")
      was missing generated files.  Add them now.
      
      gcc/ChangeLog:
      
      2020-01-30  Dragan Mladjenovic  <dmladjenovic@wavecomp.com>
      
      	* config.in: Regenerated.
      	* configure: Regenerated.
      Dragan Mladjenovic committed
    • Use promise in coroutine frame in actor function. · 3904cc10
      By standard, coroutine body should be encapsulated in try-catch block
      as following:
        try {
          // coroutine body
        } catch(...) {
          promise.unhandled_exception();
        }
      Given above try-catch block is implemented in the coroutine actor
      function called by coroutine ramp function, so the promise should
      be accessed via actor function's coroutine frame pointer argument,
      rather than the ramp function's coroutine frame variable.
      
      This patch cleans code a bit to make fix easy.
      
      gcc/cp
          * coroutines.cc (act_des_fn): New.
          (morph_fn_to_coro): Call act_des_fn to build actor/destroy decls.
          Access promise via actor function's frame pointer argument.
          (build_actor_fn, build_destroy_fn): Use frame pointer argument.
      Bin Cheng committed
    • Handle CO_AWAIT_EXPR in conversion in co_await_expander. · 3b35b3d4
      Function co_await_expander expands CO_AWAIT_EXPR and inserts expanded
      code before result of co_await is used, however, it doesn't cover the
      type conversion case and leads to gimplify ICE.  This patch fixes it.
      
      gcc/cp
          * coroutines.cc (co_await_expander): Handle type conversion case.
      
      gcc/testsuite
          * g++.dg/coroutines/co-await-syntax-09-convert.C: New test.
      Bin Cheng committed
    • runtime, syscall: add a couple of hurd build tags · 66af5a22
      Patch by Svante Signell.
      
      Updates PR go/93468
      
      Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/216959
      Ian Lance Taylor committed
    • runtime: update netpoll_hurd.go for go1.14beta1 changes · 68f3759e
      Patch from Svante Signell.
      
      Updates PR go/93468
      
      Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/216958
      Ian Lance Taylor committed
    • c++: Drop alignas restriction for stack variables. · e3b6c052
      Since expand_stack_vars and such know how to deal with variables aligned
      beyond MAX_SUPPORTED_STACK_ALIGNMENT, we shouldn't reject alignas of large
      alignments.  And if we don't do that, there's no point in having
      check_cxx_fundamental_alignment_constraints at all, since
      check_user_alignment already enforces MAX_OFILE_ALIGNMENT.
      
      	PR c++/89357
      	* c-attribs.c (check_cxx_fundamental_alignment_constraints): Remove.
      Jason Merrill committed
    • Daily bump. · 8be8e32f
      GCC Administrator committed
    • testsuite: Fix up tree-ssa/pr92706-1.c on 32-bit targets. · 59da7f96
      The test uses __int128_t, so won't work on targets that don't support it.
      
      2020-01-30  Jakub Jelinek  <jakub@redhat.com>
      
      	PR tree-optimization/92706
      	* gcc.dg/tree-ssa/pr92706-1.c: Require int128 effective target.
      Jakub Jelinek committed
  3. 29 Jan, 2020 8 commits
    • c++: Fix attributes with lambda and trailing return type. · 245e40af
      My fix for 60503 fixed handling of C++11 attributes following the
      lambda-declarator.  My patch for 89640 re-added support for GNU attributes,
      but attributes after the trailing return type were parsed as applying to the
      return type rather than to the function.  This patch adjusts parsing of a
      trailing-return-type to ignore GNU attributes at the end of the declaration
      so that they will be applied to the declaration as a whole.
      
      I also considered parsing the attributes between the closing paren and the
      trailing-return-type, and tried a variety of approaches to implementing
      that, but I think it's better to stick with the documented rule that "An
      attribute specifier list may appear immediately before the comma, '=' or
      semicolon terminating the declaration of an identifier...."  Anyone
      disagree?
      
      Meanwhile, C++ committee discussion about the lack of any way to apply
      attributes to a lambda op() seems to have concluded that they should go
      between the introducer and declarator, so I've implemented that as well.
      
      	PR c++/90333
      	PR c++/89640
      	PR c++/60503
      	* parser.c (cp_parser_type_specifier_seq): Don't parse attributes in
      	a trailing return type.
      	(cp_parser_lambda_declarator_opt): Parse C++11 attributes before
      	parens.
      Jason Merrill committed
    • GCN – call assembler with -mattr=-code-object-v3 (PR93409) · 165255c7
              PR bootstrap/93409
              * config/gcn/gcn-hsa.h (ASM_SPEC): Add -mattr=-code-object-v3 as
              LLVM's assembler changed the default in version 9.
      Tobias Burnus committed
    • c++: Add new test [PR88092] · 11ffae58
      This test got fixed by r10-1976-gdaaa6fcc
      so let's add it to the testsuite.
      
      	PR c++/88092
      	* g++.dg/cpp2a/nontype-class31.C: New test.
      Marek Polacek committed
    • Improve DSE which in turn eliminates the need for jump threading and block… · 0de349f1
      Improve DSE which in turn eliminates the need for jump threading and block duplication for the original testcase in pr89689 which in turn eliminates the false positive -Warray-bounds warning for the original testcase.
      
      	PR tree-optimization/89689
      	* builtins.def (BUILT_IN_OBJECT_SIZE): Make it const rather than pure.
      
      	PR tree-optimization/89689
      	* gcc.dg/pr89689.c: New test.
      Jeff Law committed
    • Revert g-465c7c89 · 2812a284
      The patch caused regressions in gcc.target/sh/pr64345-1.c on
      sh3-linux-gnu and gcc.target/m68k/pr39726.c on m68k-linux-gnu.
      It didn't look like they would be fixable in an acceptably
      non-invasive and unhacky way, so punting till future releases.
      
      2020-01-29  Richard Sandiford  <richard.sandiford@arm.com>
      
      gcc/
      	Revert:
      
      	2020-01-28  Richard Sandiford  <richard.sandiford@arm.com>
      
      	PR rtl-optimization/87763
      	* simplify-rtx.c (simplify_truncation): Extend sign/zero_extract
      	simplification to handle subregs as well as bare regs.
      	* config/i386/i386.md (*testqi_ext_3): Match QI extracts too.
      Richard Sandiford committed
    • c++: Fix template arguments comparison with class NTTP [PR91754] · e3b60da8
      Here we fail to compile the attached test, stating that the use of
      T<s> in T<s>::T() {} is "invalid use of incomplete type".  It is a
      function definition so grokdeclarator checks that the qualifying type
      is complete.
      
      When we parsed the class T, finish_struct gave the class a non-null
      TYPE_SIZE, making it COMPLETE_TYPE_P.  But then we're parsing T<s>,
      a TEMPLATE_ID, in
      
        T<s>::T() {}
      
      so try to lookup_template_class T.  This failed because we couldn't
      find such a class: comp_template_args told us that the argument lists
      don't match, because one of the args was wrapped in a VIEW_CONVERT_EXPR
      to make it look const.  It seems to me that we should see through
      these artificial wrappers and consider the args same.
      
      2020-01-29  Marek Polacek  <polacek@redhat.com>
      
      	PR c++/91754 - Fix template arguments comparison with class NTTP.
      	* pt.c (class_nttp_const_wrapper_p): New.
      	(template_args_equal): See through class_nttp_const_wrapper_p
      	arguments.
      
      	* g++.dg/cpp2a/nontype-class30.C: New test.
      Marek Polacek committed
    • c++: Fix class NTTP with template arguments [PR92948] · 42328405
      This PR points out an ICE with an alias template and class NTTP, but I
      found that there are more issues.  Trouble arise when we use a
      (non-type) template parameter as an argument to the template arg list of
      a template that accepts a class NTTP and a conversion to a class is
      involved, e.g.
      
        struct A { A(int) { } };
        template<A a> struct B { };
      
        template<int X> void fn () {
            B<X> b;
        }
      
      Normally for such a conversion we create a TARGET_EXPR with an
      AGGR_INIT_EXPR that calls a __ct_comp with some arguments, but not in
      this case: when converting X to type A in convert_nontype_argument we
      are in a template and the template parameter 'X' is value-dependent, and
      AGGR_INIT_EXPR don't work in templates.  So it just creates a TARGET_EXPR
      that contains "A::A(*this, X)", but with that overload resolution fails:
        error: no matching function for call to 'A::A(A*, int)'
      That happens because finish_call_expr for a BASELINK creates a dummy
      object, so we have 'this' twice.  I thought for the value-dependent case
      we could use IMPLICIT_CONV_EXPR, as in the patch below.  Note that I
      only do this when we convert to a different type than the type of the
      expr.  The point is to avoid the call to a converting ctor.
      
      The second issue was an ICE in tsubst_copy: when there's a conversion
      like the above involved then
       /* Wrapper to make a C++20 template parameter object const.  */
        op = tsubst_copy (op, args, complain, in_decl);
      might not produce a _ZT... VAR_DECL with const type, so the assert
        gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (op)));
      fails.  Allowing IMPLICIT_CONV_EXPR there probably makes sense.
      
      And since convert_nontype_argument uses value_dependent_expression_p
      a lot, I used a dedicated bool to speed things up.
      
      2020-01-29  Marek Polacek  <polacek@redhat.com>
      
      	PR c++/92948 - Fix class NTTP with template arguments.
      	* pt.c (convert_nontype_argument): Use IMPLICIT_CONV_EXPR when
      	converting a value-dependent expression to a class type.
      	(tsubst_copy) <case VIEW_CONVERT_EXPR>: Allow IMPLICIT_CONV_EXPR
      	as the result of the tsubst_copy call.
      
      	* g++.dg/cpp2a/nontype-class28.C: New test.
      	* g++.dg/cpp2a/nontype-class29.C: New test.
      Marek Polacek committed
    • libstdc++: Fix conformance issues in <stop_token> (PR92895) · 0a8f4feb
      Fix synchronization issues in <stop_token>. Replace shared_ptr with
      _Stop_state_ref and a reference count embedded in the shared state.
      Replace std::mutex with spinlock using one bit of a std::atomic<> that
      also tracks whether a stop request has been made and how many
      stop_source objects share ownership of the state.
      
      	PR libstdc++/92895
      	* include/std/stop_token (stop_token::stop_possible()): Call new
      	_M_stop_possible() function.
      	(stop_token::stop_requested()): Do not use stop_possible().
      	(stop_token::binary_semaphore): New class, as temporary stand-in for
      	std::binary_semaphore.
      	(stop_token::_Stop_cb::_M_callback): Add noexcept to type.
      	(stop_token::_Stop_cb::_M_destroyed, stop_token::_Stop_cb::_M_done):
      	New data members for symchronization with stop_callback destruction.
      	(stop_token::_Stop_cb::_Stop_cb): Make non-template.
      	(stop_token::_Stop_cb::_M_linked, stop_token::_Stop_cb::_S_execute):
      	Remove.
      	(stop_token::_Stop_cb::_M_run): New member function.
      	(stop_token::_Stop_state::_M_stopped, stop_token::_Stop_state::_M_mtx):
      	Remove.
      	(stop_token::_Stop_state::_M_owners): New data member to track
      	reference count for ownership.
      	(stop_token::_Stop_state::_M_value): New data member combining a
      	spinlock, the stop requested flag, and the reference count for
      	associated stop_source objects.
      	(stop_token::_Stop_state::_M_requester): New data member for
      	synchronization with stop_callback destruction.
      	(stop_token::_Stop_state::_M_stop_possible()): New member function.
      	(stop_token::_Stop_state::_M_stop_requested()): Inspect relevant bit
      	of _M_value.
      	(stop_token::_Stop_state::_M_add_owner)
      	(stop_token::_Stop_state::_M_release_ownership)
      	(stop_token::_Stop_state::_M_add_ssrc)
      	(stop_token::_Stop_state::_M_sub_ssrc): New member functions for
      	updating reference counts.
      	(stop_token::_Stop_state::_M_lock, stop_token::_Stop_state::_M_unlock)
      	(stop_token::_Stop_state::_M_lock, stop_token::_Stop_state::_M_unlock)
      	(stop_token::_Stop_state::_M_try_lock)
      	(stop_token::_Stop_state::_M_try_lock_and_stop)
      	(stop_token::_Stop_state::_M_do_try_lock): New member functions for
      	managing spinlock.
      	(stop_token::_Stop_state::_M_request_stop): Use atomic operations to
      	read and update state. Release lock while running callbacks. Use new
      	data members to synchronize with callback destruction.
      	(stop_token::_Stop_state::_M_remove_callback): Likewise.
      	(stop_token::_Stop_state::_M_register_callback): Use atomic operations
      	to read and update state.
      	(stop_token::_Stop_state_ref): Handle type to manage _Stop_state,
      	replacing shared_ptr.
      	(stop_source::stop_source(const stop_source&)): Update reference count.
      	(stop_source::operator=(const stop_source&)): Likewise.
      	(stop_source::~stop_source()): Likewise.
      	(stop_source::stop_source(stop_source&&)): Define as defaulted.
      	(stop_source::operator=(stop_source&&)): Establish postcondition on
      	parameter.
      	(stop_callback): Enforce preconditions on template parameter. Replace
      	base class with data member of new _Cb_impl type.
      	(stop_callback::stop_callback(const stop_token&, Cb&&))
      	(stop_callback::stop_callback(stop_token&&, Cb&&)): Fix TOCTTOU race.
      	(stop_callback::_Cb_impl): New type wrapping _Callback member and
      	defining the _S_execute member function.
      	* testsuite/30_threads/stop_token/stop_callback/deadlock-mt.cc: New
      	test.
      	* testsuite/30_threads/stop_token/stop_callback/deadlock.cc: New test.
      	* testsuite/30_threads/stop_token/stop_callback/destroy.cc: New test.
      	* testsuite/30_threads/stop_token/stop_callback/destructible_neg.cc:
      	New test.
      	* testsuite/30_threads/stop_token/stop_callback/invocable_neg.cc: New
      	test.
      	* testsuite/30_threads/stop_token/stop_callback/invoke.cc: New test.
      	* testsuite/30_threads/stop_token/stop_source/assign.cc: New test.
      	* testsuite/30_threads/stop_token/stop_token/stop_possible.cc: New
      	test.
      Jonathan Wakely committed