Skip to content

Commit d60e7dd

Browse files
vitalybukaAdvenamTacet
authored andcommitted
Move conditions into CopyContainerFirstGranuleAnnotation/CopyContainerLastGranuleAnnotation
1 parent 88b5069 commit d60e7dd

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

compiler-rt/lib/asan/asan_poisoning.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,10 @@ static void SlowReversedCopyContainerAnnotations(uptr src_beg, uptr src_end,
653653
static void CopyContainerFirstGranuleAnnotation(uptr src_beg, uptr dst_beg) {
654654
constexpr uptr granularity = ASAN_SHADOW_GRANULARITY;
655655
// First granule
656-
uptr dst_beg_down = RoundDownTo(dst_beg, granularity);
657656
uptr src_beg_down = RoundDownTo(src_beg, granularity);
657+
uptr dst_beg_down = RoundDownTo(dst_beg, granularity);
658+
if (dst_beg_down == dst_beg)
659+
return;
658660
if (!AddressIsPoisoned(src_beg))
659661
*(u8 *)MemToShadow(dst_beg_down) = *(u8 *)MemToShadow(src_beg_down);
660662
else if (!AddressIsPoisoned(dst_beg))
@@ -664,11 +666,13 @@ static void CopyContainerFirstGranuleAnnotation(uptr src_beg, uptr dst_beg) {
664666
// A helper function for __sanitizer_copy_contiguous_container_annotations,
665667
// has assumption about begin and end of the container.
666668
// Should not be used stand alone.
667-
static void CopyContainerLastGranuleAnnotation(uptr src_end,
668-
uptr dst_end_down) {
669+
static void CopyContainerLastGranuleAnnotation(uptr src_end, uptr dst_end) {
669670
constexpr uptr granularity = ASAN_SHADOW_GRANULARITY;
670671
// Last granule
671672
uptr src_end_down = RoundDownTo(src_end, granularity);
673+
uptr dst_end_down = RoundDownTo(dst_end, granularity);
674+
if (dst_end_down == dst_end || !AddressIsPoisoned(dst_end))
675+
return;
672676
if (AddressIsPoisoned(src_end))
673677
*(u8 *)MemToShadow(dst_end_down) = *(u8 *)MemToShadow(src_end_down);
674678
else
@@ -736,26 +740,21 @@ void __sanitizer_copy_contiguous_container_annotations(const void *src_beg_p,
736740
// from the middle.
737741
uptr dst_beg_up = RoundUpTo(dst_beg, granularity);
738742
uptr dst_end_down = RoundDownTo(dst_end, granularity);
739-
if (copy_in_reversed_order) {
740-
if (dst_end_down != dst_end && AddressIsPoisoned(dst_end))
741-
CopyContainerLastGranuleAnnotation(src_end, dst_end_down);
742-
} else {
743-
if (dst_beg_up != dst_beg)
744-
CopyContainerFirstGranuleAnnotation(src_beg, dst_beg);
745-
}
743+
if (copy_in_reversed_order)
744+
CopyContainerLastGranuleAnnotation(src_end, dst_end);
745+
else
746+
CopyContainerFirstGranuleAnnotation(src_beg, dst_beg);
746747

747748
if (dst_beg_up < dst_end_down) {
748749
internal_memmove((u8 *)MemToShadow(dst_beg_up),
749-
(u8 *)MemToShadow(src_beg_up),
750-
(dst_end_down - dst_beg_up) / granularity);
750+
(u8 *)MemToShadow(src_beg_up),
751+
(dst_end_down - dst_beg_up) / granularity);
751752
}
752753

753-
if (copy_in_reversed_order) {
754-
if (dst_beg_up != dst_beg)
755-
CopyContainerFirstGranuleAnnotation(src_beg, dst_beg);
756-
} else if (dst_end_down != dst_end && AddressIsPoisoned(dst_end)) {
757-
CopyContainerLastGranuleAnnotation(src_end, dst_end_down);
758-
}
754+
if (copy_in_reversed_order)
755+
CopyContainerFirstGranuleAnnotation(src_beg, dst_beg);
756+
else
757+
CopyContainerLastGranuleAnnotation(src_end, dst_end);
759758
}
760759

761760
static const void *FindBadAddress(uptr begin, uptr end, bool poisoned) {

0 commit comments

Comments
 (0)