Bug 98512 - [11/12 Regression] “#pragma GCC diagnostic ignored” ineffective in conjunction with alias attribute
Summary: [11/12 Regression] “#pragma GCC diagnostic ignored” ineffective in conjunctio...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: 12.0
Assignee: Martin Sebor
URL:
Keywords: diagnostic, patch
Depends on:
Blocks:
 
Reported: 2021-01-04 13:47 UTC by Florian Weimer
Modified: 2021-11-12 19:45 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 10.2.0, 12.0
Known to fail: 11.2.0
Last reconfirmed: 2021-01-05 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Weimer 2021-01-04 13:47:54 UTC
The following test case has been extracted from a glibc build failure on powerpc64le, but it appears to be target-independent.

This produces a -WWstringop-overread warning at -O2, even though the warning has been suppressed.

void *
__rawmemchr_ppc (const void *s, int c)
{
#pragma GCC diagnostics push
#pragma GCC diagnostic ignored "-Wstringop-overflow="
#pragma GCC diagnostic ignored "-Wstringop-overread"
  if (c != 0)
    return __builtin_memchr (s, c, (unsigned long)-1);
#pragma GCC diagnostics pop
  return (char *)s + __builtin_strlen (s);
}
extern __typeof (__rawmemchr_ppc) __EI___rawmemchr_ppc
  __attribute__((alias ("__rawmemchr_ppc")));

t.c:8:12: warning: ‘__builtin_memchr’ specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overread]               
    8 |     return __builtin_memchr (s, c, (unsigned long)-1);                 
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Seen with: 11.0.0 20210104 (experimental)
Comment 1 Martin Sebor 2021-01-05 00:34:33 UTC
The warning looks for the location into which the memchr caller was inlined (to see if the caller is defined in a system header but itself called from user code).  Without the alias it doesn't find one (because the caller isn't called from anywhere) but with the alias it finds the memchr caller, __rawmemchr_ppc.
Comment 2 Martin Sebor 2021-01-05 00:35:00 UTC
Let me see what can be done about it.
Comment 3 Martin Sebor 2021-01-18 23:54:50 UTC
My patches for pr98664 and pr98465 seem to also fix this.
Comment 4 Martin Sebor 2021-01-19 19:02:43 UTC
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2021-January/563862.html

A workaround until the patch is approved, is to move the warning suppression pragmas above the the function declaration.
Comment 5 Florian Weimer 2021-01-25 19:44:15 UTC
Note, patch has been superseded: https://gcc.gnu.org/pipermail/gcc-patches/2021-January/564060.html
Comment 6 Martin Sebor 2021-02-19 23:42:26 UTC
The fix has been deferred to GCC 12:
https://gcc.gnu.org/pipermail/gcc-patches/2021-February/565551.html
Comment 7 Martin Liška 2021-05-27 13:55:35 UTC
I noticed that for GCC 11.1 release.
@Florian: Is there any glibc workaround for it?
Comment 8 Florian Weimer 2021-05-27 14:01:33 UTC
This glibc commit works around the GCC issue:

commit 044e603b698093cf48f6e6229e0b66acf05227e4
Author: Florian Weimer <fweimer@redhat.com>
Date:   Fri Feb 19 13:29:00 2021 +0100

    string: Work around GCC PR 98512 in rawmemchr
Comment 9 Martin Liška 2021-05-27 14:08:02 UTC
(In reply to Florian Weimer from comment #8)
> This glibc commit works around the GCC issue:
> 
> commit 044e603b698093cf48f6e6229e0b66acf05227e4
> Author: Florian Weimer <fweimer@redhat.com>
> Date:   Fri Feb 19 13:29:00 2021 +0100
> 
>     string: Work around GCC PR 98512 in rawmemchr

Thanks!
Comment 10 Martin Sebor 2021-06-10 23:31:18 UTC
Latest patch: https://gcc.gnu.org/pipermail/gcc-patches/2021-June/572515.html
Comment 11 GCC Commits 2021-07-02 22:20:12 UTC
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:6feb628a706e86eb3f303aff388c74bdb29e7381

commit r12-1992-g6feb628a706e86eb3f303aff388c74bdb29e7381
Author: Martin Sebor <msebor@redhat.com>
Date:   Fri Jul 2 16:16:31 2021 -0600

    Improve warning suppression for inlined functions [PR98512].
    
    Resolves:
    PR middle-end/98871 - Cannot silence -Wmaybe-uninitialized at declaration site
    PR middle-end/98512 - #pragma GCC diagnostic ignored ineffective in conjunction with alias attribute
    
    gcc/ChangeLog:
    
            PR middle-end/98871
            PR middle-end/98512
            * diagnostic.c (get_any_inlining_info): New.
            (update_effective_level_from_pragmas): Handle inlining context.
            (diagnostic_enabled): Same.
            (diagnostic_report_diagnostic): Same.
            * diagnostic.h (struct diagnostic_info): Add ctor.
            (struct diagnostic_context): Add new member.
            * tree-diagnostic.c (set_inlining_locations): New.
            (tree_diagnostics_defaults): Set new callback pointer.
Comment 12 GCC Commits 2021-07-06 19:43:32 UTC
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:6d3bab5d5adb3e28ddb16c97b0831efdea23cf7d

commit r12-2087-g6d3bab5d5adb3e28ddb16c97b0831efdea23cf7d
Author: Martin Sebor <msebor@redhat.com>
Date:   Tue Jul 6 13:41:02 2021 -0600

    Improve warning suppression for inlined functions.
    
    Resolves:
    PR middle-end/98871 - Cannot silence -Wmaybe-uninitialized at declaration site
    PR middle-end/98512 - #pragma GCC diagnostic ignored ineffective in conjunction with alias attribute
    
    gcc/ChangeLog:
    
            * builtins.c (warn_string_no_nul): Remove %G.
            (maybe_warn_for_bound): Same.
            (warn_for_access): Same.
            (check_access): Same.
            (check_strncat_sizes): Same.
            (expand_builtin_strncat): Same.
            (expand_builtin_strncmp): Same.
            (expand_builtin): Same.
            (expand_builtin_object_size): Same.
            (warn_dealloc_offset): Same.
            (maybe_emit_free_warning): Same.
            * calls.c (maybe_warn_alloc_args_overflow): Same.
            (maybe_warn_nonstring_arg): Same.
            (maybe_warn_rdwr_sizes): Same.
            * expr.c (expand_expr_real_1): Remove %K.
            * gimple-fold.c (gimple_fold_builtin_strncpy): Remove %G.
            (gimple_fold_builtin_strncat): Same.
            * gimple-ssa-sprintf.c (format_directive): Same.
            (handle_printf_call): Same.
            * gimple-ssa-warn-alloca.c (pass_walloca::execute): Same.
            * gimple-ssa-warn-restrict.c (maybe_diag_overlap): Same.
            (maybe_diag_access_bounds): Same.  Call gimple_location.
            (check_bounds_or_overlap): Same.
            * trans-mem.c (ipa_tm_scan_irr_block): Remove %K.  Simplify.
            * tree-ssa-ccp.c (pass_post_ipa_warn::execute): Remove %G.
            * tree-ssa-strlen.c (maybe_warn_overflow): Same.
            (maybe_diag_stxncpy_trunc): Same.
            (handle_builtin_stxncpy_strncat): Same.
            (maybe_warn_pointless_strcmp): Same.
            * tree-ssa-uninit.c (maybe_warn_operand): Same.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/Wobjsize-1.c: Prune expected output.
            * gcc.dg/Warray-bounds-71.c: New test.
            * gcc.dg/Warray-bounds-71.h: New test header.
            * gcc.dg/Warray-bounds-72.c: New test.
            * gcc.dg/Warray-bounds-73.c: New test.
            * gcc.dg/Warray-bounds-74.c: New test.
            * gcc.dg/Warray-bounds-75.c: New test.
            * gcc.dg/Wfree-nonheap-object-4.c: Adjust expected output.
            * gcc.dg/Wfree-nonheap-object-5.c: New test.
            * gcc.dg/Wfree-nonheap-object-6.c: New test.
            * gcc.dg/pragma-diag-10.c: New test.
            * gcc.dg/pragma-diag-9.c: New test.
            * gcc.dg/uninit-suppress_3.c: New test.
            * gcc.dg/pr79214.c: Xfail tests.
            * gcc.dg/tree-ssa/builtin-sprintf-warn-27.c: New test.
            * gcc.dg/format/c90-printf-1.c: Adjust expected output.
Comment 13 Martin Sebor 2021-11-12 19:45:43 UTC
Fixed in GCC 12.  The patch is not suitable for backporting to release branches.