[Bug c++/94326] g++: error: pack.ii: ‘-fcompare-debug’ failure (length)

2020-03-27 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94326

Jakub Jelinek  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|NEW |RESOLVED

--- Comment #6 from Jakub Jelinek  ---
Fixed for 10+.

[Bug c++/94326] g++: error: pack.ii: ‘-fcompare-debug’ failure (length)

2020-03-27 Thread cvs-commit at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94326

--- Comment #5 from CVS Commits  ---
The master branch has been updated by Jakub Jelinek :

https://gcc.gnu.org/g:2eea00c518d5a72d0bdbc810ae675e7ad5fee414

commit r10-7411-g2eea00c518d5a72d0bdbc810ae675e7ad5fee414
Author: Jakub Jelinek 
Date:   Fri Mar 27 10:04:31 2020 +0100

c++: Avoid calls in non-evaluated contexts affect whether function can or
can't throw [PR94326]

The following testcase FAILs -fcompare-debug, because if we emit a
-Wreturn-local-addr warning, we tsubst decltype in order to print the
warning and as that function could throw, set_flags_from_callee during that
sets cp_function_chain->can_throw and later on we don't set TREE_NOTHROW
on foo.  While with -w or -Wno-return-local-addr, tsubst isn't called
during
the warning_at, cp_function_chain->can_throw is kept clear and TREE_NOTHROW
is set on foo.
It isn't just a matter of the warning though, in
int foo ();
int bar () { return sizeof (foo ()); }
int baz () { return sizeof (int); }
I don't really see why we should mark only baz as TREE_NOTHROW and not bar
too, when neither can really throw.

2020-03-27  Jakub Jelinek  

PR c++/94326
* call.c (set_flags_from_callee): Don't update
cp_function_chain->can_throw or current_function_returns_abnormally
if cp_unevaluated_operand.

* g++.dg/other/pr94326.C: New test.

[Bug c++/94326] g++: error: pack.ii: ‘-fcompare-debug’ failure (length)

2020-03-26 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94326

--- Comment #4 from Jakub Jelinek  ---
--- gcc/cp/call.c.jj2020-03-25 08:05:07.153731580 +0100
+++ gcc/cp/call.c   2020-03-26 15:03:42.432909693 +0100
@@ -333,11 +333,14 @@ set_flags_from_callee (tree call)
   && internal_fn_flags (CALL_EXPR_IFN (call)) & ECF_NOTHROW)
 nothrow = true;

-  if (!nothrow && at_function_scope_p () && cfun && cp_function_chain)
-cp_function_chain->can_throw = 1;
+  if (cfun && cp_function_chain && !cp_unevaluated_operand)
+{
+  if (!nothrow && at_function_scope_p ())
+   cp_function_chain->can_throw = 1;

-  if (decl && TREE_THIS_VOLATILE (decl) && cfun && cp_function_chain)
-current_function_returns_abnormally = 1;
+  if (decl && TREE_THIS_VOLATILE (decl))
+   current_function_returns_abnormally = 1;
+}

   TREE_NOTHROW (call) = nothrow;
 }

seems to work, but not sure if that is what we want.

[Bug c++/94326] g++: error: pack.ii: ‘-fcompare-debug’ failure (length)

2020-03-26 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94326

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jason at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek  ---
And the reason for the differences is that with -Wno-return-local-addr (or -w
etc.) m_fn1 is marked TREE_NOTHROW (fndecl) in finish_function, while with
-Wreturn-local-addr (and without -w) it is not.
The difference is in cp_function_chain->can_throw , which set not set in the no
warning case, and is set in:
#0  set_flags_from_callee (call=) at
../../gcc/cp/call.c:324
#1  0x00966d3b in build_call_a (function=,
n=2, argarray=0x7fffb1e0) at ../../gcc/cp/call.c:365
#2  0x0098936f in build_cxx_call (fn=,
nargs=2, argarray=0x7fffb1e0, complain=128, orig_fndecl=)
at ../../gcc/cp/call.c:9578
#3  0x009877cc in build_over_call (cand=0x3763930, flags=3, complain=0)
at ../../gcc/cp/call.c:9082
#4  0x0098c868 in build_new_method_call_1 (instance=, fns=, 
args=0x7fffb860 = {...}, conversion_path=,
flags=1, fn_p=0x0, complain=128) at ../../gcc/cp/call.c:10335
#5  0x0098cd56 in build_new_method_call (instance=, fns=, 
args=0x7fffb860 = {...}, conversion_path=, flags=1, fn_p=0x0,
complain=128) at ../../gcc/cp/call.c:10410
#6  0x00c41d6f in tsubst_copy_and_build (t=,
args=, complain=128, in_decl=, 
function_p=false, integral_constant_expression_p=false) at
../../gcc/cp/pt.c:19812
#7  0x00c2ae69 in tsubst (t=,
args=, complain=0, in_decl=)
at ../../gcc/cp/pt.c:15746
#8  0x00ac831c in dump_template_bindings (pp=0x34be940
, parms=, args=, 
typenames=0x7fffea950a28 = {...}) at ../../gcc/cp/error.c:414
#9  0x00ace590 in dump_substitution (pp=0x34be940
, t=, 
template_parms=, template_args=, flags=132) at ../../gcc/cp/error.c:1560
#10 0x00ad0138 in dump_function_decl (pp=0x34be940
, t=, flags=132)
at ../../gcc/cp/error.c:1718
#11 0x00acd485 in dump_decl (pp=0x34be940 ,
t=, flags=132)
at ../../gcc/cp/error.c:1290
#12 0x00ad6ba8 in decl_to_string (decl=, verbose=1) at ../../gcc/cp/error.c:3092
#13 0x00ada974 in cp_printer (pp=0x370bbb0, text=0x7fffc550,
spec=0x3721f62 "D", precision=0, wide=false, set_locus=false, 
verbose=true, quoted=0x7fffc19f, buffer_ptr=0x3721d70) at
../../gcc/cp/error.c:4260
#14 0x026f5fe2 in pp_format (pp=0x370bbb0, text=0x7fffc550) at
../../gcc/pretty-print.c:1458
#15 0x026f63b2 in pp_format_verbatim (pp=0x370bbb0,
text=0x7fffc550) at ../../gcc/pretty-print.c:1519
#16 0x026f6c1d in pp_verbatim (pp=0x370bbb0, msg=0x2813680 "required
from %q#D\n") at ../../gcc/pretty-print.c:1773
#17 0x00ad8b73 in print_instantiation_partial_context_line
(context=0x36bc320 , t=0x7fffea956440, 
loc=2147483653, recursive_p=false) at ../../gcc/cp/error.c:3537
#18 0x00ad8e6d in print_instantiation_partial_context
(context=0x36bc320 , t0=0x7fffea936860,
loc=2147483653)
at ../../gcc/cp/error.c:3625
#19 0x00ad89fb in print_instantiation_full_context (context=0x36bc320
) at ../../gcc/cp/error.c:3505
#20 0x00ad8eec in maybe_print_instantiation_context (context=0x36bc320
) at ../../gcc/cp/error.c:3642
#21 0x00ad74c6 in cp_diagnostic_starter (context=0x36bc320
, diagnostic=0x7fffc880)
at ../../gcc/cp/error.c:3341
#22 0x026cfced in diagnostic_report_diagnostic (context=0x36bc320
, diagnostic=0x7fffc880)
at ../../gcc/diagnostic.c:1160
#23 0x026d02f2 in diagnostic_impl (richloc=0x7fffc8f0,
metadata=0x0, opt=635, gmsgid=0x284c5f8 "returning reference to temporary", 
ap=0x7fffc9a0, kind=DK_WARNING) at ../../gcc/diagnostic.c:1309
#24 0x026d0b70 in warning_at (location=247168, opt=635,
gmsgid=0x284c5f8 "returning reference to temporary")

i.e. when the warning is being emitted.
The call in question is
A<>::m_fn2 (&((struct B *) this)->_M_t, TARGET_EXPR 

So, shall set_flags_from_callee be setting cp_function_chain->can_throw (or
other flags) even in cp_unevaluated_operand ?  Or shouldn't tsubst or whatever
else sets cp_unevaluated_operand?  Something else?

[Bug c++/94326] g++: error: pack.ii: ‘-fcompare-debug’ failure (length)

2020-03-26 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94326

--- Comment #2 from Jakub Jelinek  ---
$ rm -f pr94326.C.*; ./cc1plus -quiet -std=c++11 pr94326.C -Wreturn-local-addr
-da; grep REG_EH_REGION pr94326.C.*
pr94326.C: In instantiation of ‘const int& A< 
>::m_fn1() [with  = int]’:
pr94326.C:5:45:   required from ‘void A<  >::m_fn2(_Kt)
[with _Kt = C;  = int]’
pr94326.C:12:15:   required from ‘decltype
(((B*)this)->B::_M_t.A<>::m_fn2<_Kt>(p1)) B::m_fn3(_Kt) [with _Kt = C; decltype
(((B*)this)->B::_M_t.A<>::m_fn2<_Kt>(p1)) = void]’
pr94326.C:18:14:   required from here
pr94326.C:2:31: warning: returning reference to temporary [-Wreturn-local-addr]
2 |   const int _fn1() { return 0; }
  |   ^
$ rm -f pr94326.C.*; ./cc1plus -quiet -std=c++11 pr94326.C
-Wno-return-local-addr -da; grep REG_EH_REGION pr94326.C.*
pr94326.C.236r.expand: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.236r.expand: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.237r.vregs: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.238r.into_cfglayout: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.239r.jump: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.239r.jump: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.251r.reginfo: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.274r.outof_cfglayout: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.275r.split1: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.277r.dfinit: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.278r.mode_sw: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.279r.asmcons: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.284r.ira:(expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.285r.reload: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.292r.pro_and_epilogue: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.295r.jump2: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.306r.split4: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.307r.stack: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.308r.alignments: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.310r.mach: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.311r.barriers: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.316r.shorten: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.317r.nothrow: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.318r.dwarf2: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.319r.final: (expr_list:REG_EH_REGION (const_int 0 [0])
pr94326.C.320r.dfinish: (expr_list:REG_EH_REGION (const_int 0 [0])

[Bug c++/94326] g++: error: pack.ii: ‘-fcompare-debug’ failure (length)

2020-03-26 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94326

Jakub Jelinek  changed:

   What|Removed |Added

  Component|debug   |c++

--- Comment #1 from Jakub Jelinek  ---
Indeed, I think this started failing with
r0-114389-g4b6aaa996e0d8f5abac818315b6f77cb3596db98
before which it has been rejected with sorry message.
The bug isn't debug related in this case, but -w is affecting generated code.