1 //===-- sanitizer_range.cpp -----------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "sanitizer_range.h"
11 #include "sanitizer_common/sanitizer_array_ref.h"
13 namespace __sanitizer
{
15 void Intersect(ArrayRef
<Range
> a
, ArrayRef
<Range
> b
,
16 InternalMmapVectorNoCtor
<Range
> &output
) {
25 InternalMmapVector
<Event
> events
;
26 for (const Range
&r
: a
) {
27 CHECK_LE(r
.begin
, r
.end
);
28 events
.push_back({r
.begin
, 1, 0});
29 events
.push_back({r
.end
, -1, 0});
32 for (const Range
&r
: b
) {
33 CHECK_LE(r
.begin
, r
.end
);
34 events
.push_back({r
.begin
, 0, 1});
35 events
.push_back({r
.end
, 0, -1});
38 Sort(events
.data(), events
.size(),
39 [](const Event
&lh
, const Event
&rh
) { return lh
.val
< rh
.val
; });
44 for (const auto &e
: events
) {
48 if (state1
&& state2
) {
49 if (!output
.empty() && start
== output
.back().end
)
50 output
.back().end
= e
.val
;
52 output
.push_back({start
, e
.val
});
62 } // namespace __sanitizer