This is an archive of the discontinued LLVM Phabricator instance.

[Sema][SVE] Don't allow sizeless objects to be thrown
ClosedPublic

Authored by rsandifo-arm on Mar 12 2020, 11:55 AM.

Details

Summary

The same rules for throwing and catching incomplete types also apply
to sizeless types. This patch enforces that for throw statements.
It also make sure that we use "sizeless type" rather "incomplete type"
in the associated message. (Both are correct, but "sizeless type" is
more specific and hopefully more user-friendly.)

Diff Detail

Event Timeline

rsandifo-arm created this revision.Mar 12 2020, 11:55 AM

Why is throwing an svint8_t * an error? I don't see any obvious reason to forbid that.

Why is throwing an svint8_t * an error? I don't see any obvious reason to forbid that.

Yeah, I agree there's no obvious reason why it wouldn't work. The same reasoning applies here as for D76086:

(In practice, throwing pointers to sizeless types could probably
be handled without problems. It would be an odd thing to do though,
and so it didn't seem worth treating as a special case.)

I.e. once sizeless types are treated as incomplete types (which happens towards the end of the series), we'd have to create a new rule to allow sizeless types only for the pointer case. But since no-one will hopefully want to throw such a thing, it seemed better to keep it simple and leave the rule unchanged.

We already have a special case for void* here; it's trivial to extend that to also check for sizeless types. I don't want to add weird semantic restrictions just to save a few characters in the compiler.

I agree that most people won't run into it either way.

Allow pointers to sizeless types to be thrown.

We already have a special case for void* here; it's trivial to extend that to also check for sizeless types. I don't want to add weird semantic restrictions just to save a few characters in the compiler.

OK, I've done that in v2. It didn't feel right to add a Ty->isSizelessType() check alongside the existing Ty->isVoidType() check because sizelessness is IMO logically orthogonal to whether we have a fully fleshed-out definition or not. E.g. an earlier version of the extension allowed sizeless structures, and although they are no longer supported, the principle still holds that forward declarations of sizeless types make just as much conceptual sense as forward declarations of sized types. We'd then want to treat pointers to incompletely-defined sizeless types in the same as pointers to incompletely-defined sized types. The patch therefore checks for a sizeless type after RequireCompleteType instead.

This revision is now accepted and ready to land.Mar 12 2020, 3:20 PM
This revision was automatically updated to reflect the committed changes.