public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] PR 51400
@ 2014-06-28 21:46 Paolo Carlini
  2014-06-30 15:14 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Paolo Carlini @ 2014-06-28 21:46 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 851 bytes --]

Hi,

this issue manifests itself as an ICE on the gcc_assert toward the end 
of start_decl:

   if (VAR_P (decl)
       && DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl) && 
!was_public
       && !DECL_THIS_STATIC (decl) && !DECL_ARTIFICIAL (decl))
     {
       /* This is a const variable with implicit 'static'.  Set
      DECL_THIS_STATIC so we can tell it from variables that are
      !TREE_PUBLIC because of the anonymous namespace.  */
       gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (decl)) || errorcount);
       DECL_THIS_STATIC (decl) = 1;
     }

and the reason seems clear to me: both handle_noreturn_attribute and 
handle_const_attribute call build_pointer_type and discard the 
TYPE_QUALS on the original POINTER_TYPE. That seems obviously incorrect. 
The below fixes the ICE and passes testing.

Thanks!
Paolo.

/////////////////

[-- Attachment #2: CL_51400 --]
[-- Type: text/plain, Size: 308 bytes --]

/c-family
2014-06-28  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/51400
	* c-common.c (handle_noreturn_attribute, handle_const_attribute):
	Do not discard TYPE_QUALS of type.

/testsuite
2014-06-28  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/51400
	* g++.dg/cpp0x/constexpr-attribute3.C: New.

[-- Attachment #3: patch_51400 --]
[-- Type: text/plain, Size: 1743 bytes --]

Index: c-family/c-common.c
===================================================================
--- c-family/c-common.c	(revision 212104)
+++ c-family/c-common.c	(working copy)
@@ -6575,9 +6575,11 @@ handle_noreturn_attribute (tree *node, tree name,
   else if (TREE_CODE (type) == POINTER_TYPE
 	   && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
     TREE_TYPE (*node)
-      = build_pointer_type
-	(build_type_variant (TREE_TYPE (type),
-			     TYPE_READONLY (TREE_TYPE (type)), 1));
+      = (build_qualified_type
+	 (build_pointer_type
+	  (build_type_variant (TREE_TYPE (type),
+			       TYPE_READONLY (TREE_TYPE (type)), 1)),
+	  TYPE_QUALS (type)));
   else
     {
       warning (OPT_Wattributes, "%qE attribute ignored", name);
@@ -6988,9 +6990,11 @@ handle_const_attribute (tree *node, tree name, tre
   else if (TREE_CODE (type) == POINTER_TYPE
 	   && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
     TREE_TYPE (*node)
-      = build_pointer_type
-	(build_type_variant (TREE_TYPE (type), 1,
-			     TREE_THIS_VOLATILE (TREE_TYPE (type))));
+      = (build_qualified_type
+	 (build_pointer_type
+	  (build_type_variant (TREE_TYPE (type), 1,
+			       TREE_THIS_VOLATILE (TREE_TYPE (type)))),
+	  TYPE_QUALS (type)));
   else
     {
       warning (OPT_Wattributes, "%qE attribute ignored", name);
Index: testsuite/g++.dg/cpp0x/constexpr-attribute3.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-attribute3.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-attribute3.C	(working copy)
@@ -0,0 +1,5 @@
+// PR c++/51400
+// { dg-do compile { target c++11 } }
+
+constexpr int (*f)() __attribute__((noreturn)) = 0;
+constexpr int (*g)() __attribute__((const)) = 0;

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

* Re: [C++ Patch] PR 51400
  2014-06-28 21:46 [C++ Patch] PR 51400 Paolo Carlini
@ 2014-06-30 15:14 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2014-06-30 15:14 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches

OK.

Jason

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

end of thread, other threads:[~2014-06-30 15:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-28 21:46 [C++ Patch] PR 51400 Paolo Carlini
2014-06-30 15:14 ` Jason Merrill

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