public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/98664] New: inconsistent --Wfree-nonheap-object for inlined calls to system headers
@ 2021-01-13 21:20 msebor at gcc dot gnu.org
  2021-01-14  2:19 ` [Bug middle-end/98664] " msebor at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-01-13 21:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98664

            Bug ID: 98664
           Summary: inconsistent --Wfree-nonheap-object for inlined calls
                    to system headers
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

-Wfree-nonheap-object (as well as -Wmismatched-new-delete and
-Wmismatched-dealloc) should be issued for invalid calls to allocation and
deallocation functions made in system headers and inlined into user code (see
pr57111 comment 16).  The test case below shows this doesn't work consistently.
 When the program is compiled without -g only one invalid call is diagnosed. 
But when it's compiled with -g  both are.  

This bug captures the subset related to the -g inconsistency discussed in
pr98465.

Without -g:

$ cat t.C && gcc -O2 -S -Wall -Wextra t.C
# 1 "t.h" 1 3

struct S
{
  void *p;
  void f0 (void *q) { p = q; }
  void f1 (void *q) { f0 (q); }

  void g0 (void) { __builtin_free (p); }
  void g1 (void) { g0 (); }
};

# 1 "t.C"

int x;

__attribute__ ((noipa)) void f0 (struct S *p)
{
  p->f0 (&x);
  p->g0 ();
}

__attribute__ ((noipa)) void f1 (struct S *p)
{
  p->f1 (&x);
  p->g1 ();
}

In file included from t.C:1:
In member function ‘void S::g0()’,
    inlined from ‘void f0(S*)’ at t.C:7:9:
t.h:8:35: warning: ‘void __builtin_free(void*)’ called on unallocated object
‘x’ [-Wfree-nonheap-object]
In file included from t.C:1:
t.C: In function ‘void f0(S*)’:
t.C:2:5: note: declared here
    2 | 
      |     ^


With -g:

$ gcc -O2 -S -Wall -Wextra -g t.C
In file included from t.C:1:
In member function ‘void S::g0()’,
    inlined from ‘void f0(S*)’ at t.C:7:9:
t.h:8:35: warning: ‘void __builtin_free(void*)’ called on unallocated object
‘x’ [-Wfree-nonheap-object]
In file included from t.C:1:
t.C: In function ‘void f0(S*)’:
t.C:2:5: note: declared here
    2 | 
      |     ^
In file included from t.C:1:
In member function ‘void S::g0()’,
    inlined from ‘void S::g1()’ at t.h:9:23,
    inlined from ‘void f1(S*)’ at t.C:13:9:
t.h:8:35: warning: ‘void __builtin_free(void*)’ called on unallocated object
‘x’ [-Wfree-nonheap-object]
In file included from t.C:1:
t.C: In function ‘void f1(S*)’:
t.C:2:5: note: declared here
    2 | 
      |     ^

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/98664] inconsistent --Wfree-nonheap-object for inlined calls to system headers
  2021-01-13 21:20 [Bug middle-end/98664] New: inconsistent --Wfree-nonheap-object for inlined calls to system headers msebor at gcc dot gnu.org
@ 2021-01-14  2:19 ` msebor at gcc dot gnu.org
  2021-01-19 22:11 ` cvs-commit at gcc dot gnu.org
  2021-01-19 22:13 ` msebor at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-01-14  2:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98664

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-01-14
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The change below fixes the problem and lets both calls be diagnosed regardless
of -g:

index 02a7a56f0f9..a7464369d73 100644
--- a/gcc/tree-ssa-live.c
+++ b/gcc/tree-ssa-live.c
@@ -558,16 +558,13 @@ remove_unused_scope_block_p (tree scope, bool
in_ctor_dtor_block)
    else if (!flag_auto_profile && debug_info_level == DINFO_LEVEL_NONE
            && !optinfo_wants_inlining_info_p ())
      {
-       /* Even for -g0 don't prune outer scopes from artificial
-         functions, otherwise diagnostics using tree_nonartificial_location
-         will not be emitted properly.  */
+       /* Even for -g0 don't prune outer scopes from inlined functions,
+         otherwise late diagnostics from such functions will not be
+         emitted or suppressed properly.  */
        if (inlined_function_outer_scope_p (scope))
         {
           tree ao = BLOCK_ORIGIN (scope);
-          if (ao
-              && TREE_CODE (ao) == FUNCTION_DECL
-              && DECL_DECLARED_INLINE_P (ao)
-              && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao)))
+          if (ao && TREE_CODE (ao) == FUNCTION_DECL)
             unused = false;
         }
      }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/98664] inconsistent --Wfree-nonheap-object for inlined calls to system headers
  2021-01-13 21:20 [Bug middle-end/98664] New: inconsistent --Wfree-nonheap-object for inlined calls to system headers msebor at gcc dot gnu.org
  2021-01-14  2:19 ` [Bug middle-end/98664] " msebor at gcc dot gnu.org
@ 2021-01-19 22:11 ` cvs-commit at gcc dot gnu.org
  2021-01-19 22:13 ` msebor at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-01-19 22:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98664

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:9693e255ee2536c6823640eba5d0163c2b401161

commit r11-6801-g9693e255ee2536c6823640eba5d0163c2b401161
Author: Martin Sebor <msebor@redhat.com>
Date:   Tue Jan 19 15:10:30 2021 -0700

    PR middle-end/98664 - inconsistent -Wfree-nonheap-object for inlined calls
to system headers

    gcc/ChangeLog:

            PR middle-end/98664
            * tree-ssa-live.c (remove_unused_scope_block_p): Keep scopes for
            all functions, even if they're not declared artificial or inline.
            * tree.c (tree_inlined_location): Use macro expansion location
            only if scope traversal fails to expose one.

    gcc/testsuite/ChangeLog:

            PR middle-end/98664
            * gcc.dg/Wvla-larger-than-4.c: Adjust expected output.
            * gcc.dg/plugin/diagnostic-test-inlining-3.c: Same.
            * g++.dg/warn/Wfree-nonheap-object-5.C: New test.
            * gcc.dg/Wfree-nonheap-object-4.c: New test.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/98664] inconsistent --Wfree-nonheap-object for inlined calls to system headers
  2021-01-13 21:20 [Bug middle-end/98664] New: inconsistent --Wfree-nonheap-object for inlined calls to system headers msebor at gcc dot gnu.org
  2021-01-14  2:19 ` [Bug middle-end/98664] " msebor at gcc dot gnu.org
  2021-01-19 22:11 ` cvs-commit at gcc dot gnu.org
@ 2021-01-19 22:13 ` msebor at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-01-19 22:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98664

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot gnu.org
   Target Milestone|---                         |11.0
           Keywords|                            |patch

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
Patch (https://gcc.gnu.org/pipermail/gcc-patches/2021-January/563515.html)
committed in r11-6801.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-19 22:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-13 21:20 [Bug middle-end/98664] New: inconsistent --Wfree-nonheap-object for inlined calls to system headers msebor at gcc dot gnu.org
2021-01-14  2:19 ` [Bug middle-end/98664] " msebor at gcc dot gnu.org
2021-01-19 22:11 ` cvs-commit at gcc dot gnu.org
2021-01-19 22:13 ` msebor at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).