www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18504] New: Assert in synchronized crashes with SIGILL on exit


          Issue ID: 18504
           Summary: Assert in synchronized crashes with SIGILL on exit
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: default_357-line yahoo.de


void main() { synchronized assert(0); }

Expected: Error printed, program exits with error code.

Actual: Error printed, program exits with Illegal Instruction.

What happens:

In 9327d158d457093f5fc064a844f3400515558112 (emit better code for try-finally
when function does not throw) for v2.078.0, Walter added an optimization that
finally blocks can be handled more efficiently if the function does not throw

AssertError is not an exception.

As a result, the mutex of the synchronized{} block is never unlocked.

On program exit, the runtime tries to clean up mutexes at program end.
(_d_critical_term -> destroyMutex -> pthread_mutex_destroy)

pthread_mutex_destroy errors if the mutex is still locked. This triggers the
assert(0), which shows (in release mode) as a ud2: illegal instruction.

Feb 23 2018