yaxunl created this revision.
yaxunl added reviewers: tra, rjmccall, arichardson.
yaxunl requested review of this revision.
vtbl filed of an object should have same addr space of the object.
Currently it is assumed to be addr space 0 but this may not
be true. This caused issue for some out of tree project.
https://reviews.llvm.org/D109841
Files:
clang/lib/CodeGen/CGClass.cpp
Index: clang/lib/CodeGen/CGClass.cpp
===================================================================
--- clang/lib/CodeGen/CGClass.cpp
+++ clang/lib/CodeGen/CGClass.cpp
@@ -2502,6 +2502,8 @@
// Apply the offsets.
Address VTableField = LoadCXXThisAddress();
+ unsigned ThisAddrSpace =
+ VTableField.getPointer()->getType()->getPointerAddressSpace();
if (!NonVirtualOffset.isZero() || VirtualOffset)
VTableField = ApplyNonVirtualAndVirtualOffset(
@@ -2516,10 +2518,11 @@
llvm::FunctionType::get(CGM.Int32Ty, /*isVarArg=*/true)
->getPointerTo(ProgAS)
->getPointerTo(GlobalsAS);
- // vtable field is is derived from `this` pointer, therefore it should be in
- // default address space.
+ // vtable field is is derived from `this` pointer, therefore they should be
in
+ // the same addr space. Note it may not be the default address space of LLVM
+ // IR.
VTableField = Builder.CreatePointerBitCastOrAddrSpaceCast(
- VTableField, VTablePtrTy->getPointerTo());
+ VTableField, VTablePtrTy->getPointerTo(ThisAddrSpace));
VTableAddressPoint = Builder.CreatePointerBitCastOrAddrSpaceCast(
VTableAddressPoint, VTablePtrTy);
Index: clang/lib/CodeGen/CGClass.cpp
===================================================================
--- clang/lib/CodeGen/CGClass.cpp
+++ clang/lib/CodeGen/CGClass.cpp
@@ -2502,6 +2502,8 @@
// Apply the offsets.
Address VTableField = LoadCXXThisAddress();
+ unsigned ThisAddrSpace =
+ VTableField.getPointer()->getType()->getPointerAddressSpace();
if (!NonVirtualOffset.isZero() || VirtualOffset)
VTableField = ApplyNonVirtualAndVirtualOffset(
@@ -2516,10 +2518,11 @@
llvm::FunctionType::get(CGM.Int32Ty, /*isVarArg=*/true)
->getPointerTo(ProgAS)
->getPointerTo(GlobalsAS);
- // vtable field is is derived from `this` pointer, therefore it should be in
- // default address space.
+ // vtable field is is derived from `this` pointer, therefore they should be in
+ // the same addr space. Note it may not be the default address space of LLVM
+ // IR.
VTableField = Builder.CreatePointerBitCastOrAddrSpaceCast(
- VTableField, VTablePtrTy->getPointerTo());
+ VTableField, VTablePtrTy->getPointerTo(ThisAddrSpace));
VTableAddressPoint = Builder.CreatePointerBitCastOrAddrSpaceCast(
VTableAddressPoint, VTablePtrTy);
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits