summaryrefslogtreecommitdiff
path: root/lib/profile/InstrProfiling.c
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-03-21 00:27:50 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-03-21 00:27:50 +0000
commit3f566f25cda5e6bc31d53fbbffba41c7d8964ec5 (patch)
tree9e8edb3fe9da47a4c12e99d5d87ed08d529dc4e0 /lib/profile/InstrProfiling.c
parent44e4a744864074a30871290a67b11c4fee48c13a (diff)
PGO: Indicate errors in profile runtime API
Return 0 for success, non-0 for failure. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204415 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/profile/InstrProfiling.c')
-rw-r--r--lib/profile/InstrProfiling.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/profile/InstrProfiling.c b/lib/profile/InstrProfiling.c
index 45c824c84..61981b773 100644
--- a/lib/profile/InstrProfiling.c
+++ b/lib/profile/InstrProfiling.c
@@ -12,20 +12,27 @@
/* TODO: void __llvm_profile_get_size_for_buffer(void); */
-static void writeFunction(FILE *OutputFile, const __llvm_profile_data *Data) {
+static int writeFunction(FILE *OutputFile, const __llvm_profile_data *Data) {
/* TODO: Requires libc: break requirement by writing directly to a buffer
* instead of a FILE stream.
*/
uint32_t I;
for (I = 0; I < Data->NameSize; ++I)
- fputc(Data->Name[I], OutputFile);
- fprintf(OutputFile, "\n%" PRIu64 "\n%u\n", Data->FuncHash, Data->NumCounters);
+ if (fputc(Data->Name[I], OutputFile) != Data->Name[I])
+ return -1;
+ if (fprintf(OutputFile, "\n%" PRIu64 "\n%u\n", Data->FuncHash,
+ Data->NumCounters) < 0)
+ return -1;
for (I = 0; I < Data->NumCounters; ++I)
- fprintf(OutputFile, "%" PRIu64 "\n", Data->Counters[I]);
- fprintf(OutputFile, "\n");
+ if (fprintf(OutputFile, "%" PRIu64 "\n", Data->Counters[I]) < 0)
+ return -1;
+ if (fprintf(OutputFile, "\n") < 0)
+ return -1;
+
+ return 0;
}
-void __llvm_profile_write_buffer(FILE *OutputFile) {
+int __llvm_profile_write_buffer(FILE *OutputFile) {
/* TODO: Requires libc: break requirement by taking a char* buffer instead of
* a FILE stream.
*/
@@ -33,7 +40,10 @@ void __llvm_profile_write_buffer(FILE *OutputFile) {
for (I = __llvm_profile_data_begin(), E = __llvm_profile_data_end();
I != E; ++I)
- writeFunction(OutputFile, I);
+ if (writeFunction(OutputFile, I))
+ return -1;
+
+ return 0;
}
void __llvm_profile_reset_counters(void) {