This is an archive of the discontinued LLVM Phabricator instance.

[amdgpu] Don't crash on empty global ctor/dtor
ClosedPublic

Authored by JonChesterfield on Nov 12 2021, 1:12 PM.

Details

Summary

Global ctor/dtor can be an empty array, which is a Constant not a
ConstantArray. The cast<ConstantArray> therefore asserts / crashes.

Diff Detail

Event Timeline

JonChesterfield requested review of this revision.Nov 12 2021, 1:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 12 2021, 1:12 PM
arsenm added inline comments.Nov 12 2021, 1:19 PM
llvm/test/CodeGen/AMDGPU/lower-empty-ctor-dtor.ll
2

I don't see what this opt line is accomplishing with the checks. Needs some positive IR checks?

3

Why disassemble instead of directly emit text?

yaxunl added inline comments.Nov 12 2021, 1:23 PM
llvm/test/CodeGen/AMDGPU/lower-empty-ctor-dtor.ll
2

should we add a verify pass to make sure this is valid IR?

JonChesterfield added a comment.EditedNov 12 2021, 1:35 PM

Is is valid IR. There are several existing test cases with zero length global ctors.

The opt line is checking that @amdgcn.device.init kernels aren't emitted. It's disassembling instead of doing something else because it follows the pattern of lower-multiple-ctor-dtor.ll and lower-ctor-dtor.ll test cases introduced with D105682 which missed this case.

edit: don't mind if we go with this fix (which just ignores the zero length arrays) or another one, but the assert on unrelated test cases is blocking. I'm also fine with reverting D105682 while this is fixed.

arsenm accepted this revision.Nov 15 2021, 6:50 PM

I'm still not a huge fan of purely negative checks since it's so easy for them to break

This revision is now accepted and ready to land.Nov 15 2021, 6:50 PM
This revision was automatically updated to reflect the committed changes.