This is an archive of the discontinued LLVM Phabricator instance.

[CGCall] Annotate reference parameters with "align" attribute.
ClosedPublic

Authored by efriedma on May 18 2020, 3:15 PM.

Details

Summary

If we're going to assume references are dereferenceable, we should also assume they're aligned: otherwise, we can't actually dereference them.

See also D80072.

Diff Detail

Event Timeline

efriedma created this revision.May 18 2020, 3:15 PM
Herald added a project: Restricted Project. · View Herald Transcript

Hmm. It looks like we did reserve space for this in the great pointer-alignment-assumption detente ("RFC: Enforcing pointer type alignment in Clang" from early 2016, which I'm aware was never really a consensus position, but which we've nonetheless been living by):

But note that this rule does still allow the compiler to make stronger
abstract assumptions about the alignment of C++ references and the
"this" pointer.

clang/lib/CodeGen/CGCall.cpp
2116

This doesn't do the right thing for classes with virtual bases. There's a getNaturalTypeAlignment function you should be able to use, although you might have to pull it to CGM.

2258

Both of these are wrong for classes with virtual bases.

efriedma marked 2 inline comments as done.May 19 2020, 11:05 AM
efriedma added inline comments.
clang/lib/CodeGen/CGCall.cpp
2116

Good point; I'll fix it.

2258

I'm pretty sure classes with virtual bases aren't used with SwiftIndirectResult, so not really relevant.

efriedma updated this revision to Diff 264998.May 19 2020, 12:39 PM

Use getNaturalPointeeTypeAlignment to compute the alignment of a reference.

rjmccall accepted this revision.May 19 2020, 3:16 PM

LGTM.

clang/lib/CodeGen/CGCall.cpp
2258

Ah... true, and even if they were, it would presumably be a complete object that was returned.

This revision is now accepted and ready to land.May 19 2020, 3:16 PM
This revision was automatically updated to reflect the committed changes.