[PGO] Introduce error report macro in profile-rt
Also added a test case for runtime error reporting.
llvm-svn: 254625
diff --git a/compiler-rt/lib/profile/InstrProfiling.h b/compiler-rt/lib/profile/InstrProfiling.h
index 7ee41c3..0aa24071 100644
--- a/compiler-rt/lib/profile/InstrProfiling.h
+++ b/compiler-rt/lib/profile/InstrProfiling.h
@@ -163,4 +163,8 @@
/*! \brief Get the version of the file format. */
uint64_t __llvm_profile_get_version(void);
+#define PROF_ERR(Format, ...) \
+ if (getenv("LLVM_PROFILE_VERBOSE_ERRORS")) \
+ fprintf(stderr, Format, __VA_ARGS__ );
+
#endif /* PROFILE_INSTRPROFILING_H_ */
diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c
index 5663bab..8e9d2da 100644
--- a/compiler-rt/lib/profile/InstrProfilingFile.c
+++ b/compiler-rt/lib/profile/InstrProfilingFile.c
@@ -193,13 +193,15 @@
int rc;
/* Check the filename. */
- if (!__llvm_profile_CurrentFilename)
+ if (!__llvm_profile_CurrentFilename) {
+ PROF_ERR("LLVM Profile: Failed to write file : %s\n", "Filename not set");
return -1;
+ }
/* Write the file. */
rc = writeFileWithName(__llvm_profile_CurrentFilename);
- if (rc && getenv("LLVM_PROFILE_VERBOSE_ERRORS"))
- fprintf(stderr, "LLVM Profile: Failed to write file \"%s\": %s\n",
+ if (rc)
+ PROF_ERR("LLVM Profile: Failed to write file \"%s\": %s\n",
__llvm_profile_CurrentFilename, strerror(errno));
return rc;
}