summaryrefslogtreecommitdiff
path: root/lib/CodeGen/SafeStackLayout.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-01-02 19:17:04 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-01-02 19:17:04 +0000
commitb915e9e0fc85ba6f398b3fab0db6a81a8913af94 (patch)
tree98b8f811c7aff2547cab8642daf372d6c59502fb /lib/CodeGen/SafeStackLayout.cpp
parent6421cca32f69ac849537a3cff78c352195e99f1b (diff)
Notes
Diffstat (limited to 'lib/CodeGen/SafeStackLayout.cpp')
-rw-r--r--lib/CodeGen/SafeStackLayout.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/CodeGen/SafeStackLayout.cpp b/lib/CodeGen/SafeStackLayout.cpp
index fb433c1856a6..7d4dbd13abf4 100644
--- a/lib/CodeGen/SafeStackLayout.cpp
+++ b/lib/CodeGen/SafeStackLayout.cpp
@@ -132,6 +132,14 @@ void StackLayout::computeLayout() {
// If this is replaced with something smarter, it must preserve the property
// that the first object is always at the offset 0 in the stack frame (for
// StackProtectorSlot), or handle stack protector in some other way.
+
+ // Sort objects by size (largest first) to reduce fragmentation.
+ if (StackObjects.size() > 2)
+ std::stable_sort(StackObjects.begin() + 1, StackObjects.end(),
+ [](const StackObject &a, const StackObject &b) {
+ return a.Size > b.Size;
+ });
+
for (auto &Obj : StackObjects)
layoutObject(Obj);