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

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: Merge with master Created 5 years, 9 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
« no previous file with comments | « no previous file | include/llvm/Bitcode/NaCl/NaClBitcodeParser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 SmallVector<uint64_t, 3> 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
227 /// the errs() (rather than buffered) so that the test can be
228 /// debugged.
229 void setRunAsDeathTest(bool NewValue) {
230 RunAsDeathTest = NewValue;
231 }
232
218 /// Same as above except it runs function NaClObjDump with flags 233 /// Same as above except it runs function NaClObjDump with flags
219 /// NoRecords and NoAssembly set to false, and AddHeader set to true. 234 /// NoRecords and NoAssembly set to false, and AddHeader set to true.
220 bool runTest(const char *TestName) { 235 bool runTest(const char *TestName) {
221 return runTestWithFlags(TestName, true, false, false); 236 return runTestWithFlags(TestName, true, false, false);
222 } 237 }
223 238
224 /// Same as runTest, but only print out assembly and errors. 239 /// Same as runTest, but only print out assembly and errors.
225 bool runTestForAssembly(const char *TestName) { 240 bool runTestForAssembly(const char *TestName) {
226 return runTestWithFlags(TestName, true, true, false); 241 return runTestWithFlags(TestName, true, true, false);
227 } 242 }
(...skipping 25 matching lines...) Expand all
253 268
254 bool runTestForAssembly(const char* TestName, const uint64_t Munges[], 269 bool runTestForAssembly(const char* TestName, const uint64_t Munges[],
255 size_t MungesSize) { 270 size_t MungesSize) {
256 return runTestWithFlags(TestName, Munges, MungesSize, true, true, false); 271 return runTestWithFlags(TestName, Munges, MungesSize, true, true, false);
257 } 272 }
258 273
259 bool runTestForErrors(const char* TestName, const uint64_t Munges[], 274 bool runTestForErrors(const char* TestName, const uint64_t Munges[],
260 size_t MungesSize) { 275 size_t MungesSize) {
261 return runTestWithFlags(TestName, Munges, MungesSize, true, true, true); 276 return runTestWithFlags(TestName, Munges, MungesSize, true, true, true);
262 } 277 }
278
279 private:
280 // Flag to redirect dump stream if running death test.
281 bool RunAsDeathTest;
282
263 }; 283 };
264 284
265 // Class to run tests for function NaClParseBitcodeFile. 285 // Class to run tests for function NaClParseBitcodeFile.
266 class NaClParseBitcodeMunger : public NaClBitcodeMunger { 286 class NaClParseBitcodeMunger : public NaClBitcodeMunger {
267 public: 287 public:
268 NaClParseBitcodeMunger(const uint64_t Records[], size_t RecordsSize, 288 NaClParseBitcodeMunger(const uint64_t Records[], size_t RecordsSize,
269 uint64_t RecordTerminator) 289 uint64_t RecordTerminator)
270 : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {} 290 : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {}
271 291
272 /// Runs function llvm::NaClParseBitcodeFile, and puts error messages 292 /// Runs function llvm::NaClParseBitcodeFile, and puts error messages
(...skipping 20 matching lines...) Expand all
293 313
294 bool runTest(const char* TestName) { 314 bool runTest(const char* TestName) {
295 uint64_t NoMunges[] = {0}; 315 uint64_t NoMunges[] = {0};
296 return runTest(TestName, NoMunges, 0); 316 return runTest(TestName, NoMunges, 0);
297 } 317 }
298 }; 318 };
299 319
300 } // end namespace llvm. 320 } // end namespace llvm.
301 321
302 #endif // LLVM_BITCODE_NACL_NACLBITCODEMUNGE_H 322 #endif // LLVM_BITCODE_NACL_NACLBITCODEMUNGE_H
OLDNEW
« no previous file with comments | « no previous file | include/llvm/Bitcode/NaCl/NaClBitcodeParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698