Separate bits combination in object header for local variables on stack (#3659)

This commit is contained in:
LepilkinaElena
2019-12-12 16:35:39 +03:00
committed by GitHub
parent 607210bea3
commit 736bbf0a86
3 changed files with 9 additions and 3 deletions
@@ -520,8 +520,8 @@ internal class FunctionGenerationContext(val function: LLVMValueRef,
fun setTypeInfoForLocalObject(objectHeader: LLVMValueRef) {
val typeInfo = structGep(objectHeader, 0, "typeInfoOrMeta_")
// Set tag OBJECT_TAG_PERMANENT_CONTAINER.
val typeInfoValue = intToPtr(or(ptrToInt(alloca(kTypeInfo), int32Type), Int32(1).llvm), kTypeInfoPtr)
// Set tag OBJECT_TAG_PERMANENT_CONTAINER | OBJECT_TAG_NONTRIVIAL_CONTAINER.
val typeInfoValue = intToPtr(or(ptrToInt(alloca(kTypeInfo), int32Type), Int32(3).llvm), kTypeInfoPtr)
store(typeInfoValue, typeInfo)
}
+1 -1
View File
@@ -29,7 +29,7 @@ namespace {
ALWAYS_INLINE inline void mutabilityCheck(KConstRef thiz) {
// TODO: optimize it!
if (thiz->container() != nullptr && thiz->container()->frozen()) {
if (!thiz->local() && thiz->container()->frozen()) {
ThrowInvalidMutabilityException(thiz);
}
}
+6
View File
@@ -371,6 +371,12 @@ struct ObjHeader {
return (reinterpret_cast<MetaObjHeader*>(clearPointerBits(typeInfoOrMeta_, OBJECT_TAG_MASK)))->container_;
}
inline bool local() const {
unsigned bits = getPointerBits(typeInfoOrMeta_, OBJECT_TAG_MASK);
return (bits & (OBJECT_TAG_PERMANENT_CONTAINER | OBJECT_TAG_NONTRIVIAL_CONTAINER)) ==
(OBJECT_TAG_PERMANENT_CONTAINER | OBJECT_TAG_NONTRIVIAL_CONTAINER);
}
// Unsafe cast to ArrayHeader. Use carefully!
ArrayHeader* array() { return reinterpret_cast<ArrayHeader*>(this); }
const ArrayHeader* array() const { return reinterpret_cast<const ArrayHeader*>(this); }