[llvm-commits] [compiler-rt] r157559 - /compiler-rt/trunk/lib/profile/GCDAProfiling.c
Bill Wendling
isanbard at gmail.com
Sun May 27 19:34:34 PDT 2012
Author: void
Date: Sun May 27 21:34:34 2012
New Revision: 157559
URL: http://llvm.org/viewvc/llvm-project?rev=157559&view=rev
Log:
Sync with old GCOV runtime library's file.
Modified:
compiler-rt/trunk/lib/profile/GCDAProfiling.c
Modified: compiler-rt/trunk/lib/profile/GCDAProfiling.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/GCDAProfiling.c?rev=157559&r1=157558&r2=157559&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/GCDAProfiling.c (original)
+++ compiler-rt/trunk/lib/profile/GCDAProfiling.c Sun May 27 21:34:34 2012
@@ -49,10 +49,8 @@
}
static void write_int64(uint64_t i) {
- uint32_t lo, hi;
- lo = i >> 0;
- hi = i >> 32;
-
+ uint32_t lo = i >> 0;
+ uint32_t hi = i >> 32;
write_int32(lo);
write_int32(hi);
}
@@ -91,17 +89,16 @@
int i, e;
for (i = 1, e = strlen(filename); i != e; ++i) {
- if (filename[i] == '/') {
- pathname = malloc(i + 1);
- strncpy(pathname, filename, i);
- pathname[i] = '\0';
+ if (filename[i] != '/') continue;
+ pathname = malloc(i + 1);
+ strncpy(pathname, filename, i);
+ pathname[i] = '\0';
#ifdef _WIN32
- _mkdir(pathname);
+ _mkdir(pathname);
#else
- mkdir(pathname, 0750); /* some of these will fail, ignore it. */
+ mkdir(pathname, 0750); /* some of these will fail, ignore it. */
#endif
- free(pathname);
- }
+ free(pathname);
}
}
@@ -117,7 +114,18 @@
char *filename;
filename = mangle_filename(orig_filename);
recursive_mkdir(filename);
- output_file = fopen(filename, "wb");
+ output_file = fopen(filename, "w+b");
+
+ if (!output_file) {
+ const char *cptr = strrchr(orig_filename, '/');
+ output_file = fopen(cptr ? cptr + 1 : orig_filename, "w+b");
+
+ if (!output_file) {
+ fprintf(stderr, "profiling:%s: cannot open\n",
+ cptr ? cptr + 1 : orig_filename);
+ return;
+ }
+ }
/* gcda file, version 404*, stamp LLVM. */
#ifdef __APPLE__
@@ -161,6 +169,7 @@
#ifdef DEBUG_GCDAPROFILING
printf("llvmgcda: function id=%x\n", ident);
#endif
+ if (!output_file) return;
/* function tag */
fwrite("\0\0\0\1", 4, 1, output_file);
@@ -173,23 +182,24 @@
void llvm_gcda_emit_arcs(uint32_t num_counters, uint64_t *counters) {
uint32_t i;
- /* counter #1 (arcs) tag */
+
+ /* Counter #1 (arcs) tag */
+ if (!output_file) return;
fwrite("\0\0\xa1\1", 4, 1, output_file);
write_int32(num_counters * 2);
- for (i = 0; i < num_counters; ++i) {
+ for (i = 0; i < num_counters; ++i)
write_int64(counters[i]);
- }
#ifdef DEBUG_GCDAPROFILING
printf("llvmgcda: %u arcs\n", num_counters);
- for (i = 0; i < num_counters; ++i) {
+ for (i = 0; i < num_counters; ++i)
printf("llvmgcda: %llu\n", (unsigned long long)counters[i]);
- }
#endif
}
void llvm_gcda_end_file() {
/* Write out EOF record. */
+ if (!output_file) return;
fwrite("\0\0\0\0\0\0\0\0", 8, 1, output_file);
fclose(output_file);
output_file = NULL;
More information about the llvm-commits
mailing list