public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ibm/heads/gcc-9)] Fix setting of DECL_CONTEXT in pushdecl (PR c/93072).
@ 2020-02-04 21:12 Peter Bergner
  0 siblings, 0 replies; only message in thread
From: Peter Bergner @ 2020-02-04 21:12 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7cc6b679a0d0e50c0e1671fefa815dc753554184

commit 7cc6b679a0d0e50c0e1671fefa815dc753554184
Author: Joseph Myers <joseph@codesourcery.com>
Date:   Wed Jan 15 20:52:45 2020 +0000

    Fix setting of DECL_CONTEXT in pushdecl (PR c/93072).
    
    Bug 93072 is a case where the C front end (a) wrongly interprets an
    inline declaration at block scope as indicating that DECL_CONTEXT
    should be set for an inline function and (b) this results in an ICE.
    This is a regression resulting from a previous fix of mine for other
    bugs involving such declarations being wrongly interpreted elsewhere
    as nested function declarations.  The fix is similar to the previous
    fix: use TREE_PUBLIC instead of DECL_EXTERNAL in another place as the
    relevant test to determine whether to set DECL_CONTEXT.  (When a
    variable reaches the code in question in pushdecl, the two are
    equivalent.)
    
    Bootstrapped with no regressions for x86_64-pc-linux-gnu.
    
    	PR c/93072
    gcc/c:
    	* c-decl.c (pushdecl): Use TREE_PUBLIC, not DECL_EXTERNAL, to
    	determine whether to set DECL_CONTEXT.
    
    gcc/testsuite:
    	* gcc.dg/inline-42.c, gcc.dg/inline-43.c: New tests.
    
    (cherry picked from commit e2346a33b05871fc065815d4cfd531dfa0195507)

Diff:
---
 gcc/c/ChangeLog                  |  9 ++++++++
 gcc/c/c-decl.c                   |  2 +-
 gcc/testsuite/ChangeLog          |  8 +++++++
 gcc/testsuite/gcc.dg/inline-42.c | 50 ++++++++++++++++++++++++++++++++++++++++
 gcc/testsuite/gcc.dg/inline-43.c | 50 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 118 insertions(+), 1 deletion(-)

diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 3b9e284..64f0275 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,12 @@
+2020-01-15  Joseph Myers  <joseph@codesourcery.com>
+
+	Backport from mainline:
+	2020-01-15  Joseph Myers  <joseph@codesourcery.com>
+
+	PR c/93072
+	* c-decl.c (pushdecl): Use TREE_PUBLIC, not DECL_EXTERNAL, to
+	determine whether to set DECL_CONTEXT.
+
 2020-01-13  Joseph Myers  <joseph@codesourcery.com>
 
 	Backport from mainline:
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index c632e4a..f77fb17 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -3044,7 +3044,7 @@ pushdecl (tree x)
      unless they have initializers (which generate code).  */
   if (current_function_decl
       && (!VAR_OR_FUNCTION_DECL_P (x)
-	  || DECL_INITIAL (x) || !DECL_EXTERNAL (x)))
+	  || DECL_INITIAL (x) || !TREE_PUBLIC (x)))
     DECL_CONTEXT (x) = current_function_decl;
 
   /* Anonymous decls are just inserted in the scope.  */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 12d7839..4acbb6c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2020-01-15  Joseph Myers  <joseph@codesourcery.com>
+
+	Backport from mainline:
+	2020-01-15  Joseph Myers  <joseph@codesourcery.com>
+
+	PR c/93072
+	* gcc.dg/inline-42.c, gcc.dg/inline-43.c: New tests.
+
 2020-01-14  Martin Jambor  <mjambor@suse.cz>
 
 	Backport from mainline
diff --git a/gcc/testsuite/gcc.dg/inline-42.c b/gcc/testsuite/gcc.dg/inline-42.c
new file mode 100644
index 0000000..f5ccea8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/inline-42.c
@@ -0,0 +1,50 @@
+/* Test inline functions declared in inner scopes.  Bug 93072.  */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+inline_1 (void)
+{
+}
+
+void
+inline_2 (void)
+{
+}
+
+static void
+inline_static_1 (void)
+{
+}
+
+static void
+inline_static_2 (void)
+{
+}
+
+static void
+test (void)
+{
+  inline void inline_1 (void);
+  if (inline_1 == 0) ;
+  extern inline void inline_2 (void);
+  if (inline_2 == 0) ;
+  inline void inline_3 (void);
+  if (inline_3 == 0) ;
+  extern inline void inline_4 (void);
+  if (inline_4 == 0) ;
+  inline void inline_static_1 (void);
+  if (inline_static_1 == 0) ;
+  extern inline void inline_static_2 (void);
+  if (inline_static_2 == 0) ;
+}
+
+void
+inline_3 (void)
+{
+}
+
+void
+inline_4 (void)
+{
+}
diff --git a/gcc/testsuite/gcc.dg/inline-43.c b/gcc/testsuite/gcc.dg/inline-43.c
new file mode 100644
index 0000000..87b2445
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/inline-43.c
@@ -0,0 +1,50 @@
+/* Test inline functions declared in inner scopes.  Bug 93072.  */
+/* { dg-do compile } */
+/* { dg-options "-fgnu89-inline" } */
+
+void
+inline_1 (void)
+{
+}
+
+void
+inline_2 (void)
+{
+}
+
+static void
+inline_static_1 (void)
+{
+}
+
+static void
+inline_static_2 (void)
+{
+}
+
+static void
+test (void)
+{
+  inline void inline_1 (void);
+  if (inline_1 == 0) ;
+  extern inline void inline_2 (void);
+  if (inline_2 == 0) ;
+  inline void inline_3 (void);
+  if (inline_3 == 0) ;
+  extern inline void inline_4 (void);
+  if (inline_4 == 0) ;
+  inline void inline_static_1 (void);
+  if (inline_static_1 == 0) ;
+  extern inline void inline_static_2 (void);
+  if (inline_static_2 == 0) ;
+}
+
+void
+inline_3 (void)
+{
+}
+
+void
+inline_4 (void)
+{
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-02-04 21:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-04 21:12 [gcc(refs/vendors/ibm/heads/gcc-9)] Fix setting of DECL_CONTEXT in pushdecl (PR c/93072) Peter Bergner

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).