@@ -74,53 +74,85 @@ static cl::opt<unsigned> StaticFuncStripDirNamePrefix(
74
74
cl::desc(" Strip specified level of directory name from source path in "
75
75
" the profile counter name for static functions." ));
76
76
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
+
78
82
switch (Err) {
79
83
case instrprof_error::success:
80
- return " success" ;
84
+ OS << " success" ;
85
+ break ;
81
86
case instrprof_error::eof:
82
- return " end of File" ;
87
+ OS << " end of File" ;
88
+ break ;
83
89
case instrprof_error::unrecognized_format:
84
- return " unrecognized instrumentation profile encoding format" ;
90
+ OS << " unrecognized instrumentation profile encoding format" ;
91
+ break ;
85
92
case instrprof_error::bad_magic:
86
- return " invalid instrumentation profile data (bad magic)" ;
93
+ OS << " invalid instrumentation profile data (bad magic)" ;
94
+ break ;
87
95
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 ;
89
98
case instrprof_error::unsupported_version:
90
- return " unsupported instrumentation profile format version" ;
99
+ OS << " unsupported instrumentation profile format version" ;
100
+ break ;
91
101
case instrprof_error::unsupported_hash_type:
92
- return " unsupported instrumentation profile hash type" ;
102
+ OS << " unsupported instrumentation profile hash type" ;
103
+ break ;
93
104
case instrprof_error::too_large:
94
- return " too much profile data" ;
105
+ OS << " too much profile data" ;
106
+ break ;
95
107
case instrprof_error::truncated:
96
- return " truncated profile data" ;
108
+ OS << " truncated profile data" ;
109
+ break ;
97
110
case instrprof_error::malformed:
98
- return " malformed instrumentation profile data" ;
111
+ OS << " malformed instrumentation profile data" ;
112
+ break ;
99
113
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 ;
103
118
case instrprof_error::unknown_function:
104
- return " no profile data available for function" ;
119
+ OS << " no profile data available for function" ;
120
+ break ;
105
121
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 ;
107
124
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 ;
109
127
case instrprof_error::counter_overflow:
110
- return " counter overflow" ;
128
+ OS << " counter overflow" ;
129
+ break ;
111
130
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 ;
113
133
case instrprof_error::compress_failed:
114
- return " failed to compress data (zlib)" ;
134
+ OS << " failed to compress data (zlib)" ;
135
+ break ;
115
136
case instrprof_error::uncompress_failed:
116
- return " failed to uncompress data (zlib)" ;
137
+ OS << " failed to uncompress data (zlib)" ;
138
+ break ;
117
139
case instrprof_error::empty_raw_profile:
118
- return " empty raw profile file" ;
140
+ OS << " empty raw profile file" ;
141
+ break ;
119
142
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 ;
122
149
}
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 ();
124
156
}
125
157
126
158
namespace {
@@ -217,7 +249,7 @@ void SoftInstrProfErrors::addError(instrprof_error IE) {
217
249
}
218
250
219
251
std::string InstrProfError::message () const {
220
- return getInstrProfErrString (Err);
252
+ return getInstrProfErrString (Err, Msg );
221
253
}
222
254
223
255
char InstrProfError::ID = 0 ;
@@ -878,18 +910,23 @@ static std::unique_ptr<ValueProfData> allocValueProfData(uint32_t TotalSize) {
878
910
879
911
Error ValueProfData::checkIntegrity () {
880
912
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.
883
916
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" );
885
919
886
920
ValueProfRecord *VR = getFirstValueProfRecord (this );
887
921
for (uint32_t K = 0 ; K < this ->NumValueKinds ; K++) {
888
922
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" );
890
925
VR = getValueProfRecordNext (VR);
891
926
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" );
893
930
}
894
931
return Error::success ();
895
932
}
0 commit comments