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

Side by Side Diff: unittests/Bitcode/NaClParseInstsTest.cpp

Issue 986453002: Additional clean ups on errors in bitcode parsing. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix comment. 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 | « unittests/Bitcode/NaClObjDumpTest.cpp ('k') | unittests/Bitcode/NaClParseTypesTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- llvm/unittest/Bitcode/NaClParseInstsTest.cpp ----------------------===// 1 //===- llvm/unittest/Bitcode/NaClParseInstsTest.cpp ----------------------===//
2 // Tests parser for PNaCl bitcode instructions. 2 // Tests parser for PNaCl bitcode instructions.
3 // 3 //
4 // The LLVM Compiler Infrastructure 4 // The LLVM Compiler Infrastructure
5 // 5 //
6 // This file is distributed under the University of Illinois Open Source 6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details. 7 // License. See LICENSE.TXT for details.
8 // 8 //
9 //===----------------------------------------------------------------------===// 9 //===----------------------------------------------------------------------===//
10 10
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 "Error(66:4): Invalid relative value id: 100 (Must be <= 4)\n" 83 "Error(66:4): Invalid relative value id: 100 (Must be <= 4)\n"
84 " 72:6| 3: <10> | ret void;\n" 84 " 72:6| 3: <10> | ret void;\n"
85 " 74:4| 0: <65534> | }\n" 85 " 74:4| 0: <65534> | }\n"
86 " 76:0|0: <65534> |}\n", 86 " 76:0|0: <65534> |}\n",
87 DumpMunger.getTestResults()); 87 DumpMunger.getTestResults());
88 88
89 NaClParseBitcodeMunger Munger(BitcodeRecords, 89 NaClParseBitcodeMunger Munger(BitcodeRecords,
90 array_lengthof(BitcodeRecords), Terminator); 90 array_lengthof(BitcodeRecords), Terminator);
91 EXPECT_FALSE(Munger.runTest("Nonexistant call arg", true)); 91 EXPECT_FALSE(Munger.runTest("Nonexistant call arg", true));
92 EXPECT_EQ( 92 EXPECT_EQ(
93 "Error: (72:6) Invalid call argument: Index 1\n" 93 "Error(72:6): Invalid call argument: Index 1\n"
94 "Error: Invalid value in record\n", 94 "Error: Invalid value in record\n",
95 Munger.getTestResults()); 95 Munger.getTestResults());
96 } 96 }
97 97
98 /// Test how we recognize alignments in alloca instructions. 98 /// Test how we recognize alignments in alloca instructions.
99 TEST(NaClParseInstsTests, BadAllocaAlignment) { 99 TEST(NaClParseInstsTests, BadAllocaAlignment) {
100 const uint64_t BitcodeRecords[] = { 100 const uint64_t BitcodeRecords[] = {
101 1, naclbitc::BLK_CODE_ENTER, naclbitc::MODULE_BLOCK_ID, 2, Terminator, 101 1, naclbitc::BLK_CODE_ENTER, naclbitc::MODULE_BLOCK_ID, 2, Terminator,
102 1, naclbitc::BLK_CODE_ENTER, naclbitc::TYPE_BLOCK_ID_NEW, 2, Terminator, 102 1, naclbitc::BLK_CODE_ENTER, naclbitc::TYPE_BLOCK_ID_NEW, 2, Terminator,
103 3, naclbitc::TYPE_CODE_NUMENTRY, 4, Terminator, 103 3, naclbitc::TYPE_CODE_NUMENTRY, 4, Terminator,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 DumpMunger.getLinesWithSubstring("alloca")); 166 DumpMunger.getLinesWithSubstring("alloca"));
167 167
168 // Show what happens when changing alignment to 2**30. 168 // Show what happens when changing alignment to 2**30.
169 const uint64_t Align30[] = { 169 const uint64_t Align30[] = {
170 ReplaceIndex, NaClBitcodeMunger::Replace, 170 ReplaceIndex, NaClBitcodeMunger::Replace,
171 3, naclbitc::FUNC_CODE_INST_ALLOCA, 1, getEncAlignPower(30), Terminator, 171 3, naclbitc::FUNC_CODE_INST_ALLOCA, 1, getEncAlignPower(30), Terminator,
172 }; 172 };
173 EXPECT_FALSE(Munger.runTest( 173 EXPECT_FALSE(Munger.runTest(
174 "BadAllocaAlignment-30", Align30, array_lengthof(Align30), true)); 174 "BadAllocaAlignment-30", Align30, array_lengthof(Align30), true));
175 EXPECT_EQ( 175 EXPECT_EQ(
176 "Error: (65:6) Alignment can't be greater than 2**29. Found: 2**30\n" 176 "Error(65:6): Alignment can't be greater than 2**29. Found: 2**30\n"
177 "Error: Invalid value in record\n", 177 "Error: Invalid value in record\n",
178 Munger.getTestResults()); 178 Munger.getTestResults());
179 EXPECT_FALSE(DumpMunger.runTestForAssembly( 179 EXPECT_FALSE(DumpMunger.runTestForAssembly(
180 "BadAllocaAlignment-30", Align30, array_lengthof(Align30))); 180 "BadAllocaAlignment-30", Align30, array_lengthof(Align30)));
181 EXPECT_EQ( 181 EXPECT_EQ(
182 " %v0 = alloca i8, i32 %p0, align 0;\n", 182 " %v0 = alloca i8, i32 %p0, align 0;\n",
183 DumpMunger.getLinesWithSubstring("alloca")); 183 DumpMunger.getLinesWithSubstring("alloca"));
184 EXPECT_EQ( 184 EXPECT_EQ(
185 "Error(62:4): Alignment can't be greater than 2**29. Found: 2**30\n", 185 "Error(62:4): Alignment can't be greater than 2**29. Found: 2**30\n",
186 DumpMunger.getLinesWithSubstring("Error")); 186 DumpMunger.getLinesWithSubstring("Error"));
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 DumpMunger.getLinesWithSubstring("load")); 302 DumpMunger.getLinesWithSubstring("load"));
303 303
304 // Show what happens when changing alignment to 2**30. 304 // Show what happens when changing alignment to 2**30.
305 const uint64_t Align30[] = { 305 const uint64_t Align30[] = {
306 ReplaceIndex, NaClBitcodeMunger::Replace, 306 ReplaceIndex, NaClBitcodeMunger::Replace,
307 3, naclbitc::FUNC_CODE_INST_LOAD, 1, getEncAlignPower(30), 0, Terminator, 307 3, naclbitc::FUNC_CODE_INST_LOAD, 1, getEncAlignPower(30), 0, Terminator,
308 }; 308 };
309 EXPECT_FALSE(Munger.runTest( 309 EXPECT_FALSE(Munger.runTest(
310 "BadLoadAlignment-30", Align30, array_lengthof(Align30), true)); 310 "BadLoadAlignment-30", Align30, array_lengthof(Align30), true));
311 EXPECT_EQ( 311 EXPECT_EQ(
312 "Error: (62:4) Alignment can't be greater than 2**29. Found: 2**30\n" 312 "Error(62:4): Alignment can't be greater than 2**29. Found: 2**30\n"
313 "Error: Invalid value in record\n", 313 "Error: Invalid value in record\n",
314 Munger.getTestResults()); 314 Munger.getTestResults());
315 EXPECT_FALSE(DumpMunger.runTestForAssembly( 315 EXPECT_FALSE(DumpMunger.runTestForAssembly(
316 "BadLoadAlignment-30", Align30, array_lengthof(Align30))); 316 "BadLoadAlignment-30", Align30, array_lengthof(Align30)));
317 EXPECT_EQ( 317 EXPECT_EQ(
318 " %v0 = load i32* %p0, align 0;\n" 318 " %v0 = load i32* %p0, align 0;\n"
319 "Error(58:4): load: Illegal alignment for i32. Expects: 1\n", 319 "Error(58:4): load: Illegal alignment for i32. Expects: 1\n",
320 DumpMunger.getLinesWithSubstring("load")); 320 DumpMunger.getLinesWithSubstring("load"));
321 } 321 }
322 322
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 DumpMunger.getLinesWithSubstring("store")); 434 DumpMunger.getLinesWithSubstring("store"));
435 435
436 // Show what happens when changing alignment to 2**30. 436 // Show what happens when changing alignment to 2**30.
437 const uint64_t Align30[] = { 437 const uint64_t Align30[] = {
438 ReplaceIndex, NaClBitcodeMunger::Replace, 438 ReplaceIndex, NaClBitcodeMunger::Replace,
439 3, naclbitc::FUNC_CODE_INST_STORE, 2, 1, getEncAlignPower(30), Terminator, 439 3, naclbitc::FUNC_CODE_INST_STORE, 2, 1, getEncAlignPower(30), Terminator,
440 }; 440 };
441 EXPECT_FALSE(Munger.runTest( 441 EXPECT_FALSE(Munger.runTest(
442 "BadStoreAlignment-30", Align30, array_lengthof(Align30), true)); 442 "BadStoreAlignment-30", Align30, array_lengthof(Align30), true));
443 EXPECT_EQ( 443 EXPECT_EQ(
444 "Error: (66:4) Alignment can't be greater than 2**29. Found: 2**30\n" 444 "Error(66:4): Alignment can't be greater than 2**29. Found: 2**30\n"
445 "Error: Invalid value in record\n", 445 "Error: Invalid value in record\n",
446 Munger.getTestResults()); 446 Munger.getTestResults());
447 EXPECT_FALSE(DumpMunger.runTestForAssembly( 447 EXPECT_FALSE(DumpMunger.runTestForAssembly(
448 "BadStoreAlignment-30", Align30, array_lengthof(Align30))); 448 "BadStoreAlignment-30", Align30, array_lengthof(Align30)));
449 EXPECT_EQ( 449 EXPECT_EQ(
450 " store float %p1, float* %p0, align 0;\n" 450 " store float %p1, float* %p0, align 0;\n"
451 "Error(62:4): store: Illegal alignment for float. Expects: 1 or 4\n", 451 "Error(62:4): store: Illegal alignment for float. Expects: 1 or 4\n",
452 DumpMunger.getLinesWithSubstring("store")); 452 DumpMunger.getLinesWithSubstring("store"));
453 } 453 }
454 454
455 } // end of anonamous namespace. 455 } // end of anonamous namespace.
OLDNEW
« no previous file with comments | « unittests/Bitcode/NaClObjDumpTest.cpp ('k') | unittests/Bitcode/NaClParseTypesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698