Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h

Issue 932953002: Fix the NaCl bitstream reader to report fatal errors. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix formatting. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===- NaClBitcodeMunge.h - Bitcode Munger ----------------------*- C++ -*-===// 1 //===- NaClBitcodeMunge.h - Bitcode Munger ----------------------*- C++ -*-===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // Test harness for generating a PNaCl bitcode memory buffer from 10 // Test harness for generating a PNaCl bitcode memory buffer from
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 // The stream containing errors and the objdump of the generated bitcode file. 132 // The stream containing errors and the objdump of the generated bitcode file.
133 raw_ostream *DumpStream; 133 raw_ostream *DumpStream;
134 // The bitstream writer to use to generate the bitcode file. 134 // The bitstream writer to use to generate the bitcode file.
135 NaClBitstreamWriter *Writer; 135 NaClBitstreamWriter *Writer;
136 // True if any errors were reported. 136 // True if any errors were reported.
137 bool FoundErrors; 137 bool FoundErrors;
138 // The buffer to hold the generated fatal message. 138 // The buffer to hold the generated fatal message.
139 std::string FatalBuffer; 139 std::string FatalBuffer;
140 // The stream to write the fatal message to. 140 // The stream to write the fatal message to.
141 raw_string_ostream FatalStream; 141 raw_string_ostream FatalStream;
142 // The stack of maximum abbreviation indices allowed by block enter record.
143 std::vector<uint64_t> AbbrevIndexLimitStack;
142 144
143 // Records that an error occurred, and returns stream to print error 145 // Records that an error occurred, and returns stream to print error
144 // message to. 146 // message to.
145 raw_ostream &Error() { 147 raw_ostream &Error() {
146 FoundErrors = true; 148 FoundErrors = true;
147 return *DumpStream << "Error: "; 149 return *DumpStream << "Error: ";
148 } 150 }
149 151
150 // Returns stream to print fatal error message to. 152 // Returns stream to print fatal error message to.
151 // Note: Once the fatal error message has been dumped to the stream, 153 // Note: Once the fatal error message has been dumped to the stream,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 size_t &Index); 192 size_t &Index);
191 }; 193 };
192 194
193 /// Class to run tests for function llvm::NaClObjDump. 195 /// Class to run tests for function llvm::NaClObjDump.
194 class NaClObjDumpMunger : public NaClBitcodeMunger { 196 class NaClObjDumpMunger : public NaClBitcodeMunger {
195 public: 197 public:
196 198
197 /// Creates a bitcode munger, based on the given array of values. 199 /// Creates a bitcode munger, based on the given array of values.
198 NaClObjDumpMunger(const uint64_t Records[], size_t RecordsSize, 200 NaClObjDumpMunger(const uint64_t Records[], size_t RecordsSize,
199 uint64_t RecordTerminator) 201 uint64_t RecordTerminator)
200 : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {} 202 : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator),
203 RunAsDeathTest(false) {}
201 204
202 /// Runs function NaClObjDump on the sequence of records associated 205 /// Runs function NaClObjDump on the sequence of records associated
203 /// with the instance. The memory buffer containing the bitsequence 206 /// with the instance. The memory buffer containing the bitsequence
204 /// associated with the record is automatically generated, and 207 /// associated with the record is automatically generated, and
205 /// passed to NaClObjDump. TestName is the name associated with the 208 /// passed to NaClObjDump. TestName is the name associated with the
206 /// memory buffer. If AddHeader is true, test assumes that the 209 /// memory buffer. If AddHeader is true, test assumes that the
207 /// sequence of records doesn't contain a header record, and the 210 /// sequence of records doesn't contain a header record, and the
208 /// test should add one. Arguments NoRecords and NoAssembly are 211 /// test should add one. Arguments NoRecords and NoAssembly are
209 /// passed to NaClObjDump. Returns true if test succeeds without 212 /// passed to NaClObjDump. Returns true if test succeeds without
210 /// errors. 213 /// errors.
211 bool runTestWithFlags(const char *TestName, bool AddHeader, 214 bool runTestWithFlags(const char *TestName, bool AddHeader,
212 bool NoRecords, bool NoAssembly) { 215 bool NoRecords, bool NoAssembly) {
213 uint64_t NoMunges[] = {0}; 216 uint64_t NoMunges[] = {0};
214 return runTestWithFlags(TestName, NoMunges, 0, AddHeader, NoRecords, 217 return runTestWithFlags(TestName, NoMunges, 0, AddHeader, NoRecords,
215 NoAssembly); 218 NoAssembly);
216 } 219 }
217 220
221 /// Returns true if running as death test.
222 bool getRunAsDeathTest() const {
223 return RunAsDeathTest;
224 }
225
226 /// Sets death test flag. When true, output will be redirected to the
227 /// errstream so that they can be tested.
228 void setRunAsDeathTest(bool NewValue) {
229 RunAsDeathTest = NewValue;
230 }
231
218 /// Same as above except it runs function NaClObjDump with flags 232 /// Same as above except it runs function NaClObjDump with flags
219 /// NoRecords and NoAssembly set to false, and AddHeader set to true. 233 /// NoRecords and NoAssembly set to false, and AddHeader set to true.
220 bool runTest(const char *TestName) { 234 bool runTest(const char *TestName) {
221 return runTestWithFlags(TestName, true, false, false); 235 return runTestWithFlags(TestName, true, false, false);
222 } 236 }
223 237
224 /// Same as runTest, but only print out assembly and errors. 238 /// Same as runTest, but only print out assembly and errors.
225 bool runTestForAssembly(const char *TestName) { 239 bool runTestForAssembly(const char *TestName) {
226 return runTestWithFlags(TestName, true, true, false); 240 return runTestWithFlags(TestName, true, true, false);
227 } 241 }
(...skipping 25 matching lines...) Expand all
253 267
254 bool runTestForAssembly(const char* TestName, const uint64_t Munges[], 268 bool runTestForAssembly(const char* TestName, const uint64_t Munges[],
255 size_t MungesSize) { 269 size_t MungesSize) {
256 return runTestWithFlags(TestName, Munges, MungesSize, true, true, false); 270 return runTestWithFlags(TestName, Munges, MungesSize, true, true, false);
257 } 271 }
258 272
259 bool runTestForErrors(const char* TestName, const uint64_t Munges[], 273 bool runTestForErrors(const char* TestName, const uint64_t Munges[],
260 size_t MungesSize) { 274 size_t MungesSize) {
261 return runTestWithFlags(TestName, Munges, MungesSize, true, true, true); 275 return runTestWithFlags(TestName, Munges, MungesSize, true, true, true);
262 } 276 }
277
278 private:
279 // Flag to redirect dump stream if running death test.
280 bool RunAsDeathTest;
281
263 }; 282 };
264 283
265 // Class to run tests for function NaClParseBitcodeFile. 284 // Class to run tests for function NaClParseBitcodeFile.
266 class NaClParseBitcodeMunger : public NaClBitcodeMunger { 285 class NaClParseBitcodeMunger : public NaClBitcodeMunger {
267 public: 286 public:
268 NaClParseBitcodeMunger(const uint64_t Records[], size_t RecordsSize, 287 NaClParseBitcodeMunger(const uint64_t Records[], size_t RecordsSize,
269 uint64_t RecordTerminator) 288 uint64_t RecordTerminator)
270 : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {} 289 : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {}
271 290
272 /// Runs function llvm::NaClParseBitcodeFile, and puts error messages 291 /// Runs function llvm::NaClParseBitcodeFile, and puts error messages
273 /// into DumpResults. Returns true if parse is successful. 292 /// into DumpResults. Returns true if parse is successful.
274 bool runTest(const char* TestName, const uint64_t Munges[], 293 bool runTest(const char* TestName, const uint64_t Munges[],
275 size_t MungesSize, bool VerboseErrors); 294 size_t MungesSize, bool VerboseErrors);
276 295
277 // Same as above, but without any edits. 296 // Same as above, but without any edits.
278 bool runTest(const char* TestName, bool VerboseErrors) { 297 bool runTest(const char* TestName, bool VerboseErrors) {
279 uint64_t NoMunges[] = {0}; 298 uint64_t NoMunges[] = {0};
280 return runTest(TestName, NoMunges, 0, VerboseErrors); 299 return runTest(TestName, NoMunges, 0, VerboseErrors);
281 } 300 }
282 }; 301 };
283 302
284 } // end namespace llvm. 303 } // end namespace llvm.
285 304
286 #endif // LLVM_BITCODE_NACL_NACLBITCODEMUNGE_H 305 #endif // LLVM_BITCODE_NACL_NACLBITCODEMUNGE_H
OLDNEW
« no previous file with comments | « no previous file | include/llvm/Bitcode/NaCl/NaClBitcodeParser.h » ('j') | include/llvm/Bitcode/NaCl/NaClBitcodeParser.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698