Thread overview
[Issue 5517] SEGV: assert(false) in release mode
Jun 25, 2015
Shachar Shemesh
Jun 28, 2015
Jonathan M Davis
Jun 28, 2015
Jonathan M Davis
Jun 28, 2015
Shachar Shemesh
Jun 28, 2015
Jonathan M Davis
Jul 25, 2015
Kenji Hara
Jun 06, 2019
Basile-z
Mar 21, 2020
Basile-z
June 09, 2015
https://issues.dlang.org/show_bug.cgi?id=5517

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|D1 & D2                     |D2

--
June 25, 2015
https://issues.dlang.org/show_bug.cgi?id=5517

Shachar Shemesh <shachar@shemesh.biz> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |shachar@shemesh.biz
         Resolution|INVALID                     |---

--- Comment #11 from Shachar Shemesh <shachar@shemesh.biz> ---
Quoth the same spec:
void main()
{
  assert(0, "an" ~ "error message");
}

When compiled and run, it will produce the message:
Error: AssertError Failure test.d(3) an error message

In practice, all it produces is:
Segmentation fault (core dumped)

We can clearly see that dmd, hence, violates the spec.

Also, the following statement in the spec is demonstrable wrong:
(on the x86 processor, a HLT instruction can be used to halt execution)

This is untrue (or, at the very least, highly misleading) for all user space
programming purposes.

--
June 28, 2015
https://issues.dlang.org/show_bug.cgi?id=5517

--- Comment #12 from Jonathan M Davis <issues.dlang@jmdavisProg.com> ---
(In reply to Shachar Shemesh from comment #11)
> Quoth the same spec:
> void main()
> {
>   assert(0, "an" ~ "error message");
> }
> 
> When compiled and run, it will produce the message:
> Error: AssertError Failure test.d(3) an error message
> 
> In practice, all it produces is:
> Segmentation fault (core dumped)

It produces a message when compiled without -release. With -release, it becomes a HLT instruction, so no message.

> We can clearly see that dmd, hence, violates the spec.

Walter quoted the spec. It's correct. If somewhere is in the spec doesn't match that, then it should be updated. I would not expect the compiler's behavior to be changed.

Why have you reopened this issue? If the spec needs to be updated because it's unclear somewhere, then open a new issue for that. But Walter has made it clear this is acting as intended, and I really don't see a problem with it.

--
June 28, 2015
https://issues.dlang.org/show_bug.cgi?id=5517

--- Comment #13 from Jonathan M Davis <issues.dlang@jmdavisProg.com> ---
On a side note, I just tried this on FreeBSD with -release, and I get a "bus error" rather than a segmentation fault, so the behavior there is slightly different from Linux, if that matters at all. Either way, it's killing the program like it's supposed to.

--
June 28, 2015
https://issues.dlang.org/show_bug.cgi?id=5517

--- Comment #14 from Shachar Shemesh <shachar@shemesh.biz> ---
(In reply to Jonathan M Davis from comment #13)
> Either way, it's killing the program like it's supposed to.

But it is not printing the message.

Yes, I think the spec is wrong (and, at least when opening a new bug, Bugzilla is directing me to use this category, of bugs in the compiler, to report minor problems with the spec), but that is not the core of this issue, and not the reason I reopened it.

The core of this issue is that "assert(false, "message")" is defined by the spec to print the message and abort even in release mode. In practice, it aborts (in an incorrect way, IMHO), but does not print the message.

And this is a bug in the compiler.

Shachar

--
June 28, 2015
https://issues.dlang.org/show_bug.cgi?id=5517

--- Comment #15 from Jonathan M Davis <issues.dlang@jmdavisProg.com> ---
(In reply to Shachar Shemesh from comment #14)
> (In reply to Jonathan M Davis from comment #13)
> > Either way, it's killing the program like it's supposed to.
> 
> But it is not printing the message.
> 
> And this is a bug in the compiler.

Walter has made it clear that this is _not_ a bug in the compiler. The compiler is not required to print a message in release mode. Rather, it quite specifically inserts an HLT instruction - which isn't going to print a message. And I very much doubt that the spec says anywhere that assertions print out anything in release mode, since all other assertions get compiled out in release mode, and the spec clearly states that assert(0) gets turned into a HLT instruction in release mode. So, while I can see why you might want a message in release mode, I don't see how you can claim that it's a compiler bug that assert(0, "message") doesn't print one. Where in the spec gives you the idea that assert(0, "message") would print out anything in release mode? If it didn't print something when you compiled _without_ -release, then that would be a bug, but if you compile with -release, you get a HLT instruction and no message.

And even if there is somewhere in the spec that implies that assert(0, "message") is supposed to print a message even in release mode, Walter has made it clear that the compiler is doing what it's supposed to be doing, so if the spec isn't clear enough on the matter, then the spec needs to be updated. The compiler's current behavior is not going to be changed.

--
July 25, 2015
https://issues.dlang.org/show_bug.cgi?id=5517

--- Comment #16 from Kenji Hara <k.hara.pg@gmail.com> ---
(In reply to Shachar Shemesh from comment #14)
> But it is not printing the message.

Recently I opened a PR to update core language specifications. https://github.com/D-Programming-Language/dlang.org/pull/1040

In that, I modified the description about the assert(0, message) in order to follow the current compiler behavior. https://github.com/9rnsr/dlang.org/commit/4f5da7958fe2665b57521b5d897b00ed57cdab48

If you interested, please join the review of the PR.

--
June 06, 2019
https://issues.dlang.org/show_bug.cgi?id=5517

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
                 CC|                            |b2.temp@gmx.com
         Resolution|---                         |WORKSFORME

--- Comment #17 from Basile-z <b2.temp@gmx.com> ---
SEGILL, as expected, is generated nowadays, the message is another problem.

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=5517

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|b2.temp@gmx.com             |

--