@@ -74,53 +74,85 @@ static cl::opt<unsigned> StaticFuncStripDirNamePrefix(
7474 cl::desc(" Strip specified level of directory name from source path in "
7575 " the profile counter name for static functions." ));
7676
77- static std::string getInstrProfErrString (instrprof_error Err) {
77+ static std::string getInstrProfErrString (instrprof_error Err,
78+ const std::string &ErrMsg = " " ) {
79+ std::string Msg;
80+ raw_string_ostream OS (Msg);
81+
7882 switch (Err) {
7983 case instrprof_error::success:
80- return " success" ;
84+ OS << " success" ;
85+ break ;
8186 case instrprof_error::eof:
82- return " end of File" ;
87+ OS << " end of File" ;
88+ break ;
8389 case instrprof_error::unrecognized_format:
84- return " unrecognized instrumentation profile encoding format" ;
90+ OS << " unrecognized instrumentation profile encoding format" ;
91+ break ;
8592 case instrprof_error::bad_magic:
86- return " invalid instrumentation profile data (bad magic)" ;
93+ OS << " invalid instrumentation profile data (bad magic)" ;
94+ break ;
8795 case instrprof_error::bad_header:
88- return " invalid instrumentation profile data (file header is corrupt)" ;
96+ OS << " invalid instrumentation profile data (file header is corrupt)" ;
97+ break ;
8998 case instrprof_error::unsupported_version:
90- return " unsupported instrumentation profile format version" ;
99+ OS << " unsupported instrumentation profile format version" ;
100+ break ;
91101 case instrprof_error::unsupported_hash_type:
92- return " unsupported instrumentation profile hash type" ;
102+ OS << " unsupported instrumentation profile hash type" ;
103+ break ;
93104 case instrprof_error::too_large:
94- return " too much profile data" ;
105+ OS << " too much profile data" ;
106+ break ;
95107 case instrprof_error::truncated:
96- return " truncated profile data" ;
108+ OS << " truncated profile data" ;
109+ break ;
97110 case instrprof_error::malformed:
98- return " malformed instrumentation profile data" ;
111+ OS << " malformed instrumentation profile data" ;
112+ break ;
99113 case instrprof_error::invalid_prof:
100- return " invalid profile created. Please file a bug "
101- " at: " BUG_REPORT_URL
102- " and include the profraw files that caused this error." ;
114+ OS << " invalid profile created. Please file a bug "
115+ " at: " BUG_REPORT_URL
116+ " and include the profraw files that caused this error." ;
117+ break ;
103118 case instrprof_error::unknown_function:
104- return " no profile data available for function" ;
119+ OS << " no profile data available for function" ;
120+ break ;
105121 case instrprof_error::hash_mismatch:
106- return " function control flow change detected (hash mismatch)" ;
122+ OS << " function control flow change detected (hash mismatch)" ;
123+ break ;
107124 case instrprof_error::count_mismatch:
108- return " function basic block count change detected (counter mismatch)" ;
125+ OS << " function basic block count change detected (counter mismatch)" ;
126+ break ;
109127 case instrprof_error::counter_overflow:
110- return " counter overflow" ;
128+ OS << " counter overflow" ;
129+ break ;
111130 case instrprof_error::value_site_count_mismatch:
112- return " function value site count change detected (counter mismatch)" ;
131+ OS << " function value site count change detected (counter mismatch)" ;
132+ break ;
113133 case instrprof_error::compress_failed:
114- return " failed to compress data (zlib)" ;
134+ OS << " failed to compress data (zlib)" ;
135+ break ;
115136 case instrprof_error::uncompress_failed:
116- return " failed to uncompress data (zlib)" ;
137+ OS << " failed to uncompress data (zlib)" ;
138+ break ;
117139 case instrprof_error::empty_raw_profile:
118- return " empty raw profile file" ;
140+ OS << " empty raw profile file" ;
141+ break ;
119142 case instrprof_error::zlib_unavailable:
120- return " profile uses zlib compression but the profile reader was built "
121- " without zlib support" ;
143+ OS << " profile uses zlib compression but the profile reader was built "
144+ " without zlib support" ;
145+ break ;
146+ default :
147+ llvm_unreachable (" A value of instrprof_error has no message." );
148+ break ;
122149 }
123- llvm_unreachable (" A value of instrprof_error has no message." );
150+
151+ // If optional error message is not empty, append it to the message.
152+ if (!ErrMsg.empty ())
153+ OS << " : '" << ErrMsg << " '" ;
154+
155+ return OS.str ();
124156}
125157
126158namespace {
@@ -217,7 +249,7 @@ void SoftInstrProfErrors::addError(instrprof_error IE) {
217249}
218250
219251std::string InstrProfError::message () const {
220- return getInstrProfErrString (Err);
252+ return getInstrProfErrString (Err, Msg );
221253}
222254
223255char InstrProfError::ID = 0 ;
@@ -878,18 +910,23 @@ static std::unique_ptr<ValueProfData> allocValueProfData(uint32_t TotalSize) {
878910
879911Error ValueProfData::checkIntegrity () {
880912 if (NumValueKinds > IPVK_Last + 1 )
881- return make_error<InstrProfError>(instrprof_error::malformed);
882- // Total size needs to be mulltiple of quadword size.
913+ return make_error<InstrProfError>(
914+ instrprof_error::malformed, " number of value profile kinds is invalid" );
915+ // Total size needs to be multiple of quadword size.
883916 if (TotalSize % sizeof (uint64_t ))
884- return make_error<InstrProfError>(instrprof_error::malformed);
917+ return make_error<InstrProfError>(
918+ instrprof_error::malformed, " total size is not multiples of quardword" );
885919
886920 ValueProfRecord *VR = getFirstValueProfRecord (this );
887921 for (uint32_t K = 0 ; K < this ->NumValueKinds ; K++) {
888922 if (VR->Kind > IPVK_Last)
889- return make_error<InstrProfError>(instrprof_error::malformed);
923+ return make_error<InstrProfError>(instrprof_error::malformed,
924+ " value kind is invalid" );
890925 VR = getValueProfRecordNext (VR);
891926 if ((char *)VR - (char *)this > (ptrdiff_t )TotalSize)
892- return make_error<InstrProfError>(instrprof_error::malformed);
927+ return make_error<InstrProfError>(
928+ instrprof_error::malformed,
929+ " value profile address is greater than total size" );
893930 }
894931 return Error::success ();
895932}
0 commit comments