public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: C++ PATCH for c++/70353 (core issue 1962)
@ 2016-03-26 11:57 Dominique d'Humières
  2016-03-28 13:11 ` Jason Merrill
  0 siblings, 1 reply; 8+ messages in thread
From: Dominique d'Humières @ 2016-03-26 11:57 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches, Iain Sandoe

Hi Jason,

The following tests for g++.dg/ext/fnname5.C fail on darwin

FAIL: g++.dg/ext/fnname5.C  -std=c++11  scan-assembler .string\\t"foo"
FAIL: g++.dg/ext/fnname5.C  -std=c++11  scan-assembler .string\\t"void A::foo\\\\(int\\\\)"
FAIL: g++.dg/ext/fnname5.C  -std=c++14  scan-assembler .string\\t"foo"
FAIL: g++.dg/ext/fnname5.C  -std=c++14  scan-assembler .string\\t"void A::foo\\\\(int\\\\)"
FAIL: g++.dg/ext/fnname5.C  -std=c++98  scan-assembler .string\\t"foo"
FAIL: g++.dg/ext/fnname5.C  -std=c++98  scan-assembler .string\\t"void A::foo\\\\(int\\\\) »

AFAICT the corresponding patterns are

	.ascii "foo\0"
	.ascii "void A::foo(int)\0 »

This is fixed by the following patch

--- ../_clean/gcc/testsuite/g++.dg/ext/fnname5.C	2016-03-25 22:46:32.000000000 +0100
+++ gcc/testsuite/g++.dg/ext/fnname5.C	2016-03-26 09:04:51.000000000 +0100
@@ -29,5 +29,5 @@ main ()
 /* { dg-final { scan-assembler-not "_ZZN1A3fooEvE12__FUNCTION__" } } */
 /* { dg-final { scan-assembler-not "_ZZN1A3fooEiE12__FUNCTION__" } } */
 /* { dg-final { scan-assembler-not "_ZZN1A3fooEiE19__PRETTY_FUNCTION__" } } */
-/* { dg-final { scan-assembler ".string	\"void A::foo\\(int\\)\"" } } */
-/* { dg-final { scan-assembler ".string	\"foo\"" } } */
+/* { dg-final { scan-assembler ".(string|ascii) \"void A::foo\\(int\\)(.0)?\"" } } */
+/* { dg-final { scan-assembler ".(string|ascii) \"foo(.0)?\"" } } */

TIA

Dominique





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

* Re: C++ PATCH for c++/70353 (core issue 1962)
  2016-03-26 11:57 C++ PATCH for c++/70353 (core issue 1962) Dominique d'Humières
@ 2016-03-28 13:11 ` Jason Merrill
  2016-03-28 13:22   ` Dominique d'Humières
  0 siblings, 1 reply; 8+ messages in thread
From: Jason Merrill @ 2016-03-28 13:11 UTC (permalink / raw)
  To: Dominique d'Humières; +Cc: gcc-patches, Iain Sandoe

OK, thanks.

Jason

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

* Re: C++ PATCH for c++/70353 (core issue 1962)
  2016-03-28 13:11 ` Jason Merrill
@ 2016-03-28 13:22   ` Dominique d'Humières
  2016-03-28 16:31     ` Jason Merrill
  0 siblings, 1 reply; 8+ messages in thread
From: Dominique d'Humières @ 2016-03-28 13:22 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches, Iain Sandoe


> Le 28 mars 2016 à 14:55, Jason Merrill <jason@redhat.com> a écrit :
> 
> OK, thanks.
> 
> Jason

Does it mean that I should commit the patch?

Dominique

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

* Re: C++ PATCH for c++/70353 (core issue 1962)
  2016-03-28 13:22   ` Dominique d'Humières
@ 2016-03-28 16:31     ` Jason Merrill
  2016-03-28 16:41       ` Dominique d'Humières
  0 siblings, 1 reply; 8+ messages in thread
From: Jason Merrill @ 2016-03-28 16:31 UTC (permalink / raw)
  To: Dominique d'Humières; +Cc: gcc-patches, Iain Sandoe

On 03/28/2016 09:02 AM, Dominique d'Humières wrote:
>
>> Le 28 mars 2016 à 14:55, Jason Merrill <jason@redhat.com> a écrit :
>>
>> OK, thanks.
>>
>> Jason
>
> Does it mean that I should commit the patch?

Please.

Jason


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

* Re: C++ PATCH for c++/70353 (core issue 1962)
  2016-03-28 16:31     ` Jason Merrill
@ 2016-03-28 16:41       ` Dominique d'Humières
  0 siblings, 0 replies; 8+ messages in thread
From: Dominique d'Humières @ 2016-03-28 16:41 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches, Iain Sandoe


> Le 28 mars 2016 à 15:11, Jason Merrill <jason@redhat.com> a écrit :
> 
> On 03/28/2016 09:02 AM, Dominique d'Humières wrote:
>> 
>>> Le 28 mars 2016 à 14:55, Jason Merrill <jason@redhat.com> a écrit :
>>> 
>>> OK, thanks.
>>> 
>>> Jason
>> 
>> Does it mean that I should commit the patch?
> 
> Please.

Revision 234504.

Dominique

> Jason
> 

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

* Re: C++ PATCH for c++/70353 (core issue 1962)
  2016-03-25 22:01 Jason Merrill
  2016-03-26 12:03 ` Markus Trippelsdorf
@ 2016-03-28  3:25 ` Segher Boessenkool
  1 sibling, 0 replies; 8+ messages in thread
From: Segher Boessenkool @ 2016-03-28  3:25 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches List, Martin Liška

On Fri, Mar 25, 2016 at 05:29:26PM -0400, Jason Merrill wrote:
> 70353 is a problem with the function-local static declaration of 
> __func__.  Normally constexpr functions can't have local statics, so 
> this is only an issue with __func__.  Meanwhile, core issue 1962 looks 
> like it's going to be resolved by changing __func__ et al to be prvalue 
> constants of type const char * rather than static local array variables, 
> so implementing that proposed resolution also resolves this issue, as 
> well as 62466 which complains about the strings not being merged between 
> translation units.  This patch proceeds from Martin's work last year.
> 
> Tested x86_64-pc-linux-gnu, applying to trunk.

This patch caused PR70422, a bootstrap comparison failure on aarch64,
ia64, and powerpc64.


Segher

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

* Re: C++ PATCH for c++/70353 (core issue 1962)
  2016-03-25 22:01 Jason Merrill
@ 2016-03-26 12:03 ` Markus Trippelsdorf
  2016-03-28  3:25 ` Segher Boessenkool
  1 sibling, 0 replies; 8+ messages in thread
From: Markus Trippelsdorf @ 2016-03-26 12:03 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches List, Martin Liška

On 2016.03.25 at 17:29 -0400, Jason Merrill wrote:
> 70353 is a problem with the function-local static declaration of __func__.
> Normally constexpr functions can't have local statics, so this is only an
> issue with __func__.  Meanwhile, core issue 1962 looks like it's going to be
> resolved by changing __func__ et al to be prvalue constants of type const
> char * rather than static local array variables, so implementing that
> proposed resolution also resolves this issue, as well as 62466 which
> complains about the strings not being merged between translation units.
> This patch proceeds from Martin's work last year.
> 
> Tested x86_64-pc-linux-gnu, applying to trunk.

It breaks building Firefox:

trippels@gcc2-power8 places % cat nsNavHistory.ii
struct A {
  template <int N> A(const char (&)[N]);
};
void fn1() { A(__func__); }


trippels@gcc2-power8 places % c++  -c nsNavHistory.ii
nsNavHistory.ii: In function ‘void fn1()’:
nsNavHistory.ii:4:24: error: no matching function for call to ‘A::A(const char*&)’
 void fn1() { A(__func__); }
                        ^
nsNavHistory.ii:2:20: note: candidate: template<int N> A::A(const char (&)[N])
   template <int N> A(const char (&)[N]);
                    ^
nsNavHistory.ii:2:20: note:   template argument deduction/substitution failed:
nsNavHistory.ii:4:24: note:   mismatched types ‘const char [N]’ and ‘const char*’
 void fn1() { A(__func__); }
                        ^
nsNavHistory.ii:1:8: note: candidate: constexpr A::A(const A&)
 struct A {
        ^
nsNavHistory.ii:1:8: note:   no known conversion for argument 1 from ‘const char*’ to ‘const A&’
nsNavHistory.ii:1:8: note: candidate: constexpr A::A(A&&)
nsNavHistory.ii:1:8: note:   no known conversion for argument 1 from ‘const char*’ to ‘A&&’

So I'm not sure if your patch is really appropriate at this time.
Maybe waiting until next stage 1 would be better?

-- 
Markus

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

* C++ PATCH for c++/70353 (core issue 1962)
@ 2016-03-25 22:01 Jason Merrill
  2016-03-26 12:03 ` Markus Trippelsdorf
  2016-03-28  3:25 ` Segher Boessenkool
  0 siblings, 2 replies; 8+ messages in thread
From: Jason Merrill @ 2016-03-25 22:01 UTC (permalink / raw)
  To: gcc-patches List, Martin Liška

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

70353 is a problem with the function-local static declaration of 
__func__.  Normally constexpr functions can't have local statics, so 
this is only an issue with __func__.  Meanwhile, core issue 1962 looks 
like it's going to be resolved by changing __func__ et al to be prvalue 
constants of type const char * rather than static local array variables, 
so implementing that proposed resolution also resolves this issue, as 
well as 62466 which complains about the strings not being merged between 
translation units.  This patch proceeds from Martin's work last year.

Tested x86_64-pc-linux-gnu, applying to trunk.



[-- Attachment #2: 1962.patch --]
[-- Type: text/x-patch, Size: 7926 bytes --]

commit 4b69c2588521dc0d65e1fd7308ff322ffb35e5b0
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Mar 25 16:19:20 2016 -0400

    	PR c++/64266
    	PR c++/70353
    	Core issue 1962
    	* decl.c (cp_fname_init): Decay the initializer to pointer.
    	(cp_make_fname_decl): Set DECL_DECLARED_CONSTEXPR_P,
    	DECL_VALUE_EXPR, DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P.
    	Don't call cp_finish_decl.
    	* pt.c (tsubst_expr) [DECL_EXPR]: Set DECL_VALUE_EXPR,
    	DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P.  Don't call cp_finish_decl.
    	* constexpr.c (cxx_eval_constant_expression) [VAR_DECL]:
    	Handle DECL_VALUE_EXPR.

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 8ea7111..7776cac 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -3363,6 +3363,10 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
       return (*ctx->values->get (t));
 
     case VAR_DECL:
+      if (DECL_HAS_VALUE_EXPR_P (t))
+	return cxx_eval_constant_expression (ctx, DECL_VALUE_EXPR (t), lval,
+					     non_constant_p, overflow_p);
+      /* Fall through.  */
     case CONST_DECL:
       /* We used to not check lval for CONST_DECL, but darwin.c uses
 	 CONST_DECL for aggregate constants.  */
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index cd5db3f..a88b642 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -4185,13 +4185,15 @@ cp_fname_init (const char* name, tree *type_p)
   type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST);
   type = build_cplus_array_type (type, domain);
 
-  *type_p = type;
+  *type_p = type_decays_to (type);
 
   if (init)
     TREE_TYPE (init) = type;
   else
     init = error_mark_node;
 
+  init = decay_conversion (init, tf_warning_or_error);
+
   return init;
 }
 
@@ -4217,12 +4219,20 @@ cp_make_fname_decl (location_t loc, tree id, int type_dep)
   /* As we're using pushdecl_with_scope, we must set the context.  */
   DECL_CONTEXT (decl) = current_function_decl;
 
-  TREE_STATIC (decl) = 1;
   TREE_READONLY (decl) = 1;
   DECL_ARTIFICIAL (decl) = 1;
+  DECL_DECLARED_CONSTEXPR_P (decl) = 1;
 
   TREE_USED (decl) = 1;
 
+  if (init)
+    {
+      SET_DECL_VALUE_EXPR (decl, init);
+      DECL_HAS_VALUE_EXPR_P (decl) = 1;
+      /* For decl_constant_var_p.  */
+      DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
+    }
+
   if (current_function_decl)
     {
       cp_binding_level *b = current_binding_level;
@@ -4231,13 +4241,12 @@ cp_make_fname_decl (location_t loc, tree id, int type_dep)
       while (b->level_chain->kind != sk_function_parms)
 	b = b->level_chain;
       pushdecl_with_scope (decl, b, /*is_friend=*/false);
-      cp_finish_decl (decl, init, /*init_const_expr_p=*/false, NULL_TREE,
-		      LOOKUP_ONLYCONVERTING);
+      add_decl_expr (decl);
     }
   else
     {
       DECL_THIS_STATIC (decl) = true;
-      pushdecl_top_level_and_finish (decl, init);
+      pushdecl_top_level_and_finish (decl, NULL_TREE);
     }
 
   return decl;
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index a6398c0..e0b7a2a 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -15194,21 +15194,25 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
 		    DECL_CONTEXT (decl) = current_function_decl;
 		    cp_check_omp_declare_reduction (decl);
 		  }
+		else if (VAR_P (decl)
+			 && DECL_PRETTY_FUNCTION_P (decl))
+		  {
+		    /* For __PRETTY_FUNCTION__ we have to adjust the
+		       initializer.  */
+		    const char *const name
+		      = cxx_printable_name (current_function_decl, 2);
+		    init = cp_fname_init (name, &TREE_TYPE (decl));
+		    SET_DECL_VALUE_EXPR (decl, init);
+		    DECL_HAS_VALUE_EXPR_P (decl) = 1;
+		    DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
+		    maybe_push_decl (decl);
+		  }
 		else
 		  {
 		    int const_init = false;
 		    maybe_push_decl (decl);
-		    if (VAR_P (decl)
-			&& DECL_PRETTY_FUNCTION_P (decl))
-		      {
-			/* For __PRETTY_FUNCTION__ we have to adjust the
-			   initializer.  */
-			const char *const name
-			  = cxx_printable_name (current_function_decl, 2);
-			init = cp_fname_init (name, &TREE_TYPE (decl));
-		      }
-		    else
-		      init = tsubst_init (init, decl, args, complain, in_decl);
+
+		    init = tsubst_init (init, decl, args, complain, in_decl);
 
 		    if (VAR_P (decl))
 		      const_init = (DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-__func__2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-__func__2.C
new file mode 100644
index 0000000..226ae19
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-__func__2.C
@@ -0,0 +1,10 @@
+// PR c++/70353
+// { dg-do compile { target c++11 } }
+
+constexpr const char* ce ()
+{
+   return __func__;
+}
+
+#define SA(X) static_assert((X),#X)
+SA(ce()[0] == 'c');
diff --git a/gcc/testsuite/g++.dg/ext/fnname5.C b/gcc/testsuite/g++.dg/ext/fnname5.C
new file mode 100644
index 0000000..a2ead1d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/fnname5.C
@@ -0,0 +1,33 @@
+// PR c++/64266
+/* { dg-do compile } */
+
+extern "C" int printf (const char *, ...);
+
+struct A
+{
+  void foo(int i)
+  {
+    printf ("__FUNCTION__ = %s\n", __FUNCTION__);
+    printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);
+  }
+
+  void foo()
+  {
+     printf ("__FUNCTION__ = %s\n", __FUNCTION__);
+  }
+};
+
+int
+main ()
+{
+  A a;
+  a.foo (0);
+  a.foo ();
+  return 0;
+}
+
+/* { dg-final { scan-assembler-not "_ZZN1A3fooEvE12__FUNCTION__" } } */
+/* { dg-final { scan-assembler-not "_ZZN1A3fooEiE12__FUNCTION__" } } */
+/* { dg-final { scan-assembler-not "_ZZN1A3fooEiE19__PRETTY_FUNCTION__" } } */
+/* { dg-final { scan-assembler ".string	\"void A::foo\\(int\\)\"" } } */
+/* { dg-final { scan-assembler ".string	\"foo\"" } } */
diff --git a/gcc/testsuite/g++.old-deja/g++.ext/pretty4.C b/gcc/testsuite/g++.old-deja/g++.ext/pretty4.C
deleted file mode 100644
index 9017d56..0000000
--- a/gcc/testsuite/g++.old-deja/g++.ext/pretty4.C
+++ /dev/null
@@ -1,85 +0,0 @@
-// { dg-do run  }
-// Copyright (C) 2000 Free Software Foundation, Inc.
-// Contributed by Nathan Sidwell 3 Mar 2000 <nathan@codesourcery.com>
-
-// __PRETTY_FUNCTION__, __FUNCTION__ and __function__ should have the
-// type char const [X], where X is the right value for that particular function
-
-static void const *strings[4];
-static void const *tpls[4];
-static unsigned pos = 0;
-static int fail;
-static void const *ptr = 0;
-
-void unover (char const (*)[5]) {}
-void foo (char const (*)[5]) {}
-void foo (void *) {fail = 1;}
-void foo (void const *) {fail = 1;}
-void baz (char const (&)[5]) {}
-
-template<unsigned I> void PV (char const (&objRef)[I])
-{
-  strings[pos] = objRef;
-  tpls[pos] = __PRETTY_FUNCTION__;
-  pos++;
-}
-
-void fn ()
-{
-  PV (__FUNCTION__);
-  PV (__func__);
-  PV (__PRETTY_FUNCTION__);
-  PV ("wibble");
-}
-
-void baz ()
-{
-  ptr = __FUNCTION__;
-  // there should be no string const merging
-  if (ptr == "baz")
-    fail = 1;
-  // but all uses should be the same.
-  if (ptr != __FUNCTION__)
-    fail = 1;
-}
-int baz (int)
-{
-  return ptr == __FUNCTION__;
-}
-
-int main ()
-{
-  // make sure we actually emit the VAR_DECL when needed, and things have the
-  // expected type.
-  foo (&__FUNCTION__);
-  baz (__FUNCTION__);
-  unover (&__FUNCTION__);
-  if (fail)
-    return 1;
-  
-  // __FUNCTION__ should be unique across functions with the same base name
-  // (it's a local static, _not_ a string).
-  baz ();
-  if (fail)
-    return 1;
-  if (baz (1))
-    return 1;
-  fn ();
-  
-  // Check the names of fn. They should all be distinct strings (though two
-  // will have the same value).
-  if (strings[0] == strings[1])
-    return 1;
-  if (strings[0] == strings[2])
-    return 1;
-  if (strings[1] == strings[2])
-    return 1;
-
-  // check the names of the template functions so invoked
-  if (tpls[0] != tpls[1])
-    return 1;
-  if (tpls[0] == tpls[2])
-    return 1;
-  
-  return 0;
-}

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

end of thread, other threads:[~2016-03-28 13:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-26 11:57 C++ PATCH for c++/70353 (core issue 1962) Dominique d'Humières
2016-03-28 13:11 ` Jason Merrill
2016-03-28 13:22   ` Dominique d'Humières
2016-03-28 16:31     ` Jason Merrill
2016-03-28 16:41       ` Dominique d'Humières
  -- strict thread matches above, loose matches on Subject: below --
2016-03-25 22:01 Jason Merrill
2016-03-26 12:03 ` Markus Trippelsdorf
2016-03-28  3:25 ` Segher Boessenkool

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