[llvm] 126e761 - [compiler-rt] Fix diagnostic in InstrProfError

Gulfem Savrun Yeniceri via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 9 12:31:32 PST 2021


Author: Gulfem Savrun Yeniceri
Date: 2021-11-09T20:30:03Z
New Revision: 126e7611c70ca41782aa851c2bec132607eb8127

URL: https://github.com/llvm/llvm-project/commit/126e7611c70ca41782aa851c2bec132607eb8127
DIFF: https://github.com/llvm/llvm-project/commit/126e7611c70ca41782aa851c2bec132607eb8127.diff

LOG: [compiler-rt] Fix diagnostic in InstrProfError

This patch fixes some issues introduced in
https://reviews.llvm.org/D108942:

1) Remove the default label to fix the bots that use
-Werror,-Wcovered-switch-default
2) Modify the malformed test to fix the bots that are
built without zlib support
3) Modify some error messages in malformed profiles

Added: 
    

Modified: 
    llvm/lib/ProfileData/InstrProf.cpp
    llvm/lib/ProfileData/InstrProfReader.cpp
    llvm/test/tools/llvm-profdata/large-binary-id-size.test
    llvm/test/tools/llvm-profdata/malformed-not-space-for-another-header.test
    llvm/test/tools/llvm-profdata/malformed-num-counters-zero.test
    llvm/test/tools/llvm-profdata/malformed-ptr-to-counter-array.test

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index 6bd02abfe1e5d..1168ad27fe52d 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -147,7 +147,7 @@ static std::string getInstrProfErrString(instrprof_error Err,
 
   // If optional error message is not empty, append it to the message.
   if (!ErrMsg.empty())
-    OS << ": '" << ErrMsg << "'";
+    OS << ": " << ErrMsg;
 
   return OS.str();
 }

diff  --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp
index 4fd878a2230d1..b4e8025dbef92 100644
--- a/llvm/lib/ProfileData/InstrProfReader.cpp
+++ b/llvm/lib/ProfileData/InstrProfReader.cpp
@@ -463,22 +463,21 @@ Error RawInstrProfReader<IntPtrT>::readRawCounts(
   if (CounterOffset < 0)
     return error(
         instrprof_error::malformed,
-        ("counter offset(" + Twine(CounterOffset) + ")" + " is < 0").str());
+        ("counter offset " + Twine(CounterOffset) + " is negative").str());
 
   if (CounterOffset > MaxNumCounters)
     return error(instrprof_error::malformed,
-                 ("counter offset(" + Twine(CounterOffset) + ")" + " > " +
-                  "max number of counters(" + Twine((uint32_t)MaxNumCounters) +
-                  ")")
+                 ("counter offset " + Twine(CounterOffset) +
+                  " is greater than the maximum number of counters " +
+                  Twine((uint32_t)MaxNumCounters))
                      .str());
 
   if (((uint32_t)CounterOffset + NumCounters) > (uint32_t)MaxNumCounters)
     return error(instrprof_error::malformed,
-                 ("number of counters is out of bounds(counter offset(" +
-                  Twine((uint32_t)CounterOffset) + ") + " +
-                  "number of counters(" + Twine(NumCounters) + ") > " +
-                  "max number of counters(" + Twine((uint32_t)MaxNumCounters) +
-                  "))")
+                 ("number of counters " +
+                  Twine(((uint32_t)CounterOffset + NumCounters)) +
+                  " is greater than the maximum number of counters " +
+                  Twine((uint32_t)MaxNumCounters))
                      .str());
 
   auto RawCounts = makeArrayRef(getCounter(CounterOffset), NumCounters);

diff  --git a/llvm/test/tools/llvm-profdata/large-binary-id-size.test b/llvm/test/tools/llvm-profdata/large-binary-id-size.test
index 72612da47e835..2394431e94de4 100644
--- a/llvm/test/tools/llvm-profdata/large-binary-id-size.test
+++ b/llvm/test/tools/llvm-profdata/large-binary-id-size.test
@@ -17,4 +17,4 @@ RUN: printf '\0\1\2\3\4\5\6\7' >> %t.profraw
 RUN: printf '\0\1\2\3\0\0\0\0' >> %t.profraw
 
 // RUN: not llvm-profdata show --binary-ids  %t.profraw 2>&1 | FileCheck %s
-// CHECK: malformed instrumentation profile data: 'not enough data to read binary id data'
+// CHECK: malformed instrumentation profile data: not enough data to read binary id data

diff  --git a/llvm/test/tools/llvm-profdata/malformed-not-space-for-another-header.test b/llvm/test/tools/llvm-profdata/malformed-not-space-for-another-header.test
index 6ed3c0a3f047c..06f418d0235d2 100644
--- a/llvm/test/tools/llvm-profdata/malformed-not-space-for-another-header.test
+++ b/llvm/test/tools/llvm-profdata/malformed-not-space-for-another-header.test
@@ -11,16 +11,16 @@
 // INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)
 
 RUN: printf '\201rforpl\377' > %t.profraw
-RUN: printf '\x8\0\0\0\0\0\0\0' >> %t.profraw
+RUN: printf '\10\0\0\0\0\0\0\0' >> %t.profraw
 RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
 RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
 RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
 RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
 RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
-RUN: printf '\xe\0\0\0\0\0\0\0' >> %t.profraw
-RUN: printf '\xf8\xff\xff\xff\xff\xff\xff\xff' >> %t.profraw
-RUN: printf '\x89\x7a\x40\x00\x00\x00\x00\x00' >> %t.profraw
-RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
+RUN: printf '\10\0\0\0\0\0\0\0' >> %t.profraw
+RUN: printf '\0\0\4\0\1\0\0\0' >> %t.profraw
+RUN: printf '\0\0\4\0\2\0\0\0' >> %t.profraw
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
 
 // Data Section
 //
@@ -30,22 +30,18 @@ RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
 // #include "llvm/ProfileData/InstrProfData.inc"
 // };
 
-RUN: printf '\xfa\xd5\x8d\xe7\x36\x64\x95\xdb' >> %t.profraw // NameRef
-RUN: printf '\x18\0\0\0\0\0\0\0' >> %t.profraw               // FuncHash
-RUN: printf '\xf8\xff\xff\xff\xff\xff\xff\xff' >> %t.profraw // RelativeCounterPtr
-RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw                 // FunctionPointer
-RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw                 // Values
-RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw                 // NumCounters and NumValueSites
-
-// Counter section
+RUN: printf '\254\275\030\333\114\302\370\134' >> %t.profraw
+RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
+RUN: printf '\0\0\4\0\1\0\0\0' >> %t.profraw
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
 RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
 
-// Name section (Name section is 14 bytes and 2 bytes padding is added)
-RUN: printf '\x04\x0c\x78\xda\xcb\x4d\xcc\xcc' >> %t.profraw
-RUN: printf '\x03\x00\x04\x1b\x01\xa6\x00\x00' >> %t.profraw
+RUN: printf '\023\0\0\0\0\0\0\0' >> %t.profraw
+RUN: printf '\3\0foo\0\0\0' >> %t.profraw
 
 // Write some garbage data at the end so we get "not enough space for another header" message
 RUN: printf '\x03\x00\' >> %t.profraw
 
 RUN: not llvm-profdata show %t.profraw 2>&1 | FileCheck %s
-CHECK: malformed instrumentation profile data: 'not enough space for another header'
+CHECK: malformed instrumentation profile data: not enough space for another header

diff  --git a/llvm/test/tools/llvm-profdata/malformed-num-counters-zero.test b/llvm/test/tools/llvm-profdata/malformed-num-counters-zero.test
index ab63639fddc4e..b718cf0fd8e97 100644
--- a/llvm/test/tools/llvm-profdata/malformed-num-counters-zero.test
+++ b/llvm/test/tools/llvm-profdata/malformed-num-counters-zero.test
@@ -11,16 +11,16 @@
 // INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)
 
 RUN: printf '\201rforpl\377' > %t.profraw
-RUN: printf '\x8\0\0\0\0\0\0\0' >> %t.profraw
+RUN: printf '\10\0\0\0\0\0\0\0' >> %t.profraw
 RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
 RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
 RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
 RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
 RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
-RUN: printf '\xe\0\0\0\0\0\0\0' >> %t.profraw
-RUN: printf '\xf8\xff\xff\xff\xff\xff\xff\xff' >> %t.profraw
-RUN: printf '\x89\x7a\x40\x00\x00\x00\x00\x00' >> %t.profraw
-RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
+RUN: printf '\10\0\0\0\0\0\0\0' >> %t.profraw
+RUN: printf '\0\0\4\0\1\0\0\0' >> %t.profraw
+RUN: printf '\0\0\4\0\2\0\0\0' >> %t.profraw
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
 
 // Data Section
 //
@@ -30,20 +30,16 @@ RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
 // #include "llvm/ProfileData/InstrProfData.inc"
 // };
 
-RUN: printf '\xfa\xd5\x8d\xe7\x36\x64\x95\xdb' >> %t.profraw // NameRef
-RUN: printf '\x18\0\0\0\0\0\0\0' >> %t.profraw               // FuncHash
-RUN: printf '\xf8\xff\xff\xff\xff\xff\xff\xff' >> %t.profraw // RelativeCounterPtr
-RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw                 // FunctionPointer
-RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw                 // Values
-// Make NumCounters = 0 so that we get "number of counters is zero" error message
-RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw                 // NumCounters and NumValueSites
-
-// Counter section
+RUN: printf '\254\275\030\333\114\302\370\134' >> %t.profraw
 RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
+RUN: printf '\0\0\4\0\1\0\0\0' >> %t.profraw
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
+// Make NumCounters = 0 so that we get "number of counters is zero" error message
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
 
-// Name section (Name section is 14 bytes and 2 bytes padding is added)
-RUN: printf '\x04\x0c\x78\xda\xcb\x4d\xcc\xcc' >> %t.profraw
-RUN: printf '\x03\x00\x04\x1b\x01\xa6\x00\x00' >> %t.profraw
+RUN: printf '\023\0\0\0\0\0\0\0' >> %t.profraw
+RUN: printf '\3\0foo\0\0\0' >> %t.profraw
 
 RUN: not llvm-profdata show %t.profraw 2>&1 | FileCheck %s
-CHECK: malformed instrumentation profile data: 'number of counters is zero'
+CHECK: malformed instrumentation profile data: number of counters is zero

diff  --git a/llvm/test/tools/llvm-profdata/malformed-ptr-to-counter-array.test b/llvm/test/tools/llvm-profdata/malformed-ptr-to-counter-array.test
index 8667f727d0cc9..c7a8fd4db6d65 100644
--- a/llvm/test/tools/llvm-profdata/malformed-ptr-to-counter-array.test
+++ b/llvm/test/tools/llvm-profdata/malformed-ptr-to-counter-array.test
@@ -53,5 +53,5 @@ RUN: printf '\101\0\0\0\0\0\0\0' >> %t.profraw
 RUN: printf '\3\0bar\0\0\0' >> %t.profraw
 
 RUN: not llvm-profdata merge -o /dev/null %t.profraw 2>&1 | FileCheck %s
-CHECK: warning: {{.+}}: malformed instrumentation profile data: 'number of counters is out of bounds(counter offset(1) + number of counters(2) > max number of counters(2))'
+CHECK: warning: {{.+}}: malformed instrumentation profile data: number of counters 3 is greater than the maximum number of counters 2
 CHECK: error: no profile can be merged


        


More information about the llvm-commits mailing list