public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* recommended optimization level  when programming C++ contracts
@ 2023-02-23 13:59 Saifi Khan
  2023-02-23 16:28 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Saifi Khan @ 2023-02-23 13:59 UTC (permalink / raw)
  To: gcc-help

Hi:

was working through p2680r1 example with the code as follows.

---
auto f (int i) -> int {
      return i + 100;
}

int g (int j) [[pre: f (j) < j ]] {
      int r { j - f (j)};
      return 2 * r;
}

auto test () -> void {
      g (5);
}

---

Environment
 - Linux  6.1.0-3-amd64 x86_64 GNU/Linux
 - Debian GLIBC 2.36-8) 2.36
 - gcc version 13.0.1 20230215 (experimental) (GCC)

What is not clear to me is the following.

This works.

::  g++ -std=c++23 -fcontracts contract_01.cc 
::  ./a.out 
contract violation in function g at contract_01.cc:8: f (j) < j
terminate called without an active exception
Aborted
::  

But this doesn't work !

::  g++ -std=c++23 -O3 -g2 -fcontracts contract_01.cc 
during RTL pass: final
contract_01.cc: In function ‘int g(int)’:
contract_01.cc:13:1: internal compiler error: in gen_inlined_subroutine_die, at dwarf2out.cc:25002
   13 | }
      | ^
0x7d40a5 gen_inlined_subroutine_die
        /opt/gcc/src/gcc/dwarf2out.cc:25002
0x7d40a5 gen_block_die
        /opt/gcc/src/gcc/dwarf2out.cc:26487
0xe3b3ca decls_for_scope
        /opt/gcc/src/gcc/dwarf2out.cc:26612
0xe18c93 gen_subprogram_die
        /opt/gcc/src/gcc/dwarf2out.cc:24086
0xe1d82f gen_decl_die
        /opt/gcc/src/gcc/dwarf2out.cc:27020
0xe1e60a dwarf2out_decl
        /opt/gcc/src/gcc/dwarf2out.cc:27598
0xe1ea62 dwarf2out_function_decl
        /opt/gcc/src/gcc/dwarf2out.cc:27613
0xea23e7 rest_of_handle_final
        /opt/gcc/src/gcc/final.cc:4274
0xea23e7 execute
        /opt/gcc/src/gcc/final.cc:4318
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.

Is there any impact of the choice of '-O0', '-O1', '-O2' or '-O3' ?
If yes, what is the recommended optimization level ?

warm regards
Saifi

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

* Re: recommended optimization level when programming C++ contracts
  2023-02-23 13:59 recommended optimization level when programming C++ contracts Saifi Khan
@ 2023-02-23 16:28 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2023-02-23 16:28 UTC (permalink / raw)
  To: Saifi Khan; +Cc: gcc-help

On Thu, 23 Feb 2023 at 14:00, Saifi Khan <saifi.khan@nishan.io> wrote:
>
> Hi:
>
> was working through p2680r1 example with the code as follows.
>
> ---
> auto f (int i) -> int {
>       return i + 100;
> }
>
> int g (int j) [[pre: f (j) < j ]] {
>       int r { j - f (j)};
>       return 2 * r;
> }
>
> auto test () -> void {
>       g (5);
> }
>
> ---
>
> Environment
>  - Linux  6.1.0-3-amd64 x86_64 GNU/Linux
>  - Debian GLIBC 2.36-8) 2.36
>  - gcc version 13.0.1 20230215 (experimental) (GCC)
>
> What is not clear to me is the following.
>
> This works.
>
> ::  g++ -std=c++23 -fcontracts contract_01.cc
> ::  ./a.out
> contract violation in function g at contract_01.cc:8: f (j) < j
> terminate called without an active exception
> Aborted
> ::
>
> But this doesn't work !
>
> ::  g++ -std=c++23 -O3 -g2 -fcontracts contract_01.cc
> during RTL pass: final
> contract_01.cc: In function ‘int g(int)’:
> contract_01.cc:13:1: internal compiler error: in gen_inlined_subroutine_die, at dwarf2out.cc:25002

But this is just a compiler bug, why are you trying to infer anything
about recommended optimization levels from a bug?

All this means is GCC has a bug, it doesn't mean you should or
shouldn't use optimization with contracts. Please report the bug.

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

end of thread, other threads:[~2023-02-23 16:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-23 13:59 recommended optimization level when programming C++ contracts Saifi Khan
2023-02-23 16:28 ` Jonathan Wakely

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