Skip to content

Fix Issue 20318 - Illegal instruction (core dumped)#10517

Merged
dlang-bot merged 1 commit intodlang:masterfrom
RazvanN7:Issue_20318
Oct 31, 2019
Merged

Fix Issue 20318 - Illegal instruction (core dumped)#10517
dlang-bot merged 1 commit intodlang:masterfrom
RazvanN7:Issue_20318

Conversation

@RazvanN7
Copy link
Contributor

@RazvanN7 RazvanN7 commented Oct 30, 2019

void main()
{
    throw new Exception("msg");
}

When an exception is thrown, typically it is allocated and managed by the garbage collector: the compiler replaces the expression with a call to a druntime hook, in this situation _d_newclass. If the code is compiled with profile=gc the hook is further replaced with a call to another hook d_newclass_trace that collects some stats and later calls _d_newclass.

If the above code is compiled with -dip1008 the exception no longer uses the gc to be managed; it is manually managed in druntime via reference counting. So if -dip1008 and -profile=gc are used together the following thing happens: (1) the exception throwing line is rewritten to a call to _d_newthrow in druntime which does the refcount initialization for the exception then (2) toTraceGC in dmd is called that replaces any allocation hooks with trace allocation hooks. Since _d_newthrow does not do any gc allocations and therefore does not have an associated trace function, toTraceGC gets confused and asserts.

The fix is to simply return from toTraceGC if the hook is not a gc allocation hook.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
20318 normal Illegal instruction (core dumped)

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + dmd#10517"

@codecov
Copy link

codecov bot commented Oct 30, 2019

Codecov Report

Merging #10517 into master will decrease coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10517      +/-   ##
==========================================
- Coverage    1.81%    1.81%   -0.01%     
==========================================
  Files         148      148              
  Lines       77438    77440       +2     
==========================================
  Hits         1405     1405              
- Misses      76033    76035       +2
Impacted Files Coverage Δ
src/dmd/e2ir.d 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 83fde70...eae1cd8. Read the comment docs.

Geod24
Geod24 previously requested changes Oct 30, 2019
Copy link
Member

@Geod24 Geod24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like a compilable test is what's needed there, but rather a runnable.

@RazvanN7
Copy link
Contributor Author

RazvanN7 commented Oct 30, 2019

I don't get it. This was an ICE that was triggered without my patch by the testcase that I added. How can it not be covered?

@wilzbach
Copy link
Contributor

I don't get it. This was an ICE that was triggered without my patch by the testcase that I added. How can it not be covered?

It looks like someone destroyed the coverage:

https://codecov.io/gh/dlang/dmd/commits

It's on 1.8%
This commit caused it: https://codecov.io/gh/dlang/dmd/commit/6bb95b5bed514070e13ec9a497f47a80e8dfc5c7
#10446

@Geod24 Geod24 dismissed their stale review October 30, 2019 13:54

Misread the issue

@marler8997
Copy link
Contributor

code coverage issue fixed here: #10520

@RazvanN7 RazvanN7 closed this Oct 31, 2019
@RazvanN7 RazvanN7 reopened this Oct 31, 2019
@RazvanN7
Copy link
Contributor Author

Is there any way to restart codecov?

@wilzbach
Copy link
Contributor

Yes, you need to restart the respective build (CircleCi). I just did so for you.

@WalterBright
Copy link
Member

Nice work!

I do like your explanation in the opening message here. Can you boil it down to its essence and add it as a comment to the code? Because it isn't obvious.

@RazvanN7
Copy link
Contributor Author

Nice work!

Thank you!

I do like your explanation in the opening message here. Can you boil it down to its essence and add it as a comment to the code? Because it isn't obvious.

Done.

@PetarKirov
Copy link
Member

PetarKirov commented Oct 31, 2019

Wouldn't it be better to make the call to toTraceGC conditional on whether the NexExp field ne.thrownew is true here:

dmd/src/dmd/e2ir.d

Lines 1676 to 1678 in a7017a9

const rtl = global.params.ehnogc && ne.thrownew ? RTLSYM_NEWTHROW : RTLSYM_NEWCLASS;
ex = el_bin(OPcall,TYnptr,el_var(getRtlsym(rtl)),el_ptr(csym));
toTraceGC(irs, ex, ne.loc);

And then assert that s != getRtlsym(RTLSYM_NEWTHROW) inside toTraceGC?

@RazvanN7
Copy link
Contributor Author

@PetarKirov That was my first thought also, but the call to toTraceGC is made regardless of whether profile=gc is set or not and the check for it is done inside the function, so I interpreted it as a means to keep the main code clean.

@PetarKirov
Copy link
Member

Fair enough

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants