From 8f423d0e29c7d98104a7345865115df71952bbff Mon Sep 17 00:00:00 2001 From: theraven Date: Sat, 14 May 2011 16:12:46 +0000 Subject: [PATCH] Fix non-fragile ivar short-circuiting (i.e. hard-code the CORRECT ivar addresses, don't make foo and foobar have the same offset). --- opts/IvarPass.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/opts/IvarPass.cpp b/opts/IvarPass.cpp index c61772b..420793c 100644 --- a/opts/IvarPass.cpp +++ b/opts/IvarPass.cpp @@ -50,8 +50,13 @@ namespace { GlobalVariable *Cls = M->getGlobalVariable("_OBJC_CLASS_" + className); if (!Cls) return 0; Constant *ClsStruct = Cls->getInitializer(); - // Size is initialized to be negative. + // Size is initialized to be negative for the non-fragile ABI. ConstantInt *Size = cast(ClsStruct->getOperand(5)); + int s = Size->getSExtValue(); + // If we find a fragile class in the hierarchy, don't perform the + // simplification. This means that we're the mixed ABI, so we need the + // extra indirection. + if (s > 0) return 0; return sizeOfClass(getSuperName(ClsStruct)) - Size->getSExtValue(); } @@ -73,7 +78,9 @@ namespace { cast(ivar->getOperand(0))->getOperand(0)); std::string ivarNameStr = cast(name->getInitializer())->getAsString(); - if (ivarNameStr.compare(0, ivarName.size(), ivarName.str()) == 0) + // Remove the NULL terminator from the metadata string + ivarNameStr.resize(ivarNameStr.size() - 1); + if (ivarNameStr == ivarName.str()) return superSize + cast(ivar->getOperand(2))->getSExtValue(); }