Skip to content
Snippets Groups Projects
  1. Nov 14, 2022
  2. Nov 13, 2022
    • David Malcolm's avatar
      analyzer: new warning: -Wanalyzer-tainted-assertion [PR106235] · d777b38c
      David Malcolm authored
      
      This patch adds a new -Wanalyzer-tainted-assertion warning to
      -fanalyzer's "taint" mode (which also requires -fanalyzer-checker=taint).
      
      It complains about attacker-controlled values being used in assertions,
      or in any expression affecting control flow that guards a "noreturn"
      function.  As noted in the docs part of the patch, in such cases:
      
        - when assertion-checking is enabled: an attacker could trigger
          a denial of service by injecting an assertion failure
      
        - when assertion-checking is disabled, such as by defining NDEBUG,
          an attacker could inject data that subverts the process, since it
          presumably violates a precondition that is being assumed by the code.
      
      For example, given:
      
      #include <assert.h>
      
      int __attribute__((tainted_args))
      test_tainted_assert (int n)
      {
        assert (n > 0);
        return n * n;
      }
      
      compiling with
        -fanalyzer -fanalyzer-checker=taint
      gives:
      
      t.c: In function 'test_tainted_assert':
      t.c:6:3: warning: use of attacked-controlled value in condition for assertion [CWE-617] [-Wanalyzer-tainted-assertion]
          6 |   assert (n > 0);
            |   ^~~~~~
        'test_tainted_assert': event 1
          |
          |    4 | test_tainted_assert (int n)
          |      | ^~~~~~~~~~~~~~~~~~~
          |      | |
          |      | (1) function 'test_tainted_assert' marked with '__attribute__((tainted_args))'
          |
          +--> 'test_tainted_assert': event 2
                 |
                 |    4 | test_tainted_assert (int n)
                 |      | ^~~~~~~~~~~~~~~~~~~
                 |      | |
                 |      | (2) entry to 'test_tainted_assert'
                 |
               'test_tainted_assert': events 3-6
                 |
                 |/usr/include/assert.h:106:10:
                 |  106 |       if (expr)                                                         \
                 |      |          ^
                 |      |          |
                 |      |          (3) use of attacker-controlled value for control flow
                 |      |          (4) following 'false' branch (when 'n <= 0')...
                 |......
                 |  109 |         __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION);   \
                 |      |         ~~~~~~~~~~~~~
                 |      |         |
                 |      |         (5) ...to here
                 |      |         (6) treating '__assert_fail' as an assertion failure handler due to '__attribute__((__noreturn__))'
                 |
      
      The testcases have various examples for BUG and BUG_ON from the
      Linux kernel; there, the diagnostic treats "panic" as an assertion
      failure handler, due to '__attribute__((__noreturn__))'.
      
      gcc/analyzer/ChangeLog:
      	PR analyzer/106235
      	* analyzer.opt (Wanalyzer-tainted-assertion): New.
      	* checker-path.cc (checker_path::fixup_locations): Pass false to
      	pending_diagnostic::fixup_location.
      	* diagnostic-manager.cc (get_emission_location): Pass true to
      	pending_diagnostic::fixup_location.
      	* pending-diagnostic.cc (pending_diagnostic::fixup_location): Add
      	bool param.
      	* pending-diagnostic.h (pending_diagnostic::fixup_location): Add
      	bool param to decl.
      	* sm-taint.cc (taint_state_machine::m_tainted_control_flow): New.
      	(taint_diagnostic::describe_state_change): Drop "final".
      	(class tainted_assertion): New.
      	(taint_state_machine::taint_state_machine): Initialize
      	m_tainted_control_flow.
      	(taint_state_machine::alt_get_inherited_state): Support
      	comparisons being tainted, based on their arguments.
      	(is_assertion_failure_handler_p): New.
      	(taint_state_machine::on_stmt): Complain about calls to assertion
      	failure handlers guarded by an attacker-controller conditional.
      	Detect attacker-controlled gcond conditionals and gswitch index
      	values.
      	(taint_state_machine::check_control_flow_arg_for_taint): New.
      
      gcc/ChangeLog:
      	PR analyzer/106235
      	* doc/gcc/gcc-command-options/option-summary.rst: Add
      	-Wno-analyzer-tainted-assertion.
      	* doc/gcc/gcc-command-options/options-that-control-static-analysis.rst:
      	Add -Wno-analyzer-tainted-assertion.
      
      gcc/testsuite/ChangeLog:
      	PR analyzer/106235
      	* gcc.dg/analyzer/taint-assert-BUG_ON.c: New test.
      	* gcc.dg/analyzer/taint-assert-macro-expansion.c: New test.
      	* gcc.dg/analyzer/taint-assert.c: New test.
      	* gcc.dg/analyzer/taint-assert-system-header.c: New test.
      	* gcc.dg/analyzer/test-assert.h: New header.
      	* gcc.dg/plugin/analyzer_gil_plugin.c
      	(gil_diagnostic::fixup_location): Add bool param.
      
      Signed-off-by: default avatarDavid Malcolm <dmalcolm@redhat.com>
      d777b38c
    • José Rui Faustino de Sousa's avatar
      Fortran: diagnostics for actual arguments to pointer dummy arguments [PR94104] · 58e7732a
      José Rui Faustino de Sousa authored
      Error message improvement.  In Fortran 2008 actual procedure arguments
      associated with a pointer, intent(in) attribute, dummy argument
      can also have the target attribute, not just pointer.
      
      gcc/fortran/ChangeLog:
      
      	PR fortran/94104
      	* interface.cc (gfc_compare_actual_formal): Improve error message
      	dependent on Fortran standard level.
      
      gcc/testsuite/ChangeLog:
      
      	PR fortran/94104
      	* gfortran.dg/parens_2.f90: Adjust to improved error message.
      	* gfortran.dg/PR94104a.f90: New test.
      	* gfortran.dg/PR94104b.f90: New test.
      58e7732a
    • John David Anglin's avatar
      Skip guality tests on hppa-hpux. · e42b672f
      John David Anglin authored
      The guality check command hangs. This causes TCL errors in
      other tests and slows testsuite execution.
      
      2022-11-13  John David Anglin  <danglin@gcc.gnu.org>
      
      gcc/testsuite/ChangeLog:
      
      	* g++.dg/guality/guality.exp: Skip on hppa*-*-hpux*.
      	* gcc.dg/guality/guality.exp: Likewise.
      	* gfortran.dg/guality/guality.exp: Likewise.
      e42b672f
    • Philipp Tomsich's avatar
      RISC-V: optimize '(a >= 0) ? b : 0' to srai + andn, if compiling for Zbb · 43435c7e
      Philipp Tomsich authored
      If-conversion is turning '(a >= 0) ? b : 0' into a branchless sequence
      	not	a5,a0
      	srai	a5,a5,63
      	and	a0,a1,a5
      missing the opportunity to combine the NOT and AND into an ANDN.
      
      This adds a define_split to help the combiner reassociate the NOT with
      the AND.
      
      gcc/ChangeLog:
      
      	* config/riscv/bitmanip.md: New define_split.
      
      gcc/testsuite/ChangeLog:
      
      	* gcc.target/riscv/zbb-srai-andn.c: New test.
      43435c7e
    • Philipp Tomsich's avatar
      doc: Update Jeff Law's email-address in contrib.rst · 3bf46ea7
      Philipp Tomsich authored
      ChangeLog:
      
      	* doc/contrib.rst: Update Jeff Law's email address.
      3bf46ea7
    • Martin Liska's avatar
      sphinx: include todolist only if INCLUDE_TODO env. set · c64fd694
      Martin Liska authored
      It is confusing that 'Indexes and tables' contains TODO. One gets
      Index by clicking to the Index link.
      
      	PR web/107643
      
      ChangeLog:
      
      	* doc/baseconf.py: Set include_todo tag if INCLUDE_TODO env
      	is set.
      	* doc/indices-and-tables.rst: Use include_todo tag.
      c64fd694
    • Philipp Tomsich's avatar
      RISC-V: costs: support shift-and-add in strength-reduction · f90cb392
      Philipp Tomsich authored
      The strength-reduction implementation in expmed.cc will assess the
      profitability of using shift-and-add using a RTL expression that wraps
      a MULT (with a power-of-2) in a PLUS.  Unless the RISC-V rtx_costs
      function recognizes this as expressing a sh[123]add instruction, we
      will return an inflated cost---thus defeating the optimization.
      
      This change adds the necessary idiom recognition to provide an
      accurate cost for this for of expressing sh[123]add.
      
      Instead on expanding to
      	li	a5,200
      	mulw	a0,a5,a0
      with this change, the expression 'a * 200' is sythesized as:
      	sh2add	a0,a0,a0   // *5 = a + 4 * a
      	sh2add	a0,a0,a0   // *5 = a + 4 * a
      	slli	a0,a0,3    // *8
      
      gcc/ChangeLog:
      
      	* config/riscv/riscv.cc (riscv_rtx_costs): Recognize shNadd,
      	if expressed as a plus and multiplication with a power-of-2.
      	Split costing for MINUS from PLUS.
      
      gcc/testsuite/ChangeLog:
      
      	* gcc.target/riscv/zba-shNadd-07.c: New test.
      f90cb392
    • Martin Liska's avatar
      configure: always set SPHINX_BUILD · 5e749ee3
      Martin Liska authored
      During the Sphinx-migration development, I used
      SPHINX_BUILD='' in order to skip building info and manual
      pages in gcc folder. However, we've got HAS_SPHINX_BUILD
      which is the correct flag for that.
      
      With the patch, one will get a nicer error message when
      sphinx-build is missing and one builds (explicitly) a target which
      depends on it.
      
      	PR other/107620
      
      gcc/ChangeLog:
      
      	* configure: Regenerate.
      	* configure.ac: Always set sphinx-build.
      
      libgomp/ChangeLog:
      
      	* configure: Regenerate.
      	* configure.ac: Always set sphinx-build.
      
      libiberty/ChangeLog:
      
      	* configure: Regenerate.
      	* configure.ac: Always set sphinx-build.
      
      libitm/ChangeLog:
      
      	* configure: Regenerate.
      	* configure.ac: Always set sphinx-build.
      
      libquadmath/ChangeLog:
      
      	* configure: Regenerate.
      	* configure.ac: Always set sphinx-build.
      5e749ee3
    • Joseph Myers's avatar
      ginclude: C2x header version macros · 9a265c97
      Joseph Myers authored
      C2x adds __STDC_VERSION_*_H__ macros to individual headers with
      interface changes compared to C17.  All the new header features in
      headers provided by GCC have now been implemented, so define those
      macros to the value given in the current working draft.
      
      Bootstrapped with no regressions for x86_64-pc-linux-gnu.
      
      gcc/
      	* ginclude/float.h [__STDC_VERSION__ > 201710L]
      	(__STDC_VERSION_FLOAT_H__): New macro.
      	* ginclude/stdarg.h [__STDC_VERSION__ > 201710L]
      	(__STDC_VERSION_STDARG_H__): New macro.
      	* ginclude/stdatomic.h [__STDC_VERSION__ > 201710L]
      	(__STDC_VERSION_STDATOMIC_H__): New macro.
      	* ginclude/stddef.h [__STDC_VERSION__ > 201710L]
      	(__STDC_VERSION_STDDEF_H__): New macro.
      	* ginclude/stdint-gcc.h [__STDC_VERSION__ > 201710L]
      	(__STDC_VERSION_STDINT_H__): New macro.
      	* glimits.h [__STDC_VERSION__ > 201710L]
      	(__STDC_VERSION_LIMITS_H__): New macro.
      
      gcc/testsuite/
      	* gcc.dg/c11-float-8.c, gcc.dg/c11-limits-1.c,
      	gcc.dg/c11-stdarg-4.c, gcc.dg/c11-stdatomic-3.c,
      	gcc.dg/c11-stddef-1.c, gcc.dg/c11-stdint-1.c,
      	gcc.dg/c2x-float-13.c, gcc.dg/c2x-limits-1.c,
      	gcc.dg/c2x-stdarg-5.c, gcc.dg/c2x-stdatomic-1.c,
      	gcc.dg/c2x-stddef-1.c, gcc.dg/c2x-stdint-1.c: New tests.
      9a265c97
    • Jonathan Wakely's avatar
      doc: Remove outdated reference to "core" and front-end downloads · 05432288
      Jonathan Wakely authored
      gcc/ChangeLog:
      
      	* doc/install/testing.rst: Remove anachronism about separate
      	source tarballs.
      05432288
    • Jonathan Wakely's avatar
      libstdc++: Add C++20 clocks · 1736bf5a
      Jonathan Wakely authored
      Also add the basic types for timezones, without the non-inline
      definitions needed to actually use them.
      
      The get_leap_second_info function currently uses a hardcoded list of
      leap seconds, correct as of the end of 2022. That needs to be replaced
      with a dynamically generated list read from the system tzdata. That will
      be done in a later patch.
      
      libstdc++-v3/ChangeLog:
      
      	* include/std/chrono (utc_clock, tai_clock, gps_clock): Define.
      	(clock_time_conversion, clock_cast): Define.
      	(sys_info, local_info): Define structs for timezone information.
      	(nonexistent_local_time, ambiguous_local_time): Define
      	exceptions for invalid times.
      	(time_zone, time_zone_link, leap_second, zoned_traits, tzdb)
      	(tzdb_list): Define classes representing time zones.
      	(get_leap_second_info): Define new function returning leap
      	second offset for a given time point.
      	* testsuite/std/time/clock/gps/1.cc: New test.
      	* testsuite/std/time/clock/tai/1.cc: New test.
      	* testsuite/std/time/clock/utc/1.cc: New test.
      1736bf5a
    • Jonathan Wakely's avatar
      libstdc++: Implement C++20 <format> [PR104166] · 1d9454ab
      Jonathan Wakely authored
      This doesn't add the newer C++23 features like formatting ranges
      and escaped string prsentation types.
      
      However, C++23 extended floating-point types are supported, as are
      128-bit integers.
      
      It could do with more tests.
      
      libstdc++-v3/ChangeLog:
      
      	PR libstdc++/104166
      	* include/Makefile.am (std_headers): Add <format>.
      	* include/Makefile.in: Regenerate.
      	* include/precompiled/stdc++.h: Add <format>.
      	* include/std/format: New file.
      	* python/libstdcxx/v6/printers.py (StdFormatArgsPrinter): New
      	printer for std::format_args.
      	* testsuite/std/format/arguments/args.cc: New test.
      	* testsuite/std/format/error.cc: New test.
      	* testsuite/std/format/formatter.cc: New test.
      	* testsuite/std/format/functions/format.cc: New test.
      	* testsuite/std/format/functions/format_to_n.cc: New test.
      	* testsuite/std/format/functions/size.cc: New test.
      	* testsuite/std/format/functions/vformat_to.cc: New test.
      	* testsuite/std/format/parse_ctx.cc: New test.
      	* testsuite/std/format/string.cc: New test.
      	* testsuite/std/format/string_neg.cc: New test.
      1d9454ab
    • Jonathan Wakely's avatar
      libstdc++: Allow std::to_chars for 128-bit integers in strict mode · d4ba3b36
      Jonathan Wakely authored
      This allows std::format to support __int128 when __STRICT_ANSI__ is
      defined, which previously failed because __int128 is not an integral
      type in strict mode.
      
      With these changes, std::to_chars still rejects 128-bit integers in
      strict mode, but std::format will be able to use __detail::__to_chars_i
      for unsigned __int128.
      
      libstdc++-v3/ChangeLog:
      
      	* include/bits/charconv.h (__integer_to_chars_is_unsigned):
      	New variable template.
      	(__to_chars_len, __to_chars_10_impl): Use variable template in
      	assertions to allow unsigned __int128 in strict mode.
      	* include/std/charconv (__to_chars, __to_chars_16)
      	(__to_chars_10, __to_chars_8, __to_chars_2): Likewise.
      d4ba3b36
  3. Nov 06, 2021
  4. Nov 13, 2022
  5. Nov 12, 2022
    • Jakub Jelinek's avatar
      libstdc++: Fix up to_chars ppc64le _Float128 overloads [PR107636] · ec6c2029
      Jakub Jelinek authored
      As reported, I've misplaced __extension__ keywords in these cases
      (wanted not to have them on the whole inlines because _Float128 is
      completely standard now while __float128 is not, but before return
      it is a syntax error.
      I've verified on a short testcase that both g++ and clang++ accept
      __extension__ after return keyword.
      
      2022-11-12  Jakub Jelinek  <jakub@redhat.com>
      
      	PR libstdc++/107636
      	* include/std/charconv (to_chars): Fix up powerpc64le _Float128
      	overload __extension__ placement.
      ec6c2029
    • Harald Anlauf's avatar
      Fortran: fix treatment of character, value, optional dummy arguments [PR107444] · 59a63247
      Harald Anlauf authored
      Fix handling of character dummy arguments that have the optional+value
      attribute.  Change name of internal symbols that carry the hidden presence
      status of optional arguments to distinguish them from the internal hidden
      character length.  Update documentation to clarify the gfortran ABI.
      
      gcc/fortran/ChangeLog:
      
      	PR fortran/107444
      	* trans-decl.cc (create_function_arglist): Extend presence status
      	to all intrinsic types, and change prefix of internal symbol to '.'.
      	* trans-expr.cc (gfc_conv_expr_present): Align to changes in
      	create_function_arglist.
      	(gfc_conv_procedure_call): Fix generation of procedure arguments for
      	the case of character dummy arguments with optional+value attribute.
      	* trans-types.cc (gfc_get_function_type): Synchronize with changes
      	to create_function_arglist.
      	* doc/gfortran/naming-and-argument-passing-conventions.rst: Clarify
      	the gfortran argument passing conventions with regard to OPTIONAL
      	dummy arguments of intrinsic type.
      
      gcc/testsuite/ChangeLog:
      
      	PR fortran/107444
      	* gfortran.dg/optional_absent_7.f90: Adjust regex.
      	* gfortran.dg/optional_absent_8.f90: New test.
      59a63247
Loading