Skip to content

Commit aabe1b6

Browse files
committed
rtlib: fix gcc warnings in profiler report
- choose a suitable 64-bit decimal printf specifier - choose a sutiable size_t printf specifier
1 parent c3eb081 commit aabe1b6

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

src/rtlib/profile_calls.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,21 @@
1818

1919
#ifdef HOST_WIN32
2020
#include <windows.h>
21+
#include <inttypes.h>
2122
#endif
2223
#include <time.h>
2324

25+
/* choose a suitable 64-bit decimal printf specifier */
26+
#if !defined(fmtlld)
27+
#if defined(PRId64)
28+
#define fmtlld PRId64
29+
#elif defined(FB_LL_FMTMOD)
30+
#define fmtlld "%12" FB_LL_FMTMOD "d"
31+
#else
32+
#define fmtlld "%12lld"
33+
#endif
34+
#endif
35+
2436
/* procs */
2537

2638
/* extra information about procinfo entry */
@@ -499,7 +511,7 @@ static void hProfilerReportCallsProc (
499511
pad_spaces( f, len );
500512

501513
if( (prof->global->options & PROFILE_OPTION_HIDE_COUNTS) == 0 ) {
502-
len = 14 - fprintf( f, "%12lld", parent_proc->local_count );
514+
len = 14 - fprintf( f, fmtlld, parent_proc->local_count );
503515
pad_spaces( f, len );
504516
}
505517

@@ -521,7 +533,7 @@ static void hProfilerReportCallsProc (
521533
pad_spaces( f, len );
522534

523535
if( (prof->global->options & PROFILE_OPTION_HIDE_COUNTS) == 0 ) {
524-
len = 14 - fprintf( f, "%12lld", proc->local_count );
536+
len = 14 - fprintf( f, fmtlld, proc->local_count );
525537
pad_spaces( f, len );
526538
}
527539

@@ -656,7 +668,7 @@ static void hProfilerReportCallsGlobals (
656668
pad_spaces( f, len );
657669

658670
if( (prof->global->options & PROFILE_OPTION_HIDE_COUNTS) == 0 ) {
659-
len = 14 - fprintf( f, "%12lld", proc->local_count );
671+
len = 14 - fprintf( f, fmtlld, proc->local_count );
660672
pad_spaces( f, len );
661673
}
662674

@@ -845,7 +857,7 @@ static void hProfilerReportRawList (
845857
pad_spaces( f, len );
846858

847859
if( (prof->global->options & PROFILE_OPTION_HIDE_COUNTS) == 0 ) {
848-
len = 14 - fprintf( f, "%12lld", proc->local_count );
860+
len = 14 - fprintf( f, fmtlld, proc->local_count );
849861
pad_spaces( f, len );
850862
}
851863

@@ -888,7 +900,7 @@ static void hProfilerReportRawDataProc (
888900
pad_spaces( f, len );
889901

890902
if( (prof->global->options & PROFILE_OPTION_HIDE_COUNTS) == 0 ) {
891-
len = 14 - fprintf( f, "%12lld", proc->local_count );
903+
len = 14 - fprintf( f, fmtlld, proc->local_count );
892904
pad_spaces( f, len );
893905
}
894906

src/rtlib/profile_cycles.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,23 @@
1616
#include <windows.h>
1717
#endif
1818

19+
/* choose a suitable size_t printf specifier */
20+
#if !defined(fmtsizet)
21+
#if defined(HOST_CYGWIN)
22+
#define fmtsizet "%18Iu"
23+
#elif defined(HOST_WIN32)
24+
#if defined(_UCRT) || __USE_MINGW_ANSI_STDIO
25+
#define fmtsizet "%18zu"
26+
#else
27+
#define fmtsizet "%18Iu"
28+
#endif
29+
#else
30+
#define fmtsizet "%18zu"
31+
#endif
32+
#endif
33+
1934
/* profile section data */
20-
extern char __start_fb_profilecycledata;
35+
extern char __start_fb_profilecycledata[];
2136
extern char __stop_fb_profilecycledata;
2237

2338
/* profiler record ids - these indicate what the record is */
@@ -255,7 +270,7 @@ static void hProfilerReport (
255270
}
256271

257272
fprintf( f, " %s\n", rec->proc_name );
258-
fprintf( f, " %18zu %18zu %18zu\n",
273+
fprintf( f, " " fmtsizet " " fmtsizet " " fmtsizet "\n",
259274
rec->grand_total,
260275
rec->internal_total,
261276
rec->call_count
@@ -286,8 +301,8 @@ static void hProfilerWriteReport( FB_PROFILER_CYCLES *prof )
286301
fprintf( f, "Total program execution time: %5.4g seconds\n", fb_Timer() - prof->start_time );
287302
}
288303

289-
data = (unsigned char *)&__start_fb_profilecycledata;
290-
length = (ssize_t)&__stop_fb_profilecycledata - (ssize_t)&__start_fb_profilecycledata;
304+
data = (unsigned char *)&__start_fb_profilecycledata[0];
305+
length = (ssize_t)&__stop_fb_profilecycledata - (ssize_t)&__start_fb_profilecycledata[0];
291306

292307
count = hProfilerCountProcs( data, length );
293308
if( count ) {

0 commit comments

Comments
 (0)