aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGObjCMac.cpp
diff options
context:
space:
mode:
authorAtariDreams <83477269+AtariDreams@users.noreply.github.com>2024-03-05 06:32:45 -0500
committerGitHub <noreply@github.com>2024-03-05 06:32:45 -0500
commit923ddf65f4e21ec67018cf56e823895de18d83bc (patch)
treef71a559e4379de3fc5b8dddc5454f5e518ed3d82 /clang/lib/CodeGen/CGObjCMac.cpp
parent762f762504967efbe159db5c737154b989afc9bb (diff)
downloadllvm-923ddf65f4e21ec67018cf56e823895de18d83bc.zip
llvm-923ddf65f4e21ec67018cf56e823895de18d83bc.tar.gz
llvm-923ddf65f4e21ec67018cf56e823895de18d83bc.tar.bz2
[ObjC] Check entire chain of superclasses to see if class layout is statically known (#81335)
As of now, we only check if a class directly inherits from NSObject to determine if said class has fixed offsets and can therefore "opt-out" from the non-fragile ABI for ivars. However, if an NSObject subclass has fixed offsets, then so must the subclasses of that subclass, so this allows us to optimize instances of subclasses of subclasses that inherit from NSObject and so on. To determine this, we need to find that the compiler can see the implementation of each intermediate class, as that means it is statically linked. Fixes: #81369
Diffstat (limited to 'clang/lib/CodeGen/CGObjCMac.cpp')
-rw-r--r--clang/lib/CodeGen/CGObjCMac.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 27d77e9..e815e09 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -1593,12 +1593,20 @@ private:
}
bool isClassLayoutKnownStatically(const ObjCInterfaceDecl *ID) {
- // NSObject is a fixed size. If we can see the @implementation of a class
- // which inherits from NSObject then we know that all it's offsets also must
- // be fixed. FIXME: Can we do this if see a chain of super classes with
- // implementations leading to NSObject?
- return ID->getImplementation() && ID->getSuperClass() &&
- ID->getSuperClass()->getName() == "NSObject";
+ // Test a class by checking its superclasses up to
+ // its base class if it has one.
+ for (; ID; ID = ID->getSuperClass()) {
+ // The layout of base class NSObject
+ // is guaranteed to be statically known
+ if (ID->getIdentifier()->getName() == "NSObject")
+ return true;
+
+ // If we cannot see the @implementation of a class,
+ // we cannot statically know the class layout.
+ if (!ID->getImplementation())
+ return false;
+ }
+ return false;
}
public: