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

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

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: undo localmod 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/NaClParseInstsTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 //===- llvm/unittest/Bitcode/NaClObjDumpTypesTest.cpp ---------------------===//
2 // Tests objdump stream for PNaCl bitcode.
3 //
4 // The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 // Tests record errors in the types block when dumping PNaCl bitcode.
12
13 #include "llvm/ADT/STLExtras.h"
14 #include "llvm/Bitcode/NaCl/NaClBitcodeMunge.h"
15
16 #include "gtest/gtest.h"
17
18 using namespace llvm;
19
20 namespace {
21
22 static const uint64_t Terminator = 0x5768798008978675LL;
23
24 static const char ErrorPrefix[] = "Error";
25
26 // Tests what happens when a type refers to a not-yet defined type.
27 TEST(NaClObjDumpTypesTest, BadTypeReferences) {
28 const uint64_t BitcodeRecords[] = {
29 1, 65535, 8, 2, Terminator,
30 1, 65535, 17, 2, Terminator,
31 3, 1, 2, Terminator,
32 3, 7, 32, Terminator,
33 3, 3, Terminator,
34 0, 65534, Terminator,
35 0, 65534, Terminator
36 };
37
38 const uint64_t ReplaceIndex = 4;
39
40 // Show base input.
41 NaClObjDumpMunger Munger(BitcodeRecords,
42 array_lengthof(BitcodeRecords), Terminator);
43 EXPECT_TRUE(Munger.runTestForAssembly("Bad type references base"));
44 EXPECT_EQ(
45 "module { // BlockID = 8\n"
46 " types { // BlockID = 17\n"
47 " count 2;\n"
48 " @t0 = i32;\n"
49 " @t1 = float;\n"
50 " }\n"
51 "}\n",
52 Munger.getTestResults());
53
54 // Show what happens when defining: @t1 = <4 x @t1>
55 const uint64_t AddSelfReference[] = {
56 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 4, 1, Terminator
57 };
58 EXPECT_FALSE(Munger.runTestForAssembly(
59 "@t1 = <4 x @t1>", AddSelfReference, array_lengthof(AddSelfReference)));
60 // Note: Because @t1 is not defined until after this instruction,
61 // the initial lookup of @t1 in <4 x @t1> is not found. To error
62 // recover, type "void" is returned as the type of @t1.
63 EXPECT_EQ("Error(37:6): Can't find definition for @t1\n"
64 "Error(37:6): Vectors can only be defined on primitive types."
65 " Found void. Assuming i32 instead.\n",
66 Munger.getLinesWithPrefix(ErrorPrefix));
67 EXPECT_EQ(
68 " @t1 = <4 x i32>;\n"
69 "Error(37:6): Can't find definition for @t1\n",
70 Munger.getLinesWithSubstring("@t1"));
71
72 // Show what happens when defining: @t1 = <4 x @t5>
73 const uint64_t AddForwardReference[] = {
74 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 4, 5, Terminator
75 };
76 EXPECT_FALSE(Munger.runTestForAssembly(
77 "@t1 = <4 x @t5>", AddForwardReference,
78 array_lengthof(AddForwardReference)));
79 // Note: Because @t5 is not defined, type "void" is used to error recover.
80 EXPECT_EQ(
81 "Error(37:6): Can't find definition for @t5\n"
82 "Error(37:6): Vectors can only be defined on primitive types."
83 " Found void. Assuming i32 instead.\n",
84 Munger.getLinesWithPrefix(ErrorPrefix));
85 EXPECT_EQ(
86 " @t1 = <4 x i32>;\n",
87 Munger.getLinesWithSubstring("@t1"));
88 }
89
90 // Tests handling of the count record in the types block.
91 TEST(NaClObjDumpTypesTest, TestCountRecord) {
92 const uint64_t BitcodeRecords[] = {
93 1, 65535, 8, 2, Terminator,
94 1, 65535, 17, 2, Terminator,
95 3, 1, 2, Terminator,
96 3, 7, 32, Terminator,
97 3, 3, Terminator,
98 0, 65534, Terminator,
99 0, 65534, Terminator
100 };
101
102 const uint64_t AddBeforeIndex = 5;
103 const uint64_t ReplaceIndex = 2;
104
105 NaClObjDumpMunger Munger(BitcodeRecords,
106 array_lengthof(BitcodeRecords), Terminator);
107
108 // Test case where count is correct.
109 EXPECT_TRUE(Munger.runTestForAssembly("Good case"));
110 EXPECT_EQ(
111 "module { // BlockID = 8\n"
112 " types { // BlockID = 17\n"
113 " count 2;\n"
114 " @t0 = i32;\n"
115 " @t1 = float;\n"
116 " }\n"
117 "}\n",
118 Munger.getTestResults());
119
120 // Test case where more types are defined then specified by the
121 // count record.
122 const uint64_t AddDoubleType[] = {
123 AddBeforeIndex, NaClBitcodeMunger::AddBefore, 3, 4, Terminator
124 };
125 EXPECT_FALSE(Munger.runTestForAssembly(
126 "Add double type", AddDoubleType, array_lengthof(AddDoubleType)));
127 EXPECT_EQ("Error(41:2): Expected 2 types but found: 3\n",
128 Munger.getLinesWithPrefix(ErrorPrefix));
129 EXPECT_EQ(
130 " @t0 = i32;\n"
131 " @t1 = float;\n"
132 " @t2 = double;\n",
133 Munger.getLinesWithSubstring("@t"));
134
135 // Test case where fewer types are defined then specified by the count
136 // record.
137 const uint64_t DeleteI32Type[] = { 3, NaClBitcodeMunger::Remove };
138 EXPECT_FALSE(Munger.runTestForAssembly(
139 "Delete I32 type", DeleteI32Type, array_lengthof(DeleteI32Type)));
140 EXPECT_EQ("Error(36:2): Expected 2 types but found: 1\n",
141 Munger.getLinesWithPrefix(ErrorPrefix));
142 EXPECT_EQ(
143 " @t0 = float;\n",
144 Munger.getLinesWithSubstring("@t"));
145
146 // Test if we generate an error message if the count record isn't first.
147 const uint64_t AddI16BeforeCount[] = {
148 ReplaceIndex, NaClBitcodeMunger::AddBefore, 3, 7, 16, Terminator };
149 EXPECT_FALSE(Munger.runTestForAssembly(
150 "Add I16 before count", AddI16BeforeCount,
151 array_lengthof(AddI16BeforeCount)));
152 EXPECT_EQ(
153 "module { // BlockID = 8\n"
154 " types { // BlockID = 17\n"
155 " @t0 = i16;\n"
156 " count 2;\n"
157 "Error(34:4): Count record not first record of types block\n"
158 " @t1 = i32;\n"
159 " @t2 = float;\n"
160 " }\n"
161 "Error(42:0): Expected 2 types but found: 3\n"
162 "}\n",
163 Munger.getTestResults());
164
165 // Test if count record doesn't contain enough elements.
166 const uint64_t CountRecordEmpty[] = {
167 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 1, Terminator };
168 EXPECT_FALSE(Munger.runTestForErrors(
169 "Count record empty", CountRecordEmpty,
170 array_lengthof(CountRecordEmpty)));
171 EXPECT_EQ("Error(32:0): Count record should have 1 argument. Found: 0\n"
172 "Error(38:6): Expected 0 types but found: 2\n",
173 Munger.getTestResults());
174
175 // Test if count record has extraneous values.
176 const uint64_t CountRecordTooLong[] = {
177 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 1, 14, 2, Terminator
178 };
179 EXPECT_FALSE(Munger.runTestForErrors(
180 "Count record too long", CountRecordTooLong,
181 array_lengthof(CountRecordTooLong)));
182 EXPECT_EQ("Error(32:0): Count record should have 1 argument. Found: 2\n"
183 "Error(40:2): Expected 0 types but found: 2\n",
184 Munger.getTestResults());
185 }
186
187 // Tests handling of the void record in the types block.
188 TEST(NaClObjDumpTypesTest, TestVoidRecord) {
189 const uint64_t BitcodeRecords[] = {
190 1, 65535, 8, 2, Terminator,
191 1, 65535, 17, 2, Terminator,
192 3, 1, 1, Terminator,
193 3, 2, Terminator,
194 0, 65534, Terminator,
195 0, 65534, Terminator
196 };
197
198 const uint64_t ReplaceIndex = 3;
199
200 NaClObjDumpMunger Munger(BitcodeRecords,
201 array_lengthof(BitcodeRecords), Terminator);
202
203 // Test where void is properly specified.
204 EXPECT_TRUE(Munger.runTestForAssembly("Good case"));
205 EXPECT_EQ(
206 "module { // BlockID = 8\n"
207 " types { // BlockID = 17\n"
208 " count 1;\n"
209 " @t0 = void;\n"
210 " }\n"
211 "}\n",
212 Munger.getTestResults());
213
214 // Test where void record has extraneous values.
215 const uint64_t VoidRecordTooLong[] = {
216 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 2, 5, Terminator
217 };
218 EXPECT_FALSE(Munger.runTestForAssembly(
219 "Void record too long", VoidRecordTooLong,
220 array_lengthof(VoidRecordTooLong)));
221 EXPECT_EQ("Error(34:4): Void record shouldn't have arguments. Found: 1\n",
222 Munger.getLinesWithPrefix(ErrorPrefix));
223 EXPECT_EQ(
224 " @t0 = void;\n",
225 Munger.getLinesWithSubstring("@t0"));
226 }
227
228 // Tests handling of integer records in the types block.
229 TEST(NaClObjDumpTypesTest, TestIntegerRecord) {
230 const uint64_t BitcodeRecords[] = {
231 1, 65535, 8, 2, Terminator,
232 1, 65535, 17, 2, Terminator,
233 3, 1, 1, Terminator,
234 3, 7, 1, Terminator,
235 0, 65534, Terminator,
236 0, 65534, Terminator
237 };
238
239 const uint64_t ReplaceIndex = 3;
240
241 NaClObjDumpMunger Munger(BitcodeRecords,
242 array_lengthof(BitcodeRecords), Terminator);
243
244 // Tests that we accept i1.
245 EXPECT_TRUE(Munger.runTestForAssembly("Test type i1"));
246 EXPECT_EQ(
247 "module { // BlockID = 8\n"
248 " types { // BlockID = 17\n"
249 " count 1;\n"
250 " @t0 = i1;\n"
251 " }\n"
252 "}\n",
253 Munger.getTestResults());
254
255 // Tests that we reject i2.
256 const uint64_t TestTypeI2[] = {
257 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 7, 2, Terminator
258 };
259 EXPECT_FALSE(Munger.runTestForAssembly(
260 "Type type i2", TestTypeI2, array_lengthof(TestTypeI2)));
261 EXPECT_EQ(
262 "Error(34:4): Integer record contains bad integer size: 2\n",
263 Munger.getLinesWithPrefix(ErrorPrefix));
264 // Note: Error recovery uses i32 when type size is bad.
265 EXPECT_EQ(
266 " @t0 = i32;\n",
267 Munger.getLinesWithSubstring("@t0"));
268
269 // Tests that we accept i8.
270 const uint64_t TestTypeI8[] = {
271 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 7, 8, Terminator
272 };
273 EXPECT_TRUE(Munger.runTest(
274 "Type type i8", TestTypeI8, array_lengthof(TestTypeI8)));
275
276 // Tests that we accept i16.
277 const uint64_t TestTypeI16[] = {
278 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 7, 16, Terminator
279 };
280 EXPECT_TRUE(Munger.runTest(
281 "Type type i16", TestTypeI16, array_lengthof(TestTypeI16)));
282
283 // Tests that we accept i32.
284 const uint64_t TestTypeI32[] = {
285 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 7, 32, Terminator
286 };
287 EXPECT_TRUE(Munger.runTest(
288 "Type type i32", TestTypeI32, array_lengthof(TestTypeI32)));
289
290 // Tests that we accept i64.
291 const uint64_t TestTypeI64[] = {
292 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 7, 64, Terminator
293 };
294 EXPECT_TRUE(Munger.runTest(
295 "Type type i64", TestTypeI64, array_lengthof(TestTypeI64)));
296
297 // Tests that we reject i128.
298 const uint64_t TestTypeI128[] = {
299 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 7, 128, Terminator
300 };
301 EXPECT_FALSE(Munger.runTestForAssembly(
302 "Type type i128", TestTypeI128, array_lengthof(TestTypeI128)));
303 EXPECT_EQ(
304 "Error(34:4): Integer record contains bad integer size: 128\n",
305 Munger.getLinesWithPrefix(ErrorPrefix));
306 // Note: Error recovery uses i32 when type size is bad.
307 EXPECT_EQ(
308 " @t0 = i32;\n",
309 Munger.getLinesWithSubstring("@t0"));
310
311 // Tests when not enough values are in the integer record.
312 const uint64_t RecordTooShort[] = {
313 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 7, Terminator
314 };
315 EXPECT_FALSE(Munger.runTestForAssembly(
316 "Integer record too short", RecordTooShort,
317 array_lengthof(RecordTooShort)));
318 EXPECT_EQ(
319 "Error(34:4): Integer record should have one argument. Found: 0\n",
320 Munger.getLinesWithPrefix(ErrorPrefix));
321 // Note: Error recovery uses i32 when type size is bad.
322 EXPECT_EQ(
323 " @t0 = i32;\n",
324 Munger.getLinesWithSubstring("@t0"));
325
326 // Tests when too many values are in the integer record.
327 const uint64_t RecordTooLong[] = {
328 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 7, 32, 0, Terminator
329 };
330 EXPECT_FALSE(Munger.runTestForErrors(
331 "Integer record too long", RecordTooLong, array_lengthof(RecordTooLong)));
332 EXPECT_EQ(
333 "Error(34:4): Integer record should have one argument. Found: 2\n",
334 Munger.getTestResults());
335 }
336
337 // Tests handling of the float record in the types block.
338 TEST(NaClObjDumpTypesTest, TestFloatRecord) {
339 const uint64_t BitcodeRecords[] = {
340 1, 65535, 8, 2, Terminator,
341 1, 65535, 17, 2, Terminator,
342 3, 1, 1, Terminator,
343 3, 3, Terminator,
344 0, 65534, Terminator,
345 0, 65534, Terminator
346 };
347
348 const uint64_t ReplaceIndex = 3;
349
350 NaClObjDumpMunger Munger(BitcodeRecords,
351 array_lengthof(BitcodeRecords), Terminator);
352
353 // Test that we accept the float record.
354 EXPECT_TRUE(Munger.runTestForAssembly("Good case"));
355 EXPECT_EQ(
356 "module { // BlockID = 8\n"
357 " types { // BlockID = 17\n"
358 " count 1;\n"
359 " @t0 = float;\n"
360 " }\n"
361 "}\n",
362 Munger.getTestResults());
363
364 // Test error for float record that has extraneous values.
365 const uint64_t FloatRecordTooLong[] = {
366 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 3, 5, Terminator
367 };
368 EXPECT_FALSE(Munger.runTestForAssembly(
369 "Float record too long", FloatRecordTooLong,
370 array_lengthof(FloatRecordTooLong)));
371 EXPECT_EQ(
372 "Error(34:4): Float record shoudn't have arguments. Found: 1\n",
373 Munger.getLinesWithPrefix(ErrorPrefix));
374 EXPECT_EQ(
375 " @t0 = float;\n",
376 Munger.getLinesWithSubstring("@t"));
377 }
378
379 // Tests handling of the double record in the types block.
380 TEST(NaClObjDumpTypesTest, TestDoubleRecord) {
381 const uint64_t BitcodeRecords[] = {
382 1, 65535, 8, 2, Terminator,
383 1, 65535, 17, 2, Terminator,
384 3, 1, 1, Terminator,
385 3, 4, Terminator,
386 0, 65534, Terminator,
387 0, 65534, Terminator
388 };
389
390 const uint64_t ReplaceIndex = 3;
391
392 NaClObjDumpMunger Munger(BitcodeRecords,
393 array_lengthof(BitcodeRecords), Terminator);
394
395 // Test that we accept the double record.
396 EXPECT_TRUE(Munger.runTestForAssembly("Good case"));
397 EXPECT_EQ(
398 "module { // BlockID = 8\n"
399 " types { // BlockID = 17\n"
400 " count 1;\n"
401 " @t0 = double;\n"
402 " }\n"
403 "}\n",
404 Munger.getTestResults());
405
406 // Test error for double record that has extraneous values.
407 const uint64_t DoubleRecordTooLong[] = {
408 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 4, 5, Terminator
409 };
410 EXPECT_FALSE(Munger.runTestForAssembly(
411 "Double record too long", DoubleRecordTooLong,
412 array_lengthof(DoubleRecordTooLong)));
413 EXPECT_EQ(
414 "Error(34:4): Double record shound't have arguments. Found: 1\n",
415 Munger.getLinesWithPrefix(ErrorPrefix));
416 EXPECT_EQ(
417 " @t0 = double;\n",
418 Munger.getLinesWithSubstring("@t"));
419 }
420
421 // Test vector records of the wrong size.
422 TEST(NaClObjDumpTypesTest, TestVectorRecordLength) {
423 const uint64_t BitcodeRecords[] = {
424 1, 65535, 8, 2, Terminator,
425 1, 65535, 17, 2, Terminator,
426 3, 1, 2, Terminator,
427 3, 7, 32, Terminator,
428 3, 12, 4, 0, Terminator,
429 0, 65534, Terminator,
430 0, 65534, Terminator
431 };
432
433 const uint64_t ReplaceIndex = 4;
434
435 NaClObjDumpMunger Munger(BitcodeRecords,
436 array_lengthof(BitcodeRecords), Terminator);
437
438 // Test correct length vector record.
439 EXPECT_TRUE(Munger.runTestForAssembly("Test valid vector record"));
440 EXPECT_EQ(
441 "module { // BlockID = 8\n"
442 " types { // BlockID = 17\n"
443 " count 2;\n"
444 " @t0 = i32;\n"
445 " @t1 = <4 x i32>;\n"
446 " }\n"
447 "}\n",
448 Munger.getTestResults());
449
450 // Test vector record too short.
451 uint64_t RecordTooShort[] = {
452 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 4, Terminator
453 };
454 EXPECT_FALSE(Munger.runTestForAssembly(
455 "Record too short", RecordTooShort, array_lengthof(RecordTooShort)));
456 EXPECT_EQ(
457 "Error(37:6): Vector record should contain two arguments. Found: 1\n",
458 Munger.getLinesWithPrefix(ErrorPrefix));
459 EXPECT_EQ(
460 " @t1 = void;\n",
461 Munger.getLinesWithSubstring("@t1"));
462
463 // Test vector record too long.
464 uint64_t RecordTooLong[] = {
465 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 4, 0, 0, Terminator
466 };
467 EXPECT_FALSE(Munger.runTestForAssembly(
468 "Record too long", RecordTooLong, array_lengthof(RecordTooLong)));
469 EXPECT_EQ(
470 "Error(37:6): Vector record should contain two arguments. Found: 3\n",
471 Munger.getLinesWithPrefix(ErrorPrefix));
472 EXPECT_EQ(
473 " @t1 = void;\n",
474 Munger.getLinesWithSubstring("@t1"));
475 }
476
477 // Test i1 vector records in the types block.
478 TEST(NaClObjDumpTypesTest, TestI1VectorRecord) {
479 const uint64_t BitcodeRecords[] = {
480 1, 65535, 8, 2, Terminator,
481 1, 65535, 17, 2, Terminator,
482 3, 1, 2, Terminator,
483 3, 7, 1, Terminator,
484 3, 12, 4, 0, Terminator,
485 0, 65534, Terminator,
486 0, 65534, Terminator
487 };
488
489 const uint64_t ReplaceIndex = 4;
490
491 NaClObjDumpMunger Munger(BitcodeRecords,
492 array_lengthof(BitcodeRecords), Terminator);
493
494 // Test that we accept <4 x i1>.
495 EXPECT_TRUE(Munger.runTestForAssembly("Type <4 x i1>"));
496 EXPECT_EQ(
497 "module { // BlockID = 8\n"
498 " types { // BlockID = 17\n"
499 " count 2;\n"
500 " @t0 = i1;\n"
501 " @t1 = <4 x i1>;\n"
502 " }\n"
503 "}\n",
504 Munger.getTestResults());
505
506 // Test that we don't handle <1 x i1>.
507 const uint64_t Vector1xI1[] = {
508 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 1, 0, Terminator
509 };
510 EXPECT_FALSE(Munger.runTestForAssembly(
511 "Type <1 x i1>", Vector1xI1, array_lengthof(Vector1xI1)));
512 EXPECT_EQ(
513 "Error(37:0): Vector type <1 x i1> not allowed.\n",
514 Munger.getLinesWithPrefix(ErrorPrefix));
515 EXPECT_EQ(
516 " @t1 = <1 x i1>;\n",
517 Munger.getLinesWithSubstring("@t1"));
518
519 // Test that we don't handle <2 x i1>.
520 const uint64_t Vector2xI1[] = {
521 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 2, 0, Terminator
522 };
523 EXPECT_FALSE(Munger.runTestForAssembly(
524 "Type <2 x i1>", Vector2xI1, array_lengthof(Vector2xI1)));
525 EXPECT_EQ(
526 "Error(37:0): Vector type <2 x i1> not allowed.\n",
527 Munger.getLinesWithPrefix(ErrorPrefix));
528 EXPECT_EQ(
529 " @t1 = <2 x i1>;\n",
530 Munger.getLinesWithSubstring("@t1"));
531
532 // Test that we don't handle <3 x i1>.
533 const uint64_t Vector3xI1[] = {
534 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 3, 0, Terminator
535 };
536 EXPECT_FALSE(Munger.runTestForAssembly(
537 "Type <3 x i1>", Vector3xI1, array_lengthof(Vector3xI1)));
538 EXPECT_EQ(
539 "Error(37:0): Vector type <3 x i1> not allowed.\n",
540 Munger.getLinesWithPrefix(ErrorPrefix));
541 EXPECT_EQ(
542 " @t1 = <3 x i1>;\n",
543 Munger.getLinesWithSubstring("@t1"));
544
545 // Test that we handle <8 x i1>.
546 const uint64_t Vector8xI1[] = {
547 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 8, 0, Terminator
548 };
549 EXPECT_TRUE(Munger.runTest(
550 "Type <8 x i1>", Vector8xI1, array_lengthof(Vector8xI1)));
551
552 // Test that we handle <16 x i1>.
553 const uint64_t Vector16xI1[] = {
554 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 16, 0, Terminator
555 };
556 EXPECT_TRUE(Munger.runTest(
557 "Type <16 x i1>", Vector16xI1, array_lengthof(Vector16xI1)));
558
559 // Test that we reject <32 x i1>.
560 const uint64_t Vector32xI1[] = {
561 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 32, 0, Terminator
562 };
563 EXPECT_FALSE(Munger.runTestForAssembly(
564 "Type <32 x i1>", Vector32xI1, array_lengthof(Vector32xI1)));
565 EXPECT_EQ(
566 "Error(37:0): Vector type <32 x i1> not allowed.\n",
567 Munger.getLinesWithPrefix(ErrorPrefix));
568 EXPECT_EQ(
569 " @t1 = <32 x i1>;\n",
570 Munger.getLinesWithSubstring("@t1"));
571 }
572
573 // Test i8 vector records in the types block.
574 TEST(NaClObjDumpTypesTest, TestI8VectorRecord) {
575 const uint64_t BitcodeRecords[] = {
576 1, 65535, 8, 2, Terminator,
577 1, 65535, 17, 2, Terminator,
578 3, 1, 2, Terminator,
579 3, 7, 8, Terminator,
580 3, 12, 16, 0, Terminator,
581 0, 65534, Terminator,
582 0, 65534, Terminator
583 };
584
585 const uint64_t ReplaceIndex = 4;
586
587 NaClObjDumpMunger Munger(BitcodeRecords,
588 array_lengthof(BitcodeRecords), Terminator);
589
590 // Test that we accept <16 x i8>.
591 EXPECT_TRUE(Munger.runTestForAssembly("Type <16 x i8>"));
592 EXPECT_EQ(
593 "module { // BlockID = 8\n"
594 " types { // BlockID = 17\n"
595 " count 2;\n"
596 " @t0 = i8;\n"
597 " @t1 = <16 x i8>;\n"
598 " }\n"
599 "}\n",
600 Munger.getTestResults());
601
602 // Test that we reject <1 x i8>.
603 const uint64_t Vector1xI8[] = {
604 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 1, 0, Terminator
605 };
606 EXPECT_FALSE(Munger.runTestForAssembly(
607 "Type <1 x i8>", Vector1xI8, array_lengthof(Vector1xI8)));
608 EXPECT_EQ(
609 "Error(37:0): Vector type <1 x i8> not allowed.\n",
610 Munger.getLinesWithPrefix(ErrorPrefix));
611 EXPECT_EQ(
612 " @t1 = <1 x i8>;\n",
613 Munger.getLinesWithSubstring("@t1"));
614
615 // Test that we don't handle <2 x i8>.
616 const uint64_t Vector2xI8[] = {
617 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 2, 0, Terminator
618 };
619 EXPECT_FALSE(Munger.runTestForAssembly(
620 "Type <2 x i8>", Vector2xI8, array_lengthof(Vector2xI8)));
621 EXPECT_EQ(
622 "Error(37:0): Vector type <2 x i8> not allowed.\n",
623 Munger.getLinesWithPrefix(ErrorPrefix));
624 EXPECT_EQ(
625 " @t1 = <2 x i8>;\n",
626 Munger.getLinesWithSubstring("@t1"));
627
628 // Test that we don't handle <3 x i8>.
629 const uint64_t Vector3xI8[] = {
630 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 3, 0, Terminator
631 };
632 EXPECT_FALSE(Munger.runTestForAssembly(
633 "Type <3 x i8>", Vector3xI8, array_lengthof(Vector3xI8)));
634 EXPECT_EQ(
635 "Error(37:0): Vector type <3 x i8> not allowed.\n",
636 Munger.getLinesWithPrefix(ErrorPrefix));
637 EXPECT_EQ(
638 " @t1 = <3 x i8>;\n",
639 Munger.getLinesWithSubstring("@t1"));
640
641 // Test that we don't handle <4 x i8>.
642 const uint64_t Vector4xI8[] = {
643 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 4, 0, Terminator
644 };
645 EXPECT_FALSE(Munger.runTestForAssembly(
646 "Type <4 x i8>", Vector4xI8, array_lengthof(Vector4xI8)));
647 EXPECT_EQ(
648 "Error(37:0): Vector type <4 x i8> not allowed.\n",
649 Munger.getLinesWithPrefix(ErrorPrefix));
650 EXPECT_EQ(
651 " @t1 = <4 x i8>;\n",
652 Munger.getLinesWithSubstring("@t1"));
653
654 // Test that we don't handle <8 x i8>.
655 const uint64_t Vector8xI8[] = {
656 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 8, 0, Terminator
657 };
658 EXPECT_FALSE(Munger.runTestForAssembly(
659 "Type <8 x i8>", Vector8xI8, array_lengthof(Vector8xI8)));
660 EXPECT_EQ(
661 "Error(37:0): Vector type <8 x i8> not allowed.\n",
662 Munger.getLinesWithPrefix(ErrorPrefix));
663 EXPECT_EQ(
664 " @t1 = <8 x i8>;\n",
665 Munger.getLinesWithSubstring("@t1"));
666
667 // Test that we don't handle <32 x i8>.
668 const uint64_t Vector32xI8[] = {
669 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 32, 0, Terminator
670 };
671 EXPECT_FALSE(Munger.runTestForAssembly(
672 "Type <32 x i8>", Vector32xI8, array_lengthof(Vector32xI8)));
673 EXPECT_EQ(
674 "Error(37:0): Vector type <32 x i8> not allowed.\n",
675 Munger.getLinesWithPrefix(ErrorPrefix));
676 EXPECT_EQ(
677 " @t1 = <32 x i8>;\n",
678 Munger.getLinesWithSubstring("@t1"));
679 }
680
681 // Test i16 vector records in the types block.
682 TEST(NaClObjDumpTypesTest, TestI16VectorRecord) {
683 const uint64_t BitcodeRecords[] = {
684 1, 65535, 8, 2, Terminator,
685 1, 65535, 17, 2, Terminator,
686 3, 1, 2, Terminator,
687 3, 7, 16, Terminator,
688 3, 12, 8, 0, Terminator,
689 0, 65534, Terminator,
690 0, 65534, Terminator
691 };
692
693 const uint64_t ReplaceIndex = 4;
694
695 NaClObjDumpMunger Munger(BitcodeRecords,
696 array_lengthof(BitcodeRecords), Terminator);
697
698 // Test that we accept <8 x i16>.
699 EXPECT_TRUE(Munger.runTestForAssembly("Type <16 x i16>"));
700 EXPECT_EQ(
701 "module { // BlockID = 8\n"
702 " types { // BlockID = 17\n"
703 " count 2;\n"
704 " @t0 = i16;\n"
705 " @t1 = <8 x i16>;\n"
706 " }\n"
707 "}\n",
708 Munger.getTestResults());
709
710 // Test that we reject <1 x i16>.
711 const uint64_t Vector1xI16[] = {
712 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 1, 0, Terminator
713 };
714 EXPECT_FALSE(Munger.runTestForAssembly(
715 "Type <1 x i16>", Vector1xI16, array_lengthof(Vector1xI16)));
716 EXPECT_EQ(
717 "Error(37:0): Vector type <1 x i16> not allowed.\n",
718 Munger.getLinesWithPrefix(ErrorPrefix));
719 EXPECT_EQ(
720 " @t1 = <1 x i16>;\n",
721 Munger.getLinesWithSubstring("@t1"));
722
723 // Test that we don't handle <2 x i16>.
724 const uint64_t Vector2xI16[] = {
725 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 2, 0, Terminator
726 };
727 EXPECT_FALSE(Munger.runTestForAssembly(
728 "Type <2 x i16>", Vector2xI16, array_lengthof(Vector2xI16)));
729 EXPECT_EQ(
730 "Error(37:0): Vector type <2 x i16> not allowed.\n",
731 Munger.getLinesWithPrefix(ErrorPrefix));
732 EXPECT_EQ(
733 " @t1 = <2 x i16>;\n",
734 Munger.getLinesWithSubstring("@t1"));
735
736 // Test that we don't handle <3 x i16>.
737 const uint64_t Vector3xI16[] = {
738 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 3, 0, Terminator
739 };
740 EXPECT_FALSE(Munger.runTestForAssembly(
741 "Type <3 x i16>", Vector3xI16, array_lengthof(Vector3xI16)));
742 EXPECT_EQ(
743 "Error(37:0): Vector type <3 x i16> not allowed.\n",
744 Munger.getLinesWithPrefix(ErrorPrefix));
745 EXPECT_EQ(
746 " @t1 = <3 x i16>;\n",
747 Munger.getLinesWithSubstring("@t1"));
748
749 // Test that we don't handle <4 x i16>.
750 const uint64_t Vector4xI16[] = {
751 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 4, 0, Terminator
752 };
753 EXPECT_FALSE(Munger.runTestForAssembly(
754 "Type <4 x i16>", Vector4xI16, array_lengthof(Vector4xI16)));
755 EXPECT_EQ(
756 "Error(37:0): Vector type <4 x i16> not allowed.\n",
757 Munger.getLinesWithPrefix(ErrorPrefix));
758 EXPECT_EQ(
759 " @t1 = <4 x i16>;\n",
760 Munger.getLinesWithSubstring("@t1"));
761
762 // Test that we don't handle <16 x i16>.
763 const uint64_t Vector16xI16[] = {
764 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 16, 0, Terminator
765 };
766 EXPECT_FALSE(Munger.runTestForAssembly(
767 "Type <16 x i16>", Vector16xI16, array_lengthof(Vector16xI16)));
768 EXPECT_EQ(
769 "Error(37:0): Vector type <16 x i16> not allowed.\n",
770 Munger.getLinesWithPrefix(ErrorPrefix));
771 EXPECT_EQ(
772 " @t1 = <16 x i16>;\n",
773 Munger.getLinesWithSubstring("@t1"));
774
775 // Test that we don't handle <32 x i16>.
776 const uint64_t Vector32xI16[] = {
777 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 32, 0, Terminator
778 };
779 EXPECT_FALSE(Munger.runTestForAssembly(
780 "Type <32 x i16>", Vector32xI16, array_lengthof(Vector32xI16)));
781 EXPECT_EQ(
782 "Error(37:0): Vector type <32 x i16> not allowed.\n",
783 Munger.getLinesWithPrefix(ErrorPrefix));
784 EXPECT_EQ(
785 " @t1 = <32 x i16>;\n",
786 Munger.getLinesWithSubstring("@t1"));
787 }
788
789 // Test i32 vector records in the types block.
790 TEST(NaClObjDumpTypesTest, TestI32VectorRecord) {
791 const uint64_t BitcodeRecords[] = {
792 1, 65535, 8, 2, Terminator,
793 1, 65535, 17, 2, Terminator,
794 3, 1, 2, Terminator,
795 3, 7, 32, Terminator,
796 3, 12, 4, 0, Terminator,
797 0, 65534, Terminator,
798 0, 65534, Terminator
799 };
800
801 const uint64_t ReplaceIndex = 4;
802
803 NaClObjDumpMunger Munger(BitcodeRecords,
804 array_lengthof(BitcodeRecords), Terminator);
805
806 // Test that we accept <4 x i32>.
807 EXPECT_TRUE(Munger.runTestForAssembly("Type <4 x i32>"));
808 EXPECT_EQ(
809 "module { // BlockID = 8\n"
810 " types { // BlockID = 17\n"
811 " count 2;\n"
812 " @t0 = i32;\n"
813 " @t1 = <4 x i32>;\n"
814 " }\n"
815 "}\n",
816 Munger.getTestResults());
817
818 // Test that we reject <1 x i32>.
819 const uint64_t Vector1xI32[] = {
820 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 1, 0, Terminator
821 };
822 EXPECT_FALSE(Munger.runTestForAssembly(
823 "Type <1 x i32>", Vector1xI32, array_lengthof(Vector1xI32)));
824 EXPECT_EQ(
825 "Error(37:6): Vector type <1 x i32> not allowed.\n",
826 Munger.getLinesWithPrefix(ErrorPrefix));
827 EXPECT_EQ(
828 " @t1 = <1 x i32>;\n",
829 Munger.getLinesWithSubstring("@t1"));
830
831 // Test that we don't handle <2 x i32>.
832 const uint64_t Vector2xI32[] = {
833 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 2, 0, Terminator
834 };
835 EXPECT_FALSE(Munger.runTestForAssembly(
836 "Type <2 x i32>", Vector2xI32, array_lengthof(Vector2xI32)));
837 EXPECT_EQ(
838 "Error(37:6): Vector type <2 x i32> not allowed.\n",
839 Munger.getLinesWithPrefix(ErrorPrefix));
840 EXPECT_EQ(
841 " @t1 = <2 x i32>;\n",
842 Munger.getLinesWithSubstring("@t1"));
843
844 // Test that we don't handle <3 x i32>.
845 const uint64_t Vector3xI32[] = {
846 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 3, 0, Terminator
847 };
848 EXPECT_FALSE(Munger.runTestForAssembly(
849 "Type <3 x i32>", Vector3xI32, array_lengthof(Vector3xI32)));
850 EXPECT_EQ(
851 "Error(37:6): Vector type <3 x i32> not allowed.\n",
852 Munger.getLinesWithPrefix(ErrorPrefix));
853 EXPECT_EQ(
854 " @t1 = <3 x i32>;\n",
855 Munger.getLinesWithSubstring("@t1"));
856
857 // Test that we don't handle <8 x i32>.
858 const uint64_t Vector8xI32[] = {
859 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 8, 0, Terminator
860 };
861 EXPECT_FALSE(Munger.runTestForAssembly(
862 "Type <8 x i32>", Vector8xI32, array_lengthof(Vector8xI32)));
863 EXPECT_EQ(
864 "Error(37:6): Vector type <8 x i32> not allowed.\n",
865 Munger.getLinesWithPrefix(ErrorPrefix));
866 EXPECT_EQ(
867 " @t1 = <8 x i32>;\n",
868 Munger.getLinesWithSubstring("@t1"));
869
870 // Test that we don't handle <16 x i32>.
871 const uint64_t Vector16xI32[] = {
872 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 16, 0, Terminator
873 };
874 EXPECT_FALSE(Munger.runTestForAssembly(
875 "Type <16 x i32>", Vector16xI32, array_lengthof(Vector16xI32)));
876 EXPECT_EQ(
877 "Error(37:6): Vector type <16 x i32> not allowed.\n",
878 Munger.getLinesWithPrefix(ErrorPrefix));
879 EXPECT_EQ(
880 " @t1 = <16 x i32>;\n",
881 Munger.getLinesWithSubstring("@t1"));
882
883 // Test that we don't handle <32 x i32>.
884 const uint64_t Vector32xI32[] = {
885 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 32, 0, Terminator
886 };
887 EXPECT_FALSE(Munger.runTestForAssembly(
888 "Type <32 x i32>", Vector32xI32, array_lengthof(Vector32xI32)));
889 EXPECT_EQ(
890 "Error(37:6): Vector type <32 x i32> not allowed.\n",
891 Munger.getLinesWithPrefix(ErrorPrefix));
892 EXPECT_EQ(
893 " @t1 = <32 x i32>;\n",
894 Munger.getLinesWithSubstring("@t1"));
895 }
896
897 // Test i64 vector types.
898 TEST(NaClObjDumpTypesTest, TestI64VectorRecord) {
899 const uint64_t BitcodeRecords[] = {
900 1, 65535, 8, 2, Terminator,
901 1, 65535, 17, 2, Terminator,
902 3, 1, 2, Terminator,
903 3, 7, 64, Terminator,
904 3, 12, 1, 0, Terminator,
905 0, 65534, Terminator,
906 0, 65534, Terminator
907 };
908
909 const uint64_t ReplaceIndex = 4;
910
911 NaClObjDumpMunger Munger(BitcodeRecords,
912 array_lengthof(BitcodeRecords), Terminator);
913
914 // Test that we reject <1 x i64>.
915 EXPECT_FALSE(Munger.runTestForAssembly("Type <1 x i64>"));
916 EXPECT_EQ(
917 "module { // BlockID = 8\n"
918 " types { // BlockID = 17\n"
919 " count 2;\n"
920 " @t0 = i64;\n"
921 " @t1 = <1 x i64>;\n"
922 "Error(37:6): Vector type <1 x i64> not allowed.\n"
923 " }\n"
924 "}\n",
925 Munger.getTestResults());
926
927 // Test that we don't handle <2 x i64>.
928 const uint64_t Vector2xI64[] = {
929 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 2, 0, Terminator
930 };
931 EXPECT_FALSE(Munger.runTestForAssembly(
932 "Type <2 x i64>", Vector2xI64, array_lengthof(Vector2xI64)));
933 EXPECT_EQ(
934 "Error(37:6): Vector type <2 x i64> not allowed.\n",
935 Munger.getLinesWithPrefix(ErrorPrefix));
936 EXPECT_EQ(
937 " @t1 = <2 x i64>;\n",
938 Munger.getLinesWithSubstring("@t1"));
939
940 // Test that we don't handle <3 x i64>.
941 const uint64_t Vector3xI64[] = {
942 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 3, 0, Terminator
943 };
944 EXPECT_FALSE(Munger.runTestForAssembly(
945 "Type <3 x i64>", Vector3xI64, array_lengthof(Vector3xI64)));
946 EXPECT_EQ(
947 "Error(37:6): Vector type <3 x i64> not allowed.\n",
948 Munger.getLinesWithPrefix(ErrorPrefix));
949 EXPECT_EQ(
950 " @t1 = <3 x i64>;\n",
951 Munger.getLinesWithSubstring("@t1"));
952
953 // Test that we reject <4 x i64>.
954 const uint64_t Vector4xI64[] = {
955 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 4, 0, Terminator
956 };
957 EXPECT_FALSE(Munger.runTestForAssembly(
958 "Type <4 x i64>", Vector4xI64, array_lengthof(Vector4xI64)));
959 EXPECT_EQ(
960 "Error(37:6): Vector type <4 x i64> not allowed.\n",
961 Munger.getLinesWithPrefix(ErrorPrefix));
962 EXPECT_EQ(
963 " @t1 = <4 x i64>;\n",
964 Munger.getLinesWithSubstring("@t1"));
965
966 // Test that we don't handle <8 x i64>.
967 const uint64_t Vector8xI64[] = {
968 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 8, 0, Terminator
969 };
970 EXPECT_FALSE(Munger.runTestForAssembly(
971 "Type <8 x i64>", Vector8xI64, array_lengthof(Vector8xI64)));
972 EXPECT_EQ(
973 "Error(37:6): Vector type <8 x i64> not allowed.\n",
974 Munger.getLinesWithPrefix(ErrorPrefix));
975 EXPECT_EQ(
976 " @t1 = <8 x i64>;\n",
977 Munger.getLinesWithSubstring("@t1"));
978
979 // Test that we don't handle <16 x i64>.
980 const uint64_t Vector16xI64[] = {
981 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 16, 0, Terminator
982 };
983 EXPECT_FALSE(Munger.runTestForAssembly(
984 "Type <16 x i64>", Vector16xI64, array_lengthof(Vector16xI64)));
985 EXPECT_EQ(
986 "Error(37:6): Vector type <16 x i64> not allowed.\n",
987 Munger.getLinesWithPrefix(ErrorPrefix));
988 EXPECT_EQ(
989 " @t1 = <16 x i64>;\n",
990 Munger.getLinesWithSubstring("@t1"));
991
992 // Test that we don't handle <32 x i64>.
993 const uint64_t Vector32xI64[] = {
994 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 32, 0, Terminator
995 };
996 EXPECT_FALSE(Munger.runTestForAssembly(
997 "Type <32 x i64>", Vector32xI64, array_lengthof(Vector32xI64)));
998 EXPECT_EQ(
999 "Error(37:6): Vector type <32 x i64> not allowed.\n",
1000 Munger.getLinesWithPrefix(ErrorPrefix));
1001 EXPECT_EQ(
1002 " @t1 = <32 x i64>;\n",
1003 Munger.getLinesWithSubstring("@t1"));
1004 }
1005
1006 // Test handling of float vector types.
1007 TEST(NaClObjDumpTypesTest, TestFloatVectorRecord) {
1008 const uint64_t BitcodeRecords[] = {
1009 1, 65535, 8, 2, Terminator,
1010 1, 65535, 17, 2, Terminator,
1011 3, 1, 2, Terminator,
1012 3, 3, Terminator,
1013 3, 12, 4, 0, Terminator,
1014 0, 65534, Terminator,
1015 0, 65534, Terminator
1016 };
1017
1018 const uint64_t ReplaceIndex = 4;
1019
1020 NaClObjDumpMunger Munger(BitcodeRecords,
1021 array_lengthof(BitcodeRecords), Terminator);
1022
1023 // Test that we accept <4 x float>.
1024 EXPECT_TRUE(Munger.runTestForAssembly("Type <4 x float>"));
1025 EXPECT_EQ(
1026 "module { // BlockID = 8\n"
1027 " types { // BlockID = 17\n"
1028 " count 2;\n"
1029 " @t0 = float;\n"
1030 " @t1 = <4 x float>;\n"
1031 " }\n"
1032 "}\n",
1033 Munger.getTestResults());
1034
1035 // Test that we reject <1 x float>.
1036 const uint64_t Vector1xFloat[] = {
1037 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 1, 0, Terminator
1038 };
1039 EXPECT_FALSE(Munger.runTestForAssembly(
1040 "Type <1 x float>", Vector1xFloat, array_lengthof(Vector1xFloat)));
1041 EXPECT_EQ(
1042 "Error(36:2): Vector type <1 x float> not allowed.\n",
1043 Munger.getLinesWithPrefix(ErrorPrefix));
1044 EXPECT_EQ(
1045 " @t1 = <1 x float>;\n",
1046 Munger.getLinesWithSubstring("@t1"));
1047
1048 // Test that we reject <2 x float>.
1049 const uint64_t Vector2xFloat[] = {
1050 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 2, 0, Terminator
1051 };
1052 EXPECT_FALSE(Munger.runTestForAssembly(
1053 "Type <2 x float>", Vector2xFloat, array_lengthof(Vector2xFloat)));
1054 EXPECT_EQ(
1055 "Error(36:2): Vector type <2 x float> not allowed.\n",
1056 Munger.getLinesWithPrefix(ErrorPrefix));
1057 EXPECT_EQ(
1058 " @t1 = <2 x float>;\n",
1059 Munger.getLinesWithSubstring("@t1"));
1060
1061 // Test that we reject <3 x float>.
1062 const uint64_t Vector3xFloat[] = {
1063 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 3, 0, Terminator
1064 };
1065 EXPECT_FALSE(Munger.runTestForAssembly(
1066 "Type <3 x float>", Vector3xFloat, array_lengthof(Vector3xFloat)));
1067 EXPECT_EQ(
1068 "Error(36:2): Vector type <3 x float> not allowed.\n",
1069 Munger.getLinesWithPrefix(ErrorPrefix));
1070 EXPECT_EQ(
1071 " @t1 = <3 x float>;\n",
1072 Munger.getLinesWithSubstring("@t1"));
1073
1074 // Test that we reject <8 x float>.
1075 const uint64_t Vector8xFloat[] = {
1076 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 8, 0, Terminator
1077 };
1078 EXPECT_FALSE(Munger.runTestForAssembly(
1079 "Type <8 x float>", Vector8xFloat, array_lengthof(Vector8xFloat)));
1080 EXPECT_EQ(
1081 "Error(36:2): Vector type <8 x float> not allowed.\n",
1082 Munger.getLinesWithPrefix(ErrorPrefix));
1083 EXPECT_EQ(
1084 " @t1 = <8 x float>;\n",
1085 Munger.getLinesWithSubstring("@t1"));
1086 }
1087
1088 // Test handling of double vector types.
1089 TEST(NaClObjDumpTypesTest, TestDoubleVectorRecord) {
1090 const uint64_t BitcodeRecords[] = {
1091 1, 65535, 8, 2, Terminator,
1092 1, 65535, 17, 2, Terminator,
1093 3, 1, 2, Terminator,
1094 3, 4, Terminator,
1095 3, 12, 4, 0, Terminator,
1096 0, 65534, Terminator,
1097 0, 65534, Terminator
1098 };
1099
1100 const uint64_t ReplaceIndex = 4;
1101
1102 NaClObjDumpMunger Munger(BitcodeRecords,
1103 array_lengthof(BitcodeRecords), Terminator);
1104
1105 // Test that we reject <4 x double>.
1106 EXPECT_FALSE(Munger.runTestForAssembly("Type <4 x double>"));
1107 EXPECT_EQ(
1108 "module { // BlockID = 8\n"
1109 " types { // BlockID = 17\n"
1110 " count 2;\n"
1111 " @t0 = double;\n"
1112 " @t1 = <4 x double>;\n"
1113 "Error(36:2): Vector type <4 x double> not allowed.\n"
1114 " }\n"
1115 "}\n",
1116 Munger.getTestResults());
1117
1118 // Test that we reject <1 x double>.
1119 const uint64_t Vector1xDouble[] = {
1120 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 1, 0, Terminator
1121 };
1122 EXPECT_FALSE(Munger.runTestForAssembly(
1123 "Type <1 x double>", Vector1xDouble, array_lengthof(Vector1xDouble)));
1124 EXPECT_EQ(
1125 "Error(36:2): Vector type <1 x double> not allowed.\n",
1126 Munger.getLinesWithPrefix(ErrorPrefix));
1127 EXPECT_EQ(
1128 " @t1 = <1 x double>;\n",
1129 Munger.getLinesWithSubstring("@t1"));
1130
1131 // Test that we reject <2 x double>.
1132 const uint64_t Vector2xDouble[] = {
1133 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 2, 0, Terminator
1134 };
1135 EXPECT_FALSE(Munger.runTestForAssembly(
1136 "Type <2 x double>", Vector2xDouble, array_lengthof(Vector2xDouble)));
1137 EXPECT_EQ(
1138 "Error(36:2): Vector type <2 x double> not allowed.\n",
1139 Munger.getLinesWithPrefix(ErrorPrefix));
1140 EXPECT_EQ(
1141 " @t1 = <2 x double>;\n",
1142 Munger.getLinesWithSubstring("@t1"));
1143
1144 // Test that we reject <4 x double>.
1145 const uint64_t Vector3xDouble[] = {
1146 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 4, 0, Terminator
1147 };
1148 EXPECT_FALSE(Munger.runTestForAssembly(
1149 "Type <4 x double>", Vector3xDouble, array_lengthof(Vector3xDouble)));
1150 EXPECT_EQ(
1151 "Error(36:2): Vector type <4 x double> not allowed.\n",
1152 Munger.getLinesWithPrefix(ErrorPrefix));
1153 EXPECT_EQ(
1154 " @t1 = <4 x double>;\n",
1155 Munger.getLinesWithSubstring("@t1"));
1156
1157 // Test that we reject <8 x double>.
1158 const uint64_t Vector8xDouble[] = {
1159 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 12, 8, 0, Terminator
1160 };
1161 EXPECT_FALSE(Munger.runTestForAssembly(
1162 "Type <8 x double>", Vector8xDouble, array_lengthof(Vector8xDouble)));
1163 EXPECT_EQ(
1164 "Error(36:2): Vector type <8 x double> not allowed.\n",
1165 Munger.getLinesWithPrefix(ErrorPrefix));
1166 EXPECT_EQ(
1167 " @t1 = <8 x double>;\n",
1168 Munger.getLinesWithSubstring("@t1"));
1169 }
1170
1171 // Tests that we don't accept vectors of type void.
1172 TEST(NaClObjDumpTypesTest, TestVoidVectorRecord) {
1173 const uint64_t BitcodeRecords[] = {
1174 1, 65535, 8, 2, Terminator,
1175 1, 65535, 17, 2, Terminator,
1176 3, 1, 2, Terminator,
1177 3, 2, Terminator,
1178 3, 12, 4, 0, Terminator,
1179 0, 65534, Terminator,
1180 0, 65534, Terminator
1181 };
1182 NaClObjDumpMunger Munger(BitcodeRecords,
1183 array_lengthof(BitcodeRecords), Terminator);
1184 EXPECT_FALSE(Munger.runTestForAssembly("Type <4 x void>"));
1185 EXPECT_EQ(
1186 "module { // BlockID = 8\n"
1187 " types { // BlockID = 17\n"
1188 " count 2;\n"
1189 " @t0 = void;\n"
1190 " @t1 = <4 x i32>;\n"
1191 "Error(36:2): Vectors can only be defined on primitive types. "
1192 "Found void. Assuming i32 instead.\n"
1193 " }\n"
1194 "}\n",
1195 Munger.getTestResults());
1196 }
1197
1198 // Tests that we don't allow vectors of vectors.
1199 TEST(NaClObjDumpTypesTest, TestNestedVectorRecord) {
1200 const uint64_t BitcodeRecords[] = {
1201 1, 65535, 8, 2, Terminator,
1202 1, 65535, 17, 2, Terminator,
1203 3, 1, 3, Terminator,
1204 3, 3, Terminator,
1205 3, 12, 4, 0, Terminator,
1206 3, 12, 4, 1, Terminator,
1207 0, 65534, Terminator,
1208 0, 65534, Terminator
1209 };
1210 NaClObjDumpMunger Munger(BitcodeRecords,
1211 array_lengthof(BitcodeRecords), Terminator);
1212 EXPECT_FALSE(Munger.runTestForAssembly("Type <4 x <4 x float>>"));
1213 EXPECT_EQ(
1214 "module { // BlockID = 8\n"
1215 " types { // BlockID = 17\n"
1216 " count 3;\n"
1217 " @t0 = float;\n"
1218 " @t1 = <4 x float>;\n"
1219 " @t2 = <4 x i32>;\n"
1220 "Error(39:4): Vectors can only be defined on primitive types. "
1221 "Found <4 x float>. Assuming i32 instead.\n"
1222 " }\n"
1223 "}\n",
1224 Munger.getTestResults());
1225 }
1226
1227 // Test handling of the function record in the types block.
1228 TEST(NaClObjDumpTypesTest, TestFunctionRecord) {
1229 const uint64_t BitcodeRecords[] = {
1230 1, 65535, 8, 2, Terminator,
1231 1, 65535, 17, 2, Terminator,
1232 3, 1, 7, Terminator,
1233 3, 2, Terminator,
1234 3, 7, 16, Terminator,
1235 3, 7, 32, Terminator,
1236 3, 3, Terminator,
1237 3, 4, Terminator,
1238 3, 12, 4, 2, Terminator,
1239 3, 21, 0, 0, Terminator,
1240 0, 65534, Terminator,
1241 0, 65534, Terminator
1242 };
1243
1244 const uint64_t TypeCountIndex = 2;
1245 const uint64_t ReplaceIndex = 9;
1246
1247 NaClObjDumpMunger Munger(BitcodeRecords,
1248 array_lengthof(BitcodeRecords), Terminator);
1249
1250 // Test void() signature.
1251 EXPECT_TRUE(Munger.runTestForAssembly("Type void()"));
1252 EXPECT_EQ(
1253 "module { // BlockID = 8\n"
1254 " types { // BlockID = 17\n"
1255 " count 7;\n"
1256 " @t0 = void;\n"
1257 " @t1 = i16;\n"
1258 " @t2 = i32;\n"
1259 " @t3 = float;\n"
1260 " @t4 = double;\n"
1261 " @t5 = <4 x i32>;\n"
1262 " @t6 = void ();\n"
1263 " }\n}\n",
1264 Munger.getTestResults());
1265 EXPECT_EQ(
1266 " @t6 = void ();\n",
1267 Munger.getLinesWithSubstring("@t6"));
1268
1269 // Tests using integers for parameters and return types.
1270 const uint64_t UsesIntegerTypes[] = {
1271 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 21, 0, 1, 2, 1, Terminator
1272 };
1273 EXPECT_TRUE(Munger.runTestForAssembly(
1274 "Function record with integer types", UsesIntegerTypes,
1275 array_lengthof(UsesIntegerTypes)));
1276 EXPECT_EQ(
1277 " @t6 = i16 (i32, i16);\n",
1278 Munger.getLinesWithSubstring("@t6"));
1279
1280 // Test using float point types for parameters and return types.
1281 const uint64_t UsesFloatingTypes[] = {
1282 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 21, 0, 3, 3, 4, Terminator
1283 };
1284 EXPECT_TRUE(Munger.runTestForAssembly(
1285 "Function record with floating point types", UsesFloatingTypes,
1286 array_lengthof(UsesFloatingTypes)));
1287 EXPECT_EQ(
1288 " @t6 = float (float, double);\n",
1289 Munger.getLinesWithSubstring("@t6"));
1290
1291 // Test using vector types for parameters and return types.
1292 const uint64_t UsesVectorTypes[] = {
1293 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 21, 0, 5, 5, Terminator
1294 };
1295 EXPECT_TRUE(Munger.runTestForAssembly(
1296 "Function record with vector types", UsesVectorTypes,
1297 array_lengthof(UsesVectorTypes)));
1298 EXPECT_EQ(
1299 " @t6 = <4 x i32> (<4 x i32>);\n",
1300 Munger.getLinesWithSubstring("@t6"));
1301
1302 // Test error if function record is too short.
1303 const uint64_t FunctionRecordTooShort[] = {
1304 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 21, 0, Terminator
1305 };
1306 EXPECT_FALSE(Munger.runTestForAssembly(
1307 "Function record too short", FunctionRecordTooShort,
1308 array_lengthof(FunctionRecordTooShort)));
1309 EXPECT_EQ(
1310 "Error(48:6): Function record should contain at least 2 arguments. "
1311 "Found: 1\n",
1312 Munger.getLinesWithPrefix(ErrorPrefix));
1313 EXPECT_EQ(
1314 " @t6 = void;\n",
1315 Munger.getLinesWithSubstring("@t6"));
1316
1317 // Tests errror if function record specifies varargs.
1318 const uint64_t FunctionRecordWithVarArgs[] = {
1319 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 21, 1, 0, Terminator
1320 };
1321 EXPECT_FALSE(
1322 Munger.runTestForAssembly(
1323 "Function record with varargs", FunctionRecordWithVarArgs,
1324 array_lengthof(FunctionRecordWithVarArgs)));
1325 EXPECT_EQ(
1326 "Error(48:6): Functions with variable length arguments is "
1327 "not supported\n",
1328 Munger.getLinesWithPrefix(ErrorPrefix));
1329 EXPECT_EQ(
1330 " @t6 = void (...);\n",
1331 Munger.getLinesWithSubstring("@t6"));
1332
1333 // Tests if void is used as a parameter type.
1334 const uint64_t VoidParamType[] = {
1335 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 21, 0, 0, 0, Terminator
1336 };
1337 EXPECT_FALSE(Munger.runTestForAssembly(
1338 "Function record with void param type", VoidParamType,
1339 array_lengthof(VoidParamType)));
1340 EXPECT_EQ(
1341 "Error(48:6): Invalid type for parameter 1. Found: void. Assuming: i32\n",
1342 Munger.getLinesWithPrefix(ErrorPrefix));
1343 EXPECT_EQ(
1344 " @t6 = void (i32);\n",
1345 Munger.getLinesWithSubstring("@t6"));
1346
1347 // Tests using a function type as the return type.
1348 const uint64_t FunctionReturnType[] = {
1349 TypeCountIndex, NaClBitcodeMunger::Replace, 3, 1, 8, Terminator,
1350 ReplaceIndex, NaClBitcodeMunger::AddAfter, 3, 21, 0, 6, Terminator
1351 };
1352 EXPECT_FALSE(
1353 Munger.runTestForAssembly(
1354 "Function record with function return type", FunctionReturnType,
1355 array_lengthof(FunctionReturnType)));
1356 EXPECT_EQ(
1357 "Error(52:0): Invalid return type. Found: void (). Assuming: i32\n",
1358 Munger.getLinesWithPrefix(ErrorPrefix));
1359 EXPECT_EQ(
1360 " @t6 = void ();\n",
1361 Munger.getLinesWithSubstring("@t6"));
1362 EXPECT_EQ(
1363 " @t7 = i32 ();\n",
1364 Munger.getLinesWithSubstring("@t7"));
1365
1366 // Tests using a function type as a parameter type.
1367 const uint64_t FunctionParamType[] = {
1368 TypeCountIndex, NaClBitcodeMunger::Replace, 3, 1, 8, Terminator,
1369 ReplaceIndex, NaClBitcodeMunger::AddAfter, 3, 21, 0, 0, 6, Terminator
1370 };
1371 EXPECT_FALSE(
1372 Munger.runTestForAssembly(
1373 "Function record with function param type", FunctionParamType,
1374 array_lengthof(FunctionParamType)));
1375 EXPECT_EQ(
1376 "Error(52:0): Invalid type for parameter 1. Found: void (). "
1377 "Assuming: i32\n",
1378 Munger.getLinesWithPrefix(ErrorPrefix));
1379 EXPECT_EQ(
1380 " @t6 = void ();\n",
1381 Munger.getLinesWithSubstring("@t6"));
1382 EXPECT_EQ(
1383 " @t7 = void (i32);\n",
1384 Munger.getLinesWithSubstring("@t7"));
1385 }
1386
1387 // Tests how we report unknown record codes in the types block.
1388 TEST(NaClObjDumpTypesTest, TestUnknownTypesRecordCode) {
1389 const uint64_t BitcodeRecords[] = {
1390 1, 65535, 8, 2, Terminator,
1391 1, 65535, 17, 2, Terminator,
1392 3, 1, 1, Terminator,
1393 3, 10, Terminator,
1394 0, 65534, Terminator,
1395 0, 65534, Terminator
1396 };
1397 NaClObjDumpMunger Munger(BitcodeRecords,
1398 array_lengthof(BitcodeRecords), Terminator);
1399 EXPECT_FALSE(Munger.runTestForAssembly("Unknown types record code"));
1400 EXPECT_EQ(
1401 "module { // BlockID = 8\n"
1402 " types { // BlockID = 17\n"
1403 " count 1;\n"
1404 "Error(34:4): Unknown record code in types block. Found: 10\n"
1405 " }\n"
1406 "Error(36:2): Expected 1 types but found: 0\n"
1407 "}\n",
1408 Munger.getTestResults());
1409 }
1410
1411 } // End of anonymous namespace.
OLDNEW
« no previous file with comments | « unittests/Bitcode/NaClObjDumpTest.cpp ('k') | unittests/Bitcode/NaClParseInstsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698