]> granicus.if.org Git - llvm/commitdiff
[ProfData] Detect if zlib is available
authorDavid Blaikie <dblaikie@gmail.com>
Fri, 21 Jul 2017 21:41:15 +0000 (21:41 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Fri, 21 Jul 2017 21:41:15 +0000 (21:41 +0000)
As discussed on [1], if the profile is compressed and llvm-profdata is not built with zlib support, the error message is not informative. Give a better error message if zlib is not available.

[1] http://lists.llvm.org/pipermail/llvm-dev/2017-July/115571.html

Reviewers: davidxl, dblaikie

Differential Revision: https://reviews.llvm.org/D35586

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308789 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ProfileData/InstrProf.h
lib/ProfileData/InstrProf.cpp
test/tools/llvm-profdata/Inputs/compressed.profraw [new file with mode: 0644]
test/tools/llvm-profdata/nocompress.test [new file with mode: 0644]

index 772187f70153c35c7a833ec718825874f3754860..ac3f057ec2f900cf3e7f27e8390c26134b5996ed 100644 (file)
@@ -295,7 +295,8 @@ enum class instrprof_error {
   value_site_count_mismatch,
   compress_failed,
   uncompress_failed,
-  empty_raw_profile
+  empty_raw_profile,
+  zlib_unavailable
 };
 
 inline std::error_code make_error_code(instrprof_error E) {
index 48c1643cb13c8d96cdb7f6185948bf38d5e5d9a9..a732bedc6fa47c86880733f2f6bebe4f1596b635 100644 (file)
@@ -111,6 +111,8 @@ static std::string getInstrProfErrString(instrprof_error Err) {
     return "Failed to uncompress data (zlib)";
   case instrprof_error::empty_raw_profile:
     return "Empty raw profile file";
+  case instrprof_error::zlib_unavailable:
+    return "Profile uses zlib compression but the profile reader was built without zlib support";
   }
   llvm_unreachable("A value of instrprof_error has no message.");
 }
@@ -430,6 +432,9 @@ Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab) {
     SmallString<128> UncompressedNameStrings;
     StringRef NameStrings;
     if (isCompressed) {
+      if (!llvm::zlib::isAvailable())
+        return make_error<InstrProfError>(instrprof_error::zlib_unavailable);
+
       StringRef CompressedNameStrings(reinterpret_cast<const char *>(P),
                                       CompressedSize);
       if (Error E =
diff --git a/test/tools/llvm-profdata/Inputs/compressed.profraw b/test/tools/llvm-profdata/Inputs/compressed.profraw
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/tools/llvm-profdata/nocompress.test b/test/tools/llvm-profdata/nocompress.test
new file mode 100644 (file)
index 0000000..65db61d
--- /dev/null
@@ -0,0 +1,15 @@
+You need a checkout of clang with compiler-rt to generate the
+binary file here.  These shell commands can be used to regenerate
+it.
+$ SRC=path/to/llvm
+$ CFE=$SRC/tools/clang
+$ TESTDIR=$SRC/test/tools/llvm-profdata
+$ CFE_TESTDIR=$CFE/test/Profile
+$ clang -o a.out -fprofile-instr-generate $CFE_TESTDIR/c-general.c
+$ LLVM_PROFILE_FILE=$TESTDIR/Inputs/compressed.profraw ./a.out
+
+RUN: not llvm-profdata show %p/Inputs/compressed.profraw -o %t 2>&1 | FileCheck %s
+
+REQUIRES: nozlib
+
+CHECK: error: {{.*}} Profile uses zlib compression but the profile reader was built without zlib support