Skip to content

Commit cc250b8

Browse files
ampandey-AMDampandey-1995zmodem
authored
[compiler-rt]: fix CodeQL errors (llvm#3798)
Co-authored-by: Amit Kumar Pandey <[email protected]> Co-authored-by: Hans Wennborg <[email protected]> Co-authored-by: Amit Pandey <[email protected]>
1 parent 2c69a9e commit cc250b8

File tree

10 files changed

+66
-57
lines changed

10 files changed

+66
-57
lines changed

compiler-rt/lib/asan/asan_errors.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -649,11 +649,11 @@ void ErrorNonSelfGeneric::Print() {
649649
Decorator d;
650650
Printf("%s", d.Error());
651651
Report("ERROR: AddressSanitizer: %s on address %p at pc %p\n", bug_descr,
652-
(void *)addresses[0], callstack[0]);
652+
(void *)addresses[0], (void *)callstack[0]);
653653

654654
Printf("%s%s of size %zu at %p thread id %zu\n", d.Access(),
655655
access_size ? (is_write ? "WRITE" : "READ") : "ACCESS", access_size,
656-
(void *)addresses[0], thread_id[0]);
656+
(void *)addresses[0], (usize)thread_id[0]);
657657

658658
// todo: perform symbolization for the given callstack
659659
// can be done by creating in-memory object file or by writing
@@ -691,7 +691,7 @@ ErrorNonSelfAMDGPU::ErrorNonSelfAMDGPU(uptr *dev_callstack, u32 n_callstack,
691691

692692
void ErrorNonSelfAMDGPU::PrintStack() {
693693
InternalScopedString source_location;
694-
source_location.AppendF(" #0 %p", callstack[0]);
694+
source_location.AppendF(" #0 %p", (void *)callstack[0]);
695695
#if SANITIZER_AMDGPU
696696
source_location.Append(" in ");
697697
__sanitizer::AMDGPUCodeObjectSymbolizer symbolizer;
@@ -712,7 +712,8 @@ void ErrorNonSelfAMDGPU::PrintThreadsAndAddresses() {
712712
str.Append("\n");
713713
per_row_count = 0;
714714
}
715-
str.AppendF("%02d : %p ", workitem_ids[idx], device_address[idx]);
715+
str.AppendF("%02d : %p ", (int)workitem_ids[idx],
716+
(void *)device_address[idx]);
716717
per_row_count++;
717718
}
718719
str.Append("\n");
@@ -755,11 +756,12 @@ void ErrorNonSelfAMDGPU::PrintMallocStack() {
755756
uptr plo = ScanForMagicDown(start, lo, magic, lo);
756757
if (plo) {
757758
callstack[0] = ((uptr*)plo)[2];
758-
Printf("%s%p is %u bytes above an address from a %sdevice malloc "
759-
"(or free) call of size %u from%s\n",
760-
d.Location(), device_address[0],
761-
(int)(device_address[0] - (plo+offset)),
762-
d.Allocation(), ((int*)plo)[7], d.Default());
759+
Printf(
760+
"%s%p is %u bytes above an address from a %sdevice malloc "
761+
"(or free) call of size %u from%s\n",
762+
d.Location(), (void *)device_address[0],
763+
(u32)(device_address[0] - (plo + offset)), d.Allocation(),
764+
((u32*)plo)[7], d.Default());
763765
// TODO: The code object with the malloc call may not be the same
764766
// code object trying the illegal access. A mechanism is needed
765767
// to obtain the former.
@@ -769,12 +771,13 @@ void ErrorNonSelfAMDGPU::PrintMallocStack() {
769771
uptr phi = ScanForMagicUp(start, hi, magic, lo);
770772
if (phi) {
771773
callstack[0] = ((uptr*)phi)[2];
772-
Printf("%s%p is %u bytes below an address from a %sdevice malloc "
773-
"(or free) call of size %u from%s\n",
774-
d.Location(), device_address[0],
775-
(int)((phi+offset) - device_address[0]),
774+
Printf(
775+
"%s%p is %u bytes below an address from a %sdevice malloc "
776+
"(or free) call of size %u from%s\n",
777+
d.Location(), (void *)device_address[0],
778+
(u32)((phi + offset) - device_address[0]),
776779

777-
d.Allocation(), ((int*)phi)[7], d.Default());
780+
d.Allocation(), ((u32*)phi)[7], d.Default());
778781
PrintStack();
779782
}
780783
}
@@ -783,10 +786,11 @@ void ErrorNonSelfAMDGPU::PrintMallocStack() {
783786
void ErrorNonSelfAMDGPU::Print() {
784787
Decorator d;
785788
Printf("%s", d.Error());
786-
Report("ERROR: AddressSanitizer: %s on amdgpu device %zu at pc %p\n",
787-
bug_descr, device_id, callstack[0]);
788-
Printf("%s%s of size %zu in workgroup id (%zu,%zu,%zu)\n", d.Access(),
789-
(is_write ? "WRITE" : "READ"), access_size, wg.idx, wg.idy, wg.idz);
789+
Report("ERROR: AddressSanitizer: %s on amdgpu device %d at pc %p\n",
790+
bug_descr, device_id, (void *)callstack[0]);
791+
Printf("%s%s of size %zu in workgroup id (%llu,%llu,%llu)\n", d.Access(),
792+
(is_write ? "WRITE" : "READ"), access_size, wg.idx,
793+
wg.idy, wg.idz);
790794
Printf("%s", d.Default());
791795
PrintStack();
792796
Printf("%s", d.Location());

compiler-rt/lib/dfsan/dfsan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ static void PrintNoOriginTrackingWarning() {
792792

793793
static void PrintNoTaintWarning(const void *address) {
794794
Decorator d;
795-
Printf(" %sDFSan: no tainted value at %x%s\n", d.Warning(), address,
795+
Printf(" %sDFSan: no tainted value at %zx%s\n", d.Warning(), (uptr)address,
796796
d.Default());
797797
}
798798

compiler-rt/lib/hwasan/hwasan.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static void HwasanFormatMemoryUsage(InternalScopedString &s) {
176176
"HWASAN pid: %d rss: %zd threads: %zd stacks: %zd"
177177
" thr_aux: %zd stack_depot: %zd uniq_stacks: %zd"
178178
" heap: %zd",
179-
internal_getpid(), GetRSS(), thread_stats.n_live_threads,
179+
(int)internal_getpid(), GetRSS(), thread_stats.n_live_threads,
180180
thread_stats.total_stack_size,
181181
thread_stats.n_live_threads * thread_list.MemoryUsedPerThread(),
182182
sds.allocated, sds.n_uniq_ids, asc[AllocatorStatMapped]);
@@ -692,7 +692,7 @@ void __hwasan_handle_longjmp(const void *sp_dst) {
692692
"WARNING: HWASan is ignoring requested __hwasan_handle_longjmp: "
693693
"stack top: %p; target %p; distance: %p (%zd)\n"
694694
"False positive error reports may follow\n",
695-
(void *)sp, (void *)dst, dst - sp, dst - sp);
695+
(void *)sp, (void *)dst, (void *)(dst - sp), dst - sp);
696696
return;
697697
}
698698
TagMemory(sp, dst - sp, 0);

compiler-rt/lib/hwasan/hwasan_malloc_bisect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static inline bool malloc_bisect(StackTrace *stack, uptr orig_size) {
4141
if (h < left || h > right)
4242
return false;
4343
if (flags()->malloc_bisect_dump) {
44-
Printf("[alloc] %u %zu\n", h, orig_size);
44+
Printf("[alloc] %u %zu\n", (u32)h, orig_size);
4545
stack->Print();
4646
}
4747
return true;

compiler-rt/lib/hwasan/hwasan_report.cpp

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,9 @@ static void PrintStackAllocations(const StackAllocationsRingBuffer *sa,
306306
"%p is located %zd bytes %s a %zd-byte local variable %s "
307307
"[%p,%p) "
308308
"in %s %s\n",
309-
untagged_addr, offset, whence, local.size, local.name, best_beg,
310-
best_beg + local.size, local.function_name, location.data());
309+
(void *)untagged_addr, offset, whence, local.size, local.name,
310+
(void *)best_beg, (void *)(best_beg + local.size),
311+
local.function_name, location.data());
311312
location.clear();
312313
Printf("%s\n", d.Default());
313314
}
@@ -738,8 +739,8 @@ void BaseReport::PrintHeapOrGlobalCandidate() const {
738739
Printf("%s", d.Location());
739740
Printf("%p is located %zd bytes %s a %zd-byte region [%p,%p)\n",
740741
untagged_addr, offset, whence,
741-
candidate.heap.end - candidate.heap.begin, candidate.heap.begin,
742-
candidate.heap.end);
742+
candidate.heap.end - candidate.heap.begin,
743+
(void *)candidate.heap.begin, (void *)candidate.heap.end);
743744
Printf("%s", d.Allocation());
744745
Printf("allocated by thread T%u here:\n", candidate.heap.thread_id);
745746
Printf("%s", d.Default());
@@ -762,26 +763,26 @@ void BaseReport::PrintHeapOrGlobalCandidate() const {
762763
Printf(
763764
"%p is located %zd bytes %s a %zd-byte global variable "
764765
"%s [%p,%p) in %s\n",
765-
untagged_addr,
766+
(void *)untagged_addr,
766767
candidate.after ? untagged_addr - (info.start + info.size)
767768
: info.start - untagged_addr,
768769
candidate.after ? "after" : "before", info.size, info.name,
769-
info.start, info.start + info.size, module_name);
770+
(void *)info.start, (void *)(info.start + info.size), module_name);
770771
} else {
771772
uptr size = GetGlobalSizeFromDescriptor(candidate.untagged_addr);
772773
if (size == 0)
773774
// We couldn't find the size of the global from the descriptors.
774775
Printf(
775776
"%p is located %s a global variable in "
776777
"\n #0 0x%x (%s+0x%x)\n",
777-
untagged_addr, candidate.after ? "after" : "before",
778-
candidate.untagged_addr, module_name, module_address);
778+
(void *)untagged_addr, candidate.after ? "after" : "before",
779+
(void *)candidate.untagged_addr, module_name, (u32)module_address);
779780
else
780781
Printf(
781782
"%p is located %s a %zd-byte global variable in "
782783
"\n #0 0x%x (%s+0x%x)\n",
783-
untagged_addr, candidate.after ? "after" : "before", size,
784-
candidate.untagged_addr, module_name, module_address);
784+
(void *)untagged_addr, candidate.after ? "after" : "before", size,
785+
(void *)candidate.untagged_addr, module_name, (u32)module_address);
785786
}
786787
Printf("%s", d.Default());
787788
}
@@ -792,8 +793,8 @@ void BaseReport::PrintAddressDescription() const {
792793
int num_descriptions_printed = 0;
793794

794795
if (MemIsShadow(untagged_addr)) {
795-
Printf("%s%p is HWAsan shadow memory.\n%s", d.Location(), untagged_addr,
796-
d.Default());
796+
Printf("%s%p is HWAsan shadow memory.\n%s", d.Location(),
797+
(void *)untagged_addr, d.Default());
797798
return;
798799
}
799800

@@ -802,7 +803,7 @@ void BaseReport::PrintAddressDescription() const {
802803
Printf(
803804
"%s[%p,%p) is a %s %s heap chunk; "
804805
"size: %zd offset: %zd\n%s",
805-
d.Location(), heap.begin, heap.begin + heap.size,
806+
d.Location(), (void *)heap.begin, (void *)(heap.begin + heap.size),
806807
heap.from_small_heap ? "small" : "large",
807808
heap.is_allocated ? "allocated" : "unallocated", heap.size,
808809
untagged_addr - heap.begin, d.Default());
@@ -821,8 +822,8 @@ void BaseReport::PrintAddressDescription() const {
821822
Printf("%s", d.Error());
822823
Printf("\nCause: stack tag-mismatch\n");
823824
Printf("%s", d.Location());
824-
Printf("Address %p is located in stack of thread T%zd\n", untagged_addr,
825-
sa.thread_id());
825+
Printf("Address %p is located in stack of thread T%zd\n",
826+
(void *)untagged_addr, (ssize)sa.thread_id());
826827
Printf("%s", d.Default());
827828
announce_by_id(sa.thread_id());
828829
PrintStackAllocations(sa.get(), ptr_tag, untagged_addr);
@@ -842,9 +843,9 @@ void BaseReport::PrintAddressDescription() const {
842843
Printf("\nCause: use-after-free\n");
843844
Printf("%s", d.Location());
844845
Printf("%p is located %zd bytes inside a %zd-byte region [%p,%p)\n",
845-
untagged_addr, untagged_addr - UntagAddr(har.tagged_addr),
846-
har.requested_size, UntagAddr(har.tagged_addr),
847-
UntagAddr(har.tagged_addr) + har.requested_size);
846+
(void *)untagged_addr, untagged_addr - UntagAddr(har.tagged_addr),
847+
(ssize)har.requested_size, UntagAddr(har.tagged_addr),
848+
(void *)(UntagAddr(har.tagged_addr) + har.requested_size));
848849
Printf("%s", d.Allocation());
849850
Printf("freed by thread T%u here:\n", ha.free_thread_id);
850851
Printf("%s", d.Default());
@@ -858,7 +859,7 @@ void BaseReport::PrintAddressDescription() const {
858859
// Print a developer note: the index of this heap object
859860
// in the thread's deallocation ring buffer.
860861
Printf("hwasan_dev_note_heap_rb_distance: %zd %zd\n", ha.ring_index + 1,
861-
flags()->heap_history_size);
862+
(ssize)flags()->heap_history_size);
862863
Printf("hwasan_dev_note_num_matching_addrs: %zd\n", ha.num_matching_addrs);
863864
Printf("hwasan_dev_note_num_matching_addrs_4b: %zd\n",
864865
ha.num_matching_addrs_4b);
@@ -915,10 +916,11 @@ InvalidFreeReport::~InvalidFreeReport() {
915916
const Thread *thread = GetCurrentThread();
916917
if (thread) {
917918
Report("ERROR: %s: %s on address %p at pc %p on thread T%zd\n",
918-
SanitizerToolName, bug_type, untagged_addr, pc, thread->unique_id());
919+
SanitizerToolName, bug_type, (void *)untagged_addr, (void *)pc,
920+
(ssize)thread->unique_id());
919921
} else {
920922
Report("ERROR: %s: %s on address %p at pc %p on unknown thread\n",
921-
SanitizerToolName, bug_type, untagged_addr, pc);
923+
SanitizerToolName, bug_type, (void *)untagged_addr, (void *)pc);
922924
}
923925
Printf("%s", d.Access());
924926
if (shadow.addr) {
@@ -967,7 +969,8 @@ TailOverwrittenReport::~TailOverwrittenReport() {
967969
Printf("%s", d.Error());
968970
const char *bug_type = "allocation-tail-overwritten";
969971
Report("ERROR: %s: %s; heap object [%p,%p) of size %zd\n", SanitizerToolName,
970-
bug_type, untagged_addr, untagged_addr + orig_size, orig_size);
972+
bug_type, (void *)untagged_addr, (void *)(untagged_addr + orig_size),
973+
orig_size);
971974
Printf("\n%s", d.Default());
972975
Printf(
973976
"Stack of invalid access unknown. Issue detected at deallocation "
@@ -1037,7 +1040,7 @@ TagMismatchReport::~TagMismatchReport() {
10371040
uptr pc = GetTopPc(stack);
10381041
Printf("%s", d.Error());
10391042
Report("ERROR: %s: %s on address %p at pc %p\n", SanitizerToolName, bug_type,
1040-
untagged_addr, pc);
1043+
(void *)untagged_addr, (void *)pc);
10411044

10421045
Thread *t = GetCurrentThread();
10431046

@@ -1049,12 +1052,12 @@ TagMismatchReport::~TagMismatchReport() {
10491052
GetShortTagCopy(MemToShadow(untagged_addr + mismatch_offset));
10501053
Printf(
10511054
"%s of size %zu at %p tags: %02x/%02x(%02x) (ptr/mem) in thread T%zd\n",
1052-
is_store ? "WRITE" : "READ", access_size, untagged_addr, ptr_tag,
1053-
mem_tag, short_tag, t->unique_id());
1055+
is_store ? "WRITE" : "READ", access_size, (void *)untagged_addr,
1056+
ptr_tag, mem_tag, short_tag, (ssize)t->unique_id());
10541057
} else {
10551058
Printf("%s of size %zu at %p tags: %02x/%02x (ptr/mem) in thread T%zd\n",
1056-
is_store ? "WRITE" : "READ", access_size, untagged_addr, ptr_tag,
1057-
mem_tag, t->unique_id());
1059+
is_store ? "WRITE" : "READ", access_size, (void *)untagged_addr,
1060+
ptr_tag, mem_tag, (ssize)t->unique_id());
10581061
}
10591062
if (mismatch_offset)
10601063
Printf("Invalid access starting at offset %zu\n", mismatch_offset);
@@ -1093,7 +1096,7 @@ void ReportTagMismatch(StackTrace *stack, uptr tagged_addr, uptr access_size,
10931096
// See the frame breakdown defined in __hwasan_tag_mismatch (from
10941097
// hwasan_tag_mismatch_{aarch64,riscv64}.S).
10951098
void ReportRegisters(const uptr *frame, uptr pc) {
1096-
Printf("\nRegisters where the failure occurred (pc %p):\n", pc);
1099+
Printf("\nRegisters where the failure occurred (pc %p):\n", (void *)pc);
10971100

10981101
// We explicitly print a single line (4 registers/line) each iteration to
10991102
// reduce the amount of logcat error messages printed. Each Printf() will

compiler-rt/lib/hwasan/hwasan_thread.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ void Thread::Destroy() {
120120
}
121121

122122
void Thread::Print(const char *Prefix) {
123-
Printf("%sT%zd %p stack: [%p,%p) sz: %zd tls: [%p,%p)\n", Prefix, unique_id_,
124-
(void *)this, stack_bottom(), stack_top(),
125-
stack_top() - stack_bottom(), tls_begin(), tls_end());
123+
Printf("%sT%zd %p stack: [%p,%p) sz: %zd tls: [%p,%p)\n", Prefix,
124+
(ssize)unique_id_, (void *)this, (void *)stack_bottom(),
125+
(void *)stack_top(), stack_top() - stack_bottom(), (void *)tls_begin(),
126+
(void *)tls_end());
126127
}
127128

128129
static u32 xorshift(u32 state) {

compiler-rt/lib/lsan/lsan_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ static bool ReportUnsuspendedThreads(
805805
succeded = false;
806806
Report(
807807
"Running thread %zu was not suspended. False leaks are possible.\n",
808-
os_id);
808+
(usize)os_id);
809809
}
810810
}
811811
return succeded;

compiler-rt/lib/memprof/memprof_shadow_setup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static void ProtectGap(uptr addr, uptr size) {
2929
Printf("protect_shadow_gap=0:"
3030
" not protecting shadow gap, allocating gap's shadow\n"
3131
"|| `[%p, %p]` || ShadowGap's shadow ||\n",
32-
GapShadowBeg, GapShadowEnd);
32+
(void *)GapShadowBeg, (void *)GapShadowEnd);
3333
ReserveShadowMemoryRange(GapShadowBeg, GapShadowEnd,
3434
"unprotected gap shadow");
3535
return;

compiler-rt/lib/xray/xray_init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ __xray_register_sleds(const XRaySledEntry *SledsBegin,
105105
}
106106

107107
if (Verbosity())
108-
Report("Registering %d new functions!\n", SledMap.Functions);
108+
Report("Registering %d new functions!\n", (int)SledMap.Functions);
109109

110110
{
111111
SpinMutexLock Guard(&XRayInstrMapMutex);

compiler-rt/lib/xray/xray_interface.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ XRayPatchingStatus controlPatchingObjectUnchecked(bool Enable, int32_t ObjId) {
306306
return XRayPatchingStatus::NOT_INITIALIZED;
307307

308308
if (Verbosity())
309-
Report("Patching object %d with %d functions.\n", ObjId, InstrMap.Entries);
309+
Report("Patching object %d with %d functions.\n", ObjId,
310+
(int)InstrMap.Entries);
310311

311312
// Check if the corresponding DSO has been unloaded.
312313
if (!InstrMap.Loaded) {

0 commit comments

Comments
 (0)