This is an archive of the discontinued LLVM Phabricator instance.

Fix vtbl field addr space
ClosedPublic

Authored by yaxunl on Sep 15 2021, 11:27 AM.

Details

Summary

Storing the vtable field of an object should use the same address space as
the this pointer. Currently it is assumed to be addr space 0 but this may not
be true.

This assumption (added in 054cc3b1b469de4b0cb25d1dc3af43c679c5dc44) caused
issues for the out-of-tree CHERI targets.

Diff Detail

Event Timeline

yaxunl requested review of this revision.Sep 15 2021, 11:27 AM
yaxunl created this revision.

The following line is always just making a bitcast, then.

arichardson accepted this revision.Sep 15 2021, 12:57 PM

Thanks, I can confirm that this fixes the assertions we were seeing after merging D103835. A few minor suggestions below:

There's a typo in the commit message, I'd maybe change it to:
Storing the vtable field of an object should use the same address space as the this pointer.
And maybe change This caused issue for some out of tree project. to something like This assumption (added in 054cc3b1b469de4b0cb25d1dc3af43c679c5dc44) caused issues for the out-of-tree CHERI targets.

clang/lib/CodeGen/CGClass.cpp
2520–2525

As noted by @rjmccall, changing this line still allows all tests to pass (including our newly added out-of-tree CHERI ones).

2521–2522

Maybe this is clearer?

This revision is now accepted and ready to land.Sep 15 2021, 12:57 PM
yaxunl marked 2 inline comments as done.Sep 15 2021, 1:43 PM

Thanks, I can confirm that this fixes the assertions we were seeing after merging D103835. A few minor suggestions below:

There's a typo in the commit message, I'd maybe change it to:
Storing the vtable field of an object should use the same address space as the this pointer.
And maybe change This caused issue for some out of tree project. to something like This assumption (added in 054cc3b1b469de4b0cb25d1dc3af43c679c5dc44) caused issues for the out-of-tree CHERI targets.

will do

clang/lib/CodeGen/CGClass.cpp
2520–2525

will do. I think we can also make changes so that

VTableField = Builder.CreateBitCast(
      VTableField, VTablePtrTy->getPointerTo(ThisAddrSpace));
2521–2522

will do

yaxunl marked 2 inline comments as done.Sep 15 2021, 1:43 PM
yaxunl updated this revision to Diff 372792.Sep 15 2021, 1:49 PM
yaxunl edited the summary of this revision. (Show Details)

fix comments and casts

This revision was landed with ongoing or failed builds.Sep 16 2021, 7:58 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 16 2021, 7:58 AM