This is an archive of the discontinued LLVM Phabricator instance.

Fix crash on XCore on unused inline in EmitTargetMetadata
ClosedPublic

Authored by nigelp-xmos on Mar 30 2020, 8:58 AM.

Details

Summary

EmitTargetMetadata passed to emitTargetMD a null pointer as returned from GetGlobalValue, for an unused inline function which has been removed from the module at that point.

A FIXME in CodeGenModule.cpp commented that the calling code in EmitTargetMetadata should be moved into the one target that needs it (XCore). A review comment agreed. So the calling loop has been moved into the XCore subclass. The check for null is done in that loop.

Diff Detail

Event Timeline

nigelp-xmos created this revision.Mar 30 2020, 8:58 AM

Ping.

Just a polite ping to keep it alive. I hope that's all right. Not urgent at all.

This patches fixes two Clang tests which are failing for XCore target on 2020-04-27 with "unexpected null value" assert failures:

CodeGen/2003-12-14-ExternInlineSupport.c
CoverageMapping/unused_names.c

Adding code reviewer suggestions from git history. I would be grateful for review and/or reviewer suggestions. Many thanks.

It doesn't seem like it would be much work to move the EmitTargetMetadata function into the TargetInfo object (as a virtual function taking a reference to the collection). Essentially, have this take a reference to the collection instead of the 'D' and 'GV'.

I say that, because to me it seems that this check should likely be a part of that EmitTargetMetadata calling process (meaning, GV! = null is a precondition of this function).

Thanks for the comment, I will look into that.

As suggested by FIXME comment in code, and review comment, moved the EmitTargetMetadata loop into XCore target.

nigelp-xmos edited the summary of this revision. (Show Details)May 19 2020, 2:37 AM
RKSimon resigned from this revision.May 25 2020, 11:37 AM

Ping. I made the change suggested by @erichkeane .

The test needs work (check/check-not lines+ filecheck), otherwise I think this should be alright, particularly if no one else has commented in a while. I'd like to have you upload an updated test validating what you think should be happening before approving though.

clang/test/CodeGen/xcore-unused-inline.c
5

What is this test validating? It should likely have a check line of some sort.

nigelp-xmos marked an inline comment as done.Jun 22 2020, 8:59 AM
nigelp-xmos added inline comments.
clang/test/CodeGen/xcore-unused-inline.c
5

Currently this file crashes clang with xcore target, so it was to check there is no crash. I will add a comment to explain. I can add a CHECK too. Thank you.

nigelp-xmos retitled this revision from [XCore] fix crash on unused inline in EmitTargetMetadata to Fix crash on XCore on unused inline in EmitTargetMetadata.

Added explanatory comment and CHECK lines to test case, as per review comment.

Removed "[XCore]" from title as the changes are not all in XCore-only code.

I do not have commit access, so if this is approved, please could it be committed against author "Nigel Perks" nigelp@xmos.com ?

erichkeane accepted this revision.Jun 24 2020, 12:21 PM

I talked to others about the test, and they suggested the correct way to validate this is to make it simply a 'doesn't crash' test, so I'll remove the filecheck/check lines and submit this. The comment there seems sufficient to describe, so I'll live it in place.

This revision is now accepted and ready to land.Jun 24 2020, 12:21 PM
This revision was automatically updated to reflect the committed changes.