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