Skip to content

Commit 3b0a9e7

Browse files
committed
[profile] Move assertIsZero to InstrProfilingUtil.c
... and rename it to 'warnIfNonZero' to better-reflect what it actually does. The goal is to minimize the amount of logic that's conditionally compiled under '#if __APPLE__'.
1 parent 52c87e0 commit 3b0a9e7

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

compiler-rt/lib/profile/InstrProfilingFile.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,6 @@ static void truncateCurrentFile(void) {
428428

429429
// TODO: Move these functions into InstrProfilingPlatform* files.
430430
#if defined(__APPLE__)
431-
static void assertIsZero(int *i) {
432-
if (*i)
433-
PROF_WARN("Expected flag to be 0, but got: %d\n", *i);
434-
}
435-
436431
/* Write a partial profile to \p Filename, which is required to be backed by
437432
* the open file object \p File. */
438433
static int writeProfileWithFileObject(const char *Filename, FILE *File) {
@@ -495,7 +490,7 @@ static void initializeProfileForContinuousMode(void) {
495490

496491
/* Whether an exclusive lock on the profile must be dropped after init.
497492
* Use a cleanup to warn if the unlock does not occur. */
498-
COMPILER_RT_CLEANUP(assertIsZero) int ProfileRequiresUnlock = 0;
493+
COMPILER_RT_CLEANUP(warnIfNonZero) int ProfileRequiresUnlock = 0;
499494

500495
if (!doMerging()) {
501496
/* We are not merging profiles, so open the raw profile in append mode. */

compiler-rt/lib/profile/InstrProfilingUtil.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,8 @@ COMPILER_RT_VISIBILITY int lprofReleaseMemoryPagesToOS(uintptr_t Begin,
353353
}
354354
return 0;
355355
}
356+
357+
COMPILER_RT_VISIBILITY void warnIfNonZero(int *i) {
358+
if (*i)
359+
PROF_WARN("Expected flag to be 0, but got: %d\n", *i);
360+
}

compiler-rt/lib/profile/InstrProfilingUtil.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,7 @@ static inline size_t lprofRoundDownTo(size_t x, size_t boundary) {
8484

8585
int lprofReleaseMemoryPagesToOS(uintptr_t Begin, uintptr_t End);
8686

87+
/// Noisly warn if *i is non-zero. Intended for use with COMPILER_RT_CLEANUP.
88+
void warnIfNonZero(int *i);
89+
8790
#endif /* PROFILE_INSTRPROFILINGUTIL_H */

0 commit comments

Comments
 (0)