summaryrefslogtreecommitdiffstats
path: root/lldb
diff options
context:
space:
mode:
Diffstat (limited to 'lldb')
-rw-r--r--lldb/lit/Expr/Inputs/ir-memory-map-basic.test25
-rw-r--r--lldb/lit/Expr/Inputs/ir-memory-map-overlap1.test10
-rw-r--r--lldb/lit/Expr/TestIRMemoryMap.test29
-rw-r--r--lldb/source/Expression/IRMemoryMap.cpp18
4 files changed, 49 insertions, 33 deletions
diff --git a/lldb/lit/Expr/Inputs/ir-memory-map-basic.test b/lldb/lit/Expr/Inputs/ir-memory-map-basic.test
new file mode 100644
index 00000000000..2f97d98155b
--- /dev/null
+++ b/lldb/lit/Expr/Inputs/ir-memory-map-basic.test
@@ -0,0 +1,25 @@
+malloc 0 1
+malloc 1 1
+
+malloc 2 1
+malloc 2 2
+malloc 2 4
+
+malloc 3 1
+malloc 3 2
+malloc 3 4
+
+malloc 128 1
+malloc 128 2
+malloc 128 4
+malloc 128 128
+
+malloc 2048 1
+malloc 2048 2
+malloc 2048 4
+
+malloc 3968 1
+malloc 3968 2
+malloc 3968 4
+
+malloc 0 1
diff --git a/lldb/lit/Expr/Inputs/ir-memory-map-overlap1.test b/lldb/lit/Expr/Inputs/ir-memory-map-overlap1.test
new file mode 100644
index 00000000000..535e3cae5b2
--- /dev/null
+++ b/lldb/lit/Expr/Inputs/ir-memory-map-overlap1.test
@@ -0,0 +1,10 @@
+malloc 8 16
+malloc 16 8
+malloc 64 32
+malloc 1 8
+malloc 64 32
+malloc 64 8
+malloc 1024 32
+malloc 1 16
+malloc 8 16
+malloc 1024 16 \ No newline at end of file
diff --git a/lldb/lit/Expr/TestIRMemoryMap.test b/lldb/lit/Expr/TestIRMemoryMap.test
index dfe3128e04e..8ca46718531 100644
--- a/lldb/lit/Expr/TestIRMemoryMap.test
+++ b/lldb/lit/Expr/TestIRMemoryMap.test
@@ -1,28 +1,3 @@
# RUN: %cxx %p/Inputs/call-function.cpp -g -o %t
-# RUN: lldb-test ir-memory-map %t %s
-
-malloc 0 1
-malloc 1 1
-
-malloc 2 1
-malloc 2 2
-malloc 2 4
-
-malloc 3 1
-malloc 3 2
-malloc 3 4
-
-malloc 128 1
-malloc 128 2
-malloc 128 4
-malloc 128 128
-
-malloc 2048 1
-malloc 2048 2
-malloc 2048 4
-
-malloc 3968 1
-malloc 3968 2
-malloc 3968 4
-
-malloc 0 1
+# RUN: lldb-test ir-memory-map %t %S/Inputs/ir-memory-map-basic.test
+# RUN: lldb-test ir-memory-map %t %S/Inputs/ir-memory-map-overlap1.test
diff --git a/lldb/source/Expression/IRMemoryMap.cpp b/lldb/source/Expression/IRMemoryMap.cpp
index 8fc2b4a4520..1953e80852f 100644
--- a/lldb/source/Expression/IRMemoryMap.cpp
+++ b/lldb/source/Expression/IRMemoryMap.cpp
@@ -301,15 +301,21 @@ lldb::addr_t IRMemoryMap::Malloc(size_t size, uint8_t alignment,
lldb::addr_t allocation_address = LLDB_INVALID_ADDRESS;
lldb::addr_t aligned_address = LLDB_INVALID_ADDRESS;
- size_t alignment_mask = alignment - 1;
size_t allocation_size;
- if (size == 0)
+ if (size == 0) {
+ // FIXME: Malloc(0) should either return an invalid address or assert, in
+ // order to cut down on unnecessary allocations.
allocation_size = alignment;
- else
- allocation_size = (size & alignment_mask)
- ? ((size + alignment) & (~alignment_mask))
- : size;
+ } else {
+ // Round up the requested size to an aligned value.
+ allocation_size = llvm::alignTo(size, alignment);
+
+ // The process page cache does not see the requested alignment. We can't
+ // assume its result will be any more than 1-byte aligned. To work around
+ // this, request `alignment - 1` additional bytes.
+ allocation_size += alignment - 1;
+ }
switch (policy) {
default:
OpenPOWER on IntegriCloud