public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ patch] PR 65858
@ 2015-04-30 17:21 Prathamesh Kulkarni
  2015-04-30 18:01 ` Paolo Carlini
  0 siblings, 1 reply; 6+ messages in thread
From: Prathamesh Kulkarni @ 2015-04-30 17:21 UTC (permalink / raw)
  To: gcc Patches, paolo.carlini

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

Hi,
The attached patch fixes ICE in PR65858.

For the test-case:
int x { 0.5 };
int main() { return 0; }

Compiling with: g++ -flto -Wno-narrowing -std=gnu++11
results in following ICE:
lto1: internal compiler error: in get_constructor, at varpool.c:331
0xd22f73 varpool_node::get_constructor()
../../src/gcc/varpool.c:331
0xd23e28 varpool_node::assemble_decl()
../../src/gcc/varpool.c:602
0x6b8793 output_in_order
../../src/gcc/cgraphunit.c:2137
0x6b8c83 symbol_table::compile()
../../src/gcc/cgraphunit.c:2378
0x62b205 lto_main()
../../src/gcc/lto/lto.c:3496

The ICE happens because error_mark_node gets streamed in the
object file and hits the assert:
gcc_assert (DECL_INITIAL (decl) != error_mark_node);

It appears that r222249, which fixed PR65801 introduced this issue.

For the above test-case convert_like_real() calls check_narrowing():
 if (convs->check_narrowing
      && !check_narrowing (totype, expr, complain))
    return error_mark_node;

Here convert_like_real() returns error_mark_node, because
check_narrowing() returns false.

Conside this part of check_narrowing():

if (!ok)
  {
     //...
     else if (complain & tf_error)
       {
         global_dc->pedantic_errors = 1;
         pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing,
                        "narrowing conversion of %qE from %qT to %qT
inside { }",
                         init, ftype, type);
         global_dc->pedantic_errors = flag_pedantic_errors;
       }
   }
return cxx_dialect == cxx98 || ok;

pedwarn() doesn't print warning here and returns 0.
That's because the following condition becomes true in
diagnostic.c:diagnostic_report_diagnostic():

/* This tests if the user provided the appropriate -Wfoo or
   -Wno-foo option.  */
if (! context->option_enabled (diagnostic->option_index,
                               context->option_state))
  return false;

So diagnostic_report_diagnostic() returns false to pedwarn()
which then returns 0 to check_narrowing() and warning is not printed.

return cxx_dialect == cxx98 || ok;
Since cxx_dialect is not cxx98 and ok is false, it returns false.

The attached patch fixes the ICE, by setting "ok = true" if
warn_narrowing is enabled thereby returning "true" to
convert_like_real().
Booststrapped and tested on x86_64-unknown-linux-gnu with no regressions.
OK for trunk ?

Thank you,
Prathamesh

[-- Attachment #2: ChangeLog.txt --]
[-- Type: text/plain, Size: 163 bytes --]

/cp
2015-04-20  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
	
	PR c++/65858
	* typeck2.c (check_narrowing): Do not pedwarn if -Wno-narrowing is enabled.

[-- Attachment #3: 65858.patch --]
[-- Type: text/x-patch, Size: 892 bytes --]

Index: gcc/cp/typeck2.c
===================================================================
--- gcc/cp/typeck2.c	(revision 222573)
+++ gcc/cp/typeck2.c	(working copy)
@@ -958,11 +958,17 @@
 	}
       else if (complain & tf_error)
 	{
-	  global_dc->pedantic_errors = 1;
-	  pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing,
-		   "narrowing conversion of %qE from %qT to %qT inside { }",
-		   init, ftype, type);
-	  global_dc->pedantic_errors = flag_pedantic_errors;
+	  /* silence warning if -Wno-narrowing -is specified */
+	  if (!warn_narrowing)
+	    ok = true;
+	  else
+	    { 
+	      global_dc->pedantic_errors = 1;
+	      pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing,
+		      "narrowing conversion of %qE from %qT to %qT inside { }",
+		       init, ftype, type);
+	      global_dc->pedantic_errors = flag_pedantic_errors;
+	    }
 	}
     }
 

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

* Re: [C++ patch] PR 65858
  2015-04-30 17:21 [C++ patch] PR 65858 Prathamesh Kulkarni
@ 2015-04-30 18:01 ` Paolo Carlini
  2015-04-30 19:08   ` Paolo Carlini
  0 siblings, 1 reply; 6+ messages in thread
From: Paolo Carlini @ 2015-04-30 18:01 UTC (permalink / raw)
  To: Prathamesh Kulkarni, gcc Patches, Jason Merrill

Hi,

On 04/30/2015 06:36 PM, Prathamesh Kulkarni wrote:
> Hi,
> The attached patch fixes ICE in PR65858.
>
> For the test-case:
> int x { 0.5 };
Eventually, we have to add to the testsuite the testcase too (the code 
is simpler but equivalent to what we added for 65801, -flto makes all 
the difference). And a fix goes in gcc-5-branch too.

Anyway, your proposal makes sense to me (this couple of issues is really 
weird, essentially we end up using a pedwarn instead of a plain error 
*only* to print [-Wnarrowing] and tell people that the diagnostic can be 
suppressed!?!) but we want to ear Jason.

Paolo.

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

* Re: [C++ patch] PR 65858
  2015-04-30 18:01 ` Paolo Carlini
@ 2015-04-30 19:08   ` Paolo Carlini
  2015-04-30 20:44     ` Paolo Carlini
  0 siblings, 1 reply; 6+ messages in thread
From: Paolo Carlini @ 2015-04-30 19:08 UTC (permalink / raw)
  To: Prathamesh Kulkarni, gcc Patches, Jason Merrill

.. also, your patch doesn't seem to fix the case of -w instead of 
-Wno-narrowing. I think we want to check the return value of the pedwarn 
instead. I'm testing something.

Paolo.

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

* Re: [C++ patch] PR 65858
  2015-04-30 19:08   ` Paolo Carlini
@ 2015-04-30 20:44     ` Paolo Carlini
  2015-04-30 21:15       ` Prathamesh Kulkarni
  2015-05-01 17:25       ` Jason Merrill
  0 siblings, 2 replies; 6+ messages in thread
From: Paolo Carlini @ 2015-04-30 20:44 UTC (permalink / raw)
  To: Prathamesh Kulkarni, gcc Patches, Jason Merrill

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

Hi again,

On 04/30/2015 08:45 PM, Paolo Carlini wrote:
> .. also, your patch doesn't seem to fix the case of -w instead of 
> -Wno-narrowing. I think we want to check the return value of the 
> pedwarn instead. I'm testing something.
I'm finishing testing the below: with hindsight, checking the return 
value of the pedwarn makes a lot of sense to me!

Paolo.

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

[-- Attachment #2: patch_65858 --]
[-- Type: text/plain, Size: 1103 bytes --]

Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c	(revision 222628)
+++ cp/typeck2.c	(working copy)
@@ -959,9 +959,10 @@ check_narrowing (tree type, tree init, tsubst_flag
       else if (complain & tf_error)
 	{
 	  global_dc->pedantic_errors = 1;
-	  pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing,
-		   "narrowing conversion of %qE from %qT to %qT inside { }",
-		   init, ftype, type);
+	  if (!pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing,
+			"narrowing conversion of %qE from %qT to %qT "
+			"inside { }", init, ftype, type))
+	    ok = true;
 	  global_dc->pedantic_errors = flag_pedantic_errors;
 	}
     }
Index: testsuite/g++.dg/cpp0x/Wnarrowing4.C
===================================================================
--- testsuite/g++.dg/cpp0x/Wnarrowing4.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/Wnarrowing4.C	(working copy)
@@ -0,0 +1,6 @@
+// PR c++/65858
+// { dg-do compile { target c++11 } }
+// { dg-require-effective-target lto }
+// { dg-options "-flto -Wno-narrowing" }
+
+int x { 0.5 };

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

* Re: [C++ patch] PR 65858
  2015-04-30 20:44     ` Paolo Carlini
@ 2015-04-30 21:15       ` Prathamesh Kulkarni
  2015-05-01 17:25       ` Jason Merrill
  1 sibling, 0 replies; 6+ messages in thread
From: Prathamesh Kulkarni @ 2015-04-30 21:15 UTC (permalink / raw)
  To: Paolo Carlini; +Cc: gcc Patches, Jason Merrill

On 1 May 2015 at 01:12, Paolo Carlini <paolo.carlini@oracle.com> wrote:
> Hi again,
>
> On 04/30/2015 08:45 PM, Paolo Carlini wrote:
>>
>> .. also, your patch doesn't seem to fix the case of -w instead of
That could be fixed as follows:
if (!warn_narrowing || inhibit_warnings)
  ok = true;
else
  // pedwarn
>> -Wno-narrowing. I think we want to check the return value of the pedwarn
>> instead. I'm testing something.
>
> I'm finishing testing the below: with hindsight, checking the return value
> of the pedwarn makes a lot of sense to me!
Indeed, checking return value of pedwarn is better compared to testing
on warning flags.
Thanks for pointing out -;)

Regards,
Prathamesh
>
> Paolo.
>
> ///////////////////////

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

* Re: [C++ patch] PR 65858
  2015-04-30 20:44     ` Paolo Carlini
  2015-04-30 21:15       ` Prathamesh Kulkarni
@ 2015-05-01 17:25       ` Jason Merrill
  1 sibling, 0 replies; 6+ messages in thread
From: Jason Merrill @ 2015-05-01 17:25 UTC (permalink / raw)
  To: Paolo Carlini, Prathamesh Kulkarni, gcc Patches

OK (= true).

Jason

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

end of thread, other threads:[~2015-05-01 17:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-30 17:21 [C++ patch] PR 65858 Prathamesh Kulkarni
2015-04-30 18:01 ` Paolo Carlini
2015-04-30 19:08   ` Paolo Carlini
2015-04-30 20:44     ` Paolo Carlini
2015-04-30 21:15       ` Prathamesh Kulkarni
2015-05-01 17:25       ` 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).