summaryrefslogtreecommitdiffstats
path: root/build/build-clang/llvmorg-17-init-6909-gd644ab022a7b.patch
blob: ed7dcc8b2e4c4fa3540a38da9af74624c77f9534 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
From d644ab022a7be985255db29fd466798e9b138bee Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston@google.com>
Date: Tue, 4 Apr 2023 00:42:37 +0000
Subject: [PATCH] Update __sanitizer_get_allocated_begin to return const void*

D147005 introduced __sanitizer_get_allocated_begin, with a return
value of void*. This involved a few naughty casts that dropped the
const. This patch adds back the const qualifier.

Differential Revision: https://reviews.llvm.org/D147489
---
 compiler-rt/include/sanitizer/allocator_interface.h         | 2 +-
 compiler-rt/lib/asan/asan_allocator.cpp                     | 6 +++---
 compiler-rt/lib/dfsan/dfsan_allocator.cpp                   | 6 +++---
 compiler-rt/lib/hwasan/hwasan_allocator.cpp                 | 6 +++---
 compiler-rt/lib/lsan/lsan_allocator.cpp                     | 6 +++---
 compiler-rt/lib/memprof/memprof_allocator.cpp               | 6 +++---
 compiler-rt/lib/msan/msan_allocator.cpp                     | 6 +++---
 .../lib/sanitizer_common/sanitizer_allocator_interface.h    | 2 +-
 compiler-rt/lib/tsan/rtl/tsan_mman.cpp                      | 6 +++---
 .../test/sanitizer_common/TestCases/get_allocated_begin.cpp | 2 +-
 10 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/compiler-rt/include/sanitizer/allocator_interface.h b/compiler-rt/include/sanitizer/allocator_interface.h
index d846f3f330741..d0cfce79c1aef 100644
--- a/compiler-rt/include/sanitizer/allocator_interface.h
+++ b/compiler-rt/include/sanitizer/allocator_interface.h
@@ -28,7 +28,7 @@ extern "C" {
 
   /* If a pointer lies within an allocation, it will return the start address
      of the allocation. Otherwise, it returns nullptr. */
-  void *__sanitizer_get_allocated_begin(const void *p);
+  const void *__sanitizer_get_allocated_begin(const void *p);
 
   /* Returns the number of bytes reserved for the pointer p.
      Requires (get_ownership(p) == true) or (p == 0). */
diff --git a/compiler-rt/lib/asan/asan_allocator.cpp b/compiler-rt/lib/asan/asan_allocator.cpp
index 4b65b44a88f91..708d975a93dcf 100644
--- a/compiler-rt/lib/asan/asan_allocator.cpp
+++ b/compiler-rt/lib/asan/asan_allocator.cpp
@@ -1164,7 +1164,7 @@ IgnoreObjectResult IgnoreObjectLocked(const void *p) {
 // ---------------------- Interface ---------------- {{{1
 using namespace __asan;
 
-void *AllocationBegin(const void *p) {
+const void *AllocationBegin(const void *p) {
   AsanChunk *m = __asan::instance.GetAsanChunkByAddr((uptr)p);
   if (!m)
     return nullptr;
@@ -1172,7 +1172,7 @@ void *AllocationBegin(const void *p) {
     return nullptr;
   if (m->UsedSize() == 0)
     return nullptr;
-  return (void *)(m->Beg());
+  return (const void *)(m->Beg());
 }
 
 // ASan allocator doesn't reserve extra bytes, so normally we would
@@ -1198,7 +1198,7 @@ uptr __sanitizer_get_allocated_size(const void *p) {
   return allocated_size;
 }
 
-void *__sanitizer_get_allocated_begin(const void *p) {
+const void *__sanitizer_get_allocated_begin(const void *p) {
   return AllocationBegin(p);
 }
 
diff --git a/compiler-rt/lib/dfsan/dfsan_allocator.cpp b/compiler-rt/lib/dfsan/dfsan_allocator.cpp
index 7ae6024fb2c9d..36346d163d982 100644
--- a/compiler-rt/lib/dfsan/dfsan_allocator.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_allocator.cpp
@@ -174,7 +174,7 @@ void *DFsanCalloc(uptr nmemb, uptr size) {
   return DFsanAllocate(nmemb * size, sizeof(u64), true /*zeroise*/);
 }
 
-void *AllocationBegin(const void *p) {
+const void *AllocationBegin(const void *p) {
   if (!p)
     return nullptr;
   void *beg = allocator.GetBlockBegin(p);
@@ -185,7 +185,7 @@ void *AllocationBegin(const void *p) {
     return nullptr;
   if (b->requested_size == 0)
     return nullptr;
-  return (void *)beg;
+  return (const void *)beg;
 }
 
 static uptr AllocationSize(const void *p) {
@@ -308,7 +308,7 @@ uptr __sanitizer_get_estimated_allocated_size(uptr size) { return size; }
 
 int __sanitizer_get_ownership(const void *p) { return AllocationSize(p) != 0; }
 
-void *__sanitizer_get_allocated_begin(const void *p) {
+const void *__sanitizer_get_allocated_begin(const void *p) {
   return AllocationBegin(p);
 }
 
diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.cpp b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
index 8ccdeb23fa995..994a580dc95e0 100644
--- a/compiler-rt/lib/hwasan/hwasan_allocator.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
@@ -397,7 +397,7 @@ HwasanChunkView FindHeapChunkByAddress(uptr address) {
   return HwasanChunkView(reinterpret_cast<uptr>(block), metadata);
 }
 
-void *AllocationBegin(const void *p) {
+const void *AllocationBegin(const void *p) {
   const void *untagged_ptr = UntagPtr(p);
   if (!untagged_ptr)
     return nullptr;
@@ -411,7 +411,7 @@ void *AllocationBegin(const void *p) {
     return nullptr;
 
   tag_t tag = GetTagFromPointer((uptr)p);
-  return (void *)AddTagToPointer((uptr)beg, tag);
+  return (const void *)AddTagToPointer((uptr)beg, tag);
 }
 
 static uptr AllocationSize(const void *tagged_ptr) {
@@ -658,7 +658,7 @@ uptr __sanitizer_get_estimated_allocated_size(uptr size) { return size; }
 
 int __sanitizer_get_ownership(const void *p) { return AllocationSize(p) != 0; }
 
-void *__sanitizer_get_allocated_begin(const void *p) {
+const void *__sanitizer_get_allocated_begin(const void *p) {
   return AllocationBegin(p);
 }
 
diff --git a/compiler-rt/lib/lsan/lsan_allocator.cpp b/compiler-rt/lib/lsan/lsan_allocator.cpp
index b0a54d7cd9bc5..471b134a26471 100644
--- a/compiler-rt/lib/lsan/lsan_allocator.cpp
+++ b/compiler-rt/lib/lsan/lsan_allocator.cpp
@@ -145,7 +145,7 @@ void GetAllocatorCacheRange(uptr *begin, uptr *end) {
   *end = *begin + sizeof(AllocatorCache);
 }
 
-void *GetMallocBegin(const void *p) {
+const void *GetMallocBegin(const void *p) {
   if (!p)
     return nullptr;
   void *beg = allocator.GetBlockBegin(p);
@@ -158,7 +158,7 @@ void *GetMallocBegin(const void *p) {
     return nullptr;
   if (m->requested_size == 0)
     return nullptr;
-  return (void *)beg;
+  return (const void *)beg;
 }
 
 uptr GetMallocUsableSize(const void *p) {
@@ -380,7 +380,7 @@ SANITIZER_INTERFACE_ATTRIBUTE
 int __sanitizer_get_ownership(const void *p) { return Metadata(p) != nullptr; }
 
 SANITIZER_INTERFACE_ATTRIBUTE
-void * __sanitizer_get_allocated_begin(const void *p) {
+const void * __sanitizer_get_allocated_begin(const void *p) {
   return GetMallocBegin(p);
 }
 
diff --git a/compiler-rt/lib/memprof/memprof_allocator.cpp b/compiler-rt/lib/memprof/memprof_allocator.cpp
index 80a87d49dfc6e..49c0aad39cfbd 100644
--- a/compiler-rt/lib/memprof/memprof_allocator.cpp
+++ b/compiler-rt/lib/memprof/memprof_allocator.cpp
@@ -681,7 +681,7 @@ int memprof_posix_memalign(void **memptr, uptr alignment, uptr size,
   return 0;
 }
 
-void *memprof_malloc_begin(const void *p) {
+const void *memprof_malloc_begin(const void *p) {
   u64 user_requested_size;
   MemprofChunk *m =
       instance.GetMemprofChunkByAddr((uptr)p, user_requested_size);
@@ -690,7 +690,7 @@ void *memprof_malloc_begin(const void *p) {
   if (user_requested_size == 0)
     return nullptr;
 
-  return (void *)m->Beg();
+  return (const void *)m->Beg();
 }
 
 uptr memprof_malloc_usable_size(const void *ptr, uptr pc, uptr bp) {
@@ -711,7 +711,7 @@ int __sanitizer_get_ownership(const void *p) {
   return memprof_malloc_usable_size(p, 0, 0) != 0;
 }
 
-void *__sanitizer_get_allocated_begin(const void *p) {
+const void *__sanitizer_get_allocated_begin(const void *p) {
   return memprof_malloc_begin(p);
 }
 
diff --git a/compiler-rt/lib/msan/msan_allocator.cpp b/compiler-rt/lib/msan/msan_allocator.cpp
index 08ec3314b26e6..1013303af6795 100644
--- a/compiler-rt/lib/msan/msan_allocator.cpp
+++ b/compiler-rt/lib/msan/msan_allocator.cpp
@@ -260,7 +260,7 @@ static void *MsanCalloc(StackTrace *stack, uptr nmemb, uptr size) {
   return MsanAllocate(stack, nmemb * size, sizeof(u64), true);
 }
 
-void *AllocationBegin(const void *p) {
+const void *AllocationBegin(const void *p) {
   if (!p)
     return nullptr;
   void *beg = allocator.GetBlockBegin(p);
@@ -272,7 +272,7 @@ void *AllocationBegin(const void *p) {
   if (b->requested_size == 0)
     return nullptr;
 
-  return (void *)beg;
+  return (const void *)beg;
 }
 
 static uptr AllocationSize(const void *p) {
@@ -388,7 +388,7 @@ uptr __sanitizer_get_estimated_allocated_size(uptr size) { return size; }
 
 int __sanitizer_get_ownership(const void *p) { return AllocationSize(p) != 0; }
 
-void *__sanitizer_get_allocated_begin(const void *p) {
+const void *__sanitizer_get_allocated_begin(const void *p) {
   return AllocationBegin(p);
 }
 
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_interface.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_interface.h
index 35c7c97df3299..504109e9d3f6f 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_interface.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_interface.h
@@ -21,7 +21,7 @@ extern "C" {
 SANITIZER_INTERFACE_ATTRIBUTE
 uptr __sanitizer_get_estimated_allocated_size(uptr size);
 SANITIZER_INTERFACE_ATTRIBUTE int __sanitizer_get_ownership(const void *p);
-SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void *
+SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE const void *
 __sanitizer_get_allocated_begin(const void *p);
 SANITIZER_INTERFACE_ATTRIBUTE uptr
 __sanitizer_get_allocated_size(const void *p);
diff --git a/compiler-rt/lib/tsan/rtl/tsan_mman.cpp b/compiler-rt/lib/tsan/rtl/tsan_mman.cpp
index 3cc4d16955ede..b548265fe6833 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_mman.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_mman.cpp
@@ -352,7 +352,7 @@ void *user_pvalloc(ThreadState *thr, uptr pc, uptr sz) {
   return SetErrnoOnNull(user_alloc_internal(thr, pc, sz, PageSize));
 }
 
-void *user_alloc_begin(const void *p) {
+const void *user_alloc_begin(const void *p) {
   if (p == nullptr || !IsAppMem((uptr)p))
     return nullptr;
   void *beg = allocator()->GetBlockBegin(p);
@@ -363,7 +363,7 @@ void *user_alloc_begin(const void *p) {
   if (!b)
     return nullptr;  // Not a valid pointer.
 
-  return (void *)beg;
+  return (const void *)beg;
 }
 
 uptr user_alloc_usable_size(const void *p) {
@@ -444,7 +444,7 @@ int __sanitizer_get_ownership(const void *p) {
   return allocator()->GetBlockBegin(p) != 0;
 }
 
-void *__sanitizer_get_allocated_begin(const void *p) {
+const void *__sanitizer_get_allocated_begin(const void *p) {
   return user_alloc_begin(p);
 }
 
diff --git a/compiler-rt/test/sanitizer_common/TestCases/get_allocated_begin.cpp b/compiler-rt/test/sanitizer_common/TestCases/get_allocated_begin.cpp
index 6892a4a7fb282..1683063baea26 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/get_allocated_begin.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/get_allocated_begin.cpp
@@ -23,7 +23,7 @@ int main(void) {
 
     // Bogus value to unpoison start. Calling __sanitizer_get_allocated_begin
     // does not unpoison it.
-    void *start = NULL;
+    const void *start = NULL;
     for (int j = 0; j < sizes[i]; j++) {
       printf("j: %d\n", j);