[compiler-rt] r254625 - [PGO] Introduce error report macro in profile-rt

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 3 10:31:59 PST 2015


Author: davidxl
Date: Thu Dec  3 12:31:59 2015
New Revision: 254625

URL: http://llvm.org/viewvc/llvm-project?rev=254625&view=rev
Log:
[PGO] Introduce error report macro in profile-rt

Also added a test case for runtime error reporting.


Added:
    compiler-rt/trunk/test/profile/instrprof-error.c
Modified:
    compiler-rt/trunk/lib/profile/InstrProfiling.h
    compiler-rt/trunk/lib/profile/InstrProfilingFile.c

Modified: compiler-rt/trunk/lib/profile/InstrProfiling.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.h?rev=254625&r1=254624&r2=254625&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfiling.h (original)
+++ compiler-rt/trunk/lib/profile/InstrProfiling.h Thu Dec  3 12:31:59 2015
@@ -163,4 +163,8 @@ uint64_t __llvm_profile_get_magic(void);
 /*! \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_ */

Modified: compiler-rt/trunk/lib/profile/InstrProfilingFile.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingFile.c?rev=254625&r1=254624&r2=254625&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingFile.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingFile.c Thu Dec  3 12:31:59 2015
@@ -193,13 +193,15 @@ int __llvm_profile_write_file(void) {
   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;
 }

Added: compiler-rt/trunk/test/profile/instrprof-error.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/instrprof-error.c?rev=254625&view=auto
==============================================================================
--- compiler-rt/trunk/test/profile/instrprof-error.c (added)
+++ compiler-rt/trunk/test/profile/instrprof-error.c Thu Dec  3 12:31:59 2015
@@ -0,0 +1,12 @@
+// RUN: %clang_profgen -o %t -O3 %s
+// RUN: touch %t.profraw
+// RUN: chmod -w %t.profraw
+// RUN: LLVM_PROFILE_FILE=%t.profraw LLVM_PROFILE_VERBOSE_ERRORS=1 %run %t 1 2>&1 | FileCheck %s
+// RUN: chmod +w %t.profraw
+
+int main(int argc, const char *argv[]) {
+  if (argc < 2)
+    return 1;
+  return 0;
+}
+// CHECK: LLVM Profile: Failed to write file 




More information about the llvm-commits mailing list