aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-04-23 01:29:05 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-04-23 01:29:05 +0000
commit0941b49af3b7204ddb69ed21f07c966b8d949cf4 (patch)
treecad7c5c1af6900f82430d780001ec93be27fde66 /lib/CodeGen
parent653f1b1bf293a9bd96fd4dd6372e779cc7af1597 (diff)
Use std::sort instead of qsort.
- Notably, there was a memory error here, SkipIvars does not have to be the same size as IvarsInfo. - Fariborz, please check. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69850 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CGObjCMac.cpp22
1 files changed, 7 insertions, 15 deletions
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp
index cf15d2e62c..03f15ee7ed 100644
--- a/lib/CodeGen/CGObjCMac.cpp
+++ b/lib/CodeGen/CGObjCMac.cpp
@@ -707,6 +707,11 @@ public:
unsigned int ivar_bytepos;
unsigned int ivar_size;
GC_IVAR() : ivar_bytepos(0), ivar_size(0) {}
+
+ // Allow sorting based on byte pos.
+ bool operator<(const GC_IVAR &b) const {
+ return ivar_bytepos < b.ivar_bytepos;
+ }
};
class SKIP_SCAN {
@@ -3108,19 +3113,6 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCInterfaceDecl *OI,
}
}
-static int
-IvarBytePosCompare(const void *a, const void *b)
-{
- unsigned int sa = ((CGObjCCommonMac::GC_IVAR *)a)->ivar_bytepos;
- unsigned int sb = ((CGObjCCommonMac::GC_IVAR *)b)->ivar_bytepos;
-
- if (sa < sb)
- return -1;
- if (sa > sb)
- return 1;
- return 0;
-}
-
/// BuildIvarLayout - Builds ivar layout bitmap for the class
/// implementation for the __strong or __weak case.
/// The layout map displays which words in ivar list must be skipped
@@ -3168,9 +3160,9 @@ llvm::Constant *CGObjCCommonMac::BuildIvarLayout(
// Sort on byte position in case we encounterred a union nested in
// the ivar list.
if (hasUnion && !IvarsInfo.empty())
- qsort(&IvarsInfo[0], Index+1, sizeof(GC_IVAR), IvarBytePosCompare);
+ std::sort(IvarsInfo.begin(), IvarsInfo.end());
if (hasUnion && !SkipIvars.empty())
- qsort(&SkipIvars[0], Index+1, sizeof(GC_IVAR), IvarBytePosCompare);
+ std::sort(SkipIvars.begin(), SkipIvars.end());
// Build the string of skip/scan nibbles
SkipScan = -1;