[Bug c++/90940] [9/10 Regression] Miscompilation of ternary operator with throw expression in return statement

2019-06-19 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90940

Jonathan Wakely  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |DUPLICATE

--- Comment #5 from Jonathan Wakely  ---
Agreed, thanks.

*** This bug has been marked as a duplicate of bug 90393 ***

[Bug c++/90940] [9/10 Regression] Miscompilation of ternary operator with throw expression in return statement

2019-06-19 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90940

Marek Polacek  changed:

   What|Removed |Added

 CC||mpolacek at gcc dot gnu.org

--- Comment #4 from Marek Polacek  ---
I think it's a dup of 90393.

[Bug c++/90940] [9/10 Regression] Miscompilation of ternary operator with throw expression in return statement

2019-06-19 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90940

--- Comment #3 from Jonathan Wakely  ---
Oh, and for completeness, the ICE case reduced:

extern "C" void* malloc(decltype(sizeof(0)));
extern "C" void free(void*);

struct string {
  string(int) : s(malloc(1)) { }
  ~string() { free(s); }
  string(const string& str) : s(str.s ? malloc(1) : nullptr) { }
  void* s;
  bool empty() const { return s == nullptr; }
};

string foo()
{
  const string s(42);
  return s.empty() ? throw "empty" : s;
}

90940.cc: In function 'string foo()':
90940.cc:15:38: internal compiler error: in ocp_convert, at cp/cvt.c:765
   15 |   return s.empty() ? throw "empty" : s;
  |  ^
0x5ce07b ocp_convert(tree_node*, tree_node*, int, int, int)
/home/jwakely/src/gcc/gcc/gcc/cp/cvt.c:765
0xa195c9 check_return_expr(tree_node*, bool*)
/home/jwakely/src/gcc/gcc/gcc/cp/typeck.c:9796
0x9d0a4e finish_return_stmt(tree_node*)
/home/jwakely/src/gcc/gcc/gcc/cp/semantics.c:894
0x9486db cp_parser_jump_statement
/home/jwakely/src/gcc/gcc/gcc/cp/parser.c:12903
0x9486db cp_parser_statement
/home/jwakely/src/gcc/gcc/gcc/cp/parser.c:11180
0x949500 cp_parser_statement_seq_opt
/home/jwakely/src/gcc/gcc/gcc/cp/parser.c:11646
0x9495d7 cp_parser_compound_statement
/home/jwakely/src/gcc/gcc/gcc/cp/parser.c:11600
0x962500 cp_parser_function_body
/home/jwakely/src/gcc/gcc/gcc/cp/parser.c:22624
0x962500 cp_parser_ctor_initializer_opt_and_function_body
/home/jwakely/src/gcc/gcc/gcc/cp/parser.c:22675
0x962d86 cp_parser_function_definition_after_declarator
/home/jwakely/src/gcc/gcc/gcc/cp/parser.c:27776
0x963b1e cp_parser_function_definition_from_specifiers_and_declarator
/home/jwakely/src/gcc/gcc/gcc/cp/parser.c:27692
0x963b1e cp_parser_init_declarator
/home/jwakely/src/gcc/gcc/gcc/cp/parser.c:20261
0x945c6f cp_parser_simple_declaration
/home/jwakely/src/gcc/gcc/gcc/cp/parser.c:13525
0x96a402 cp_parser_declaration
/home/jwakely/src/gcc/gcc/gcc/cp/parser.c:13222
0x96abaf cp_parser_translation_unit
/home/jwakely/src/gcc/gcc/gcc/cp/parser.c:4690
0x96abaf c_parse_file()
/home/jwakely/src/gcc/gcc/gcc/cp/parser.c:41243
0xa78820 c_common_parse_file()
/home/jwakely/src/gcc/gcc/gcc/c-family/c-opts.c:1156
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See  for instructions.

[Bug c++/90940] [9/10 Regression] Miscompilation of ternary operator with throw expression in return statement

2019-06-19 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90940

--- Comment #2 from Jonathan Wakely  ---
Reduced example showing double free, which started with the same revision as
the ICE:

extern "C" void* malloc(decltype(sizeof(0)));
extern "C" void free(void*);

struct string {
  string(int) : s(malloc(1)) { }
  ~string() { free(s); }
  string(const string& str) : s(str.s ? malloc(1) : nullptr) { }
  void* s;
  bool empty() const { return s == nullptr; }
};

string foo()
{
  string s(42);
  return s.empty() ? throw "empty" : s;
}

int main()
{
  foo();
}

[Bug c++/90940] [9/10 Regression] Miscompilation of ternary operator with throw expression in return statement

2019-06-19 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90940

Jonathan Wakely  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
  Known to work||8.3.0
   Keywords||ice-on-valid-code,
   ||wrong-code
   Last reconfirmed||2019-06-19
 CC||jason at gcc dot gnu.org
 Ever confirmed|0   |1
Summary|Miscompilation of ternary   |[9/10 Regression]
   |operator with throw |Miscompilation of ternary
   |expression in return|operator with throw
   |statement   |expression in return
   ||statement
   Target Milestone|--- |9.2
  Known to fail||10.0, 9.1.0

--- Comment #1 from Jonathan Wakely  ---
Confirmed, thanks for the minimal example.

The ICE started with r260272:

PR c++/64372 - CWG 1560, gratuitous lvalue-rvalue conversion in ?:

* call.c (build_conditional_expr_1): Don't force_rvalue when one
arm
is a throw-expression.