| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169 |
- // Copyright (c) 2016 Google Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- #include <vector>
- #include "gmock/gmock.h"
- #include "test/opt/pass_fixture.h"
- namespace spvtools {
- namespace opt {
- namespace {
- using testing::Eq;
- using SpecIdToValueStrMap =
- SetSpecConstantDefaultValuePass::SpecIdToValueStrMap;
- using SpecIdToValueBitPatternMap =
- SetSpecConstantDefaultValuePass::SpecIdToValueBitPatternMap;
- struct DefaultValuesStringParsingTestCase {
- const char* default_values_str;
- bool expect_success;
- SpecIdToValueStrMap expected_map;
- };
- using DefaultValuesStringParsingTest =
- ::testing::TestWithParam<DefaultValuesStringParsingTestCase>;
- TEST_P(DefaultValuesStringParsingTest, TestCase) {
- const auto& tc = GetParam();
- auto actual_map = SetSpecConstantDefaultValuePass::ParseDefaultValuesString(
- tc.default_values_str);
- if (tc.expect_success) {
- EXPECT_NE(nullptr, actual_map);
- if (actual_map) {
- EXPECT_THAT(*actual_map, Eq(tc.expected_map));
- }
- } else {
- EXPECT_EQ(nullptr, actual_map);
- }
- }
- INSTANTIATE_TEST_SUITE_P(
- ValidString, DefaultValuesStringParsingTest,
- ::testing::ValuesIn(std::vector<DefaultValuesStringParsingTestCase>{
- // 0. empty map
- {"", true, SpecIdToValueStrMap{}},
- // 1. one pair
- {"100:1024", true, SpecIdToValueStrMap{{100, "1024"}}},
- // 2. two pairs
- {"100:1024 200:2048", true,
- SpecIdToValueStrMap{{100, "1024"}, {200, "2048"}}},
- // 3. spaces between entries
- {"100:1024 \n \r \t \v \f 200:2048", true,
- SpecIdToValueStrMap{{100, "1024"}, {200, "2048"}}},
- // 4. \t, \n, \r and spaces before spec id
- {" \n \r\t \t \v \f 100:1024", true,
- SpecIdToValueStrMap{{100, "1024"}}},
- // 5. \t, \n, \r and spaces after value string
- {"100:1024 \n \r\t \t \v \f ", true,
- SpecIdToValueStrMap{{100, "1024"}}},
- // 6. maximum spec id
- {"4294967295:0", true, SpecIdToValueStrMap{{4294967295, "0"}}},
- // 7. minimum spec id
- {"0:100", true, SpecIdToValueStrMap{{0, "100"}}},
- // 8. random content without spaces are allowed
- {"200:random_stuff", true, SpecIdToValueStrMap{{200, "random_stuff"}}},
- // 9. support hex format spec id (just because we use the
- // ParseNumber() utility)
- {"0x100:1024", true, SpecIdToValueStrMap{{256, "1024"}}},
- // 10. multiple entries
- {"101:1 102:2 103:3 104:4 200:201 9999:1000 0x100:333", true,
- SpecIdToValueStrMap{{101, "1"},
- {102, "2"},
- {103, "3"},
- {104, "4"},
- {200, "201"},
- {9999, "1000"},
- {256, "333"}}},
- // 11. default value in hex float format
- {"100:0x0.3p10", true, SpecIdToValueStrMap{{100, "0x0.3p10"}}},
- // 12. default value in decimal float format
- {"100:1.5e-13", true, SpecIdToValueStrMap{{100, "1.5e-13"}}},
- }));
- INSTANTIATE_TEST_SUITE_P(
- InvalidString, DefaultValuesStringParsingTest,
- ::testing::ValuesIn(std::vector<DefaultValuesStringParsingTestCase>{
- // 0. missing default value
- {"100:", false, SpecIdToValueStrMap{}},
- // 1. spec id is not an integer
- {"100.0:200", false, SpecIdToValueStrMap{}},
- // 2. spec id is not a number
- {"something_not_a_number:1", false, SpecIdToValueStrMap{}},
- // 3. only spec id number
- {"100", false, SpecIdToValueStrMap{}},
- // 4. same spec id defined multiple times
- {"100:20 100:21", false, SpecIdToValueStrMap{}},
- // 5. Multiple definition of an identical spec id in different forms
- // is not allowed
- {"0x100:100 256:200", false, SpecIdToValueStrMap{}},
- // 6. empty spec id
- {":3", false, SpecIdToValueStrMap{}},
- // 7. only colon
- {":", false, SpecIdToValueStrMap{}},
- // 8. spec id overflow
- {"4294967296:200", false, SpecIdToValueStrMap{}},
- // 9. spec id less than 0
- {"-1:200", false, SpecIdToValueStrMap{}},
- // 10. nullptr
- {nullptr, false, SpecIdToValueStrMap{}},
- // 11. only a number is invalid
- {"1234", false, SpecIdToValueStrMap{}},
- // 12. invalid entry separator
- {"12:34;23:14", false, SpecIdToValueStrMap{}},
- // 13. invalid spec id and default value separator
- {"12@34", false, SpecIdToValueStrMap{}},
- // 14. spaces before colon
- {"100 :1024", false, SpecIdToValueStrMap{}},
- // 15. spaces after colon
- {"100: 1024", false, SpecIdToValueStrMap{}},
- // 16. spec id represented in hex float format is invalid
- {"0x3p10:200", false, SpecIdToValueStrMap{}},
- }));
- struct SetSpecConstantDefaultValueInStringFormTestCase {
- const char* code;
- SpecIdToValueStrMap default_values;
- const char* expected;
- };
- using SetSpecConstantDefaultValueInStringFormParamTest = PassTest<
- ::testing::TestWithParam<SetSpecConstantDefaultValueInStringFormTestCase>>;
- TEST_P(SetSpecConstantDefaultValueInStringFormParamTest, TestCase) {
- const auto& tc = GetParam();
- SinglePassRunAndCheck<SetSpecConstantDefaultValuePass>(
- tc.code, tc.expected, /* skip_nop = */ false, tc.default_values);
- }
- INSTANTIATE_TEST_SUITE_P(
- ValidCases, SetSpecConstantDefaultValueInStringFormParamTest,
- ::testing::ValuesIn(std::vector<
- SetSpecConstantDefaultValueInStringFormTestCase>{
- // 0. Empty.
- {"", SpecIdToValueStrMap{}, ""},
- // 1. Empty with non-empty values to set.
- {"", SpecIdToValueStrMap{{1, "100"}, {2, "200"}}, ""},
- // 2. Bool type.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "%bool = OpTypeBool\n"
- "%1 = OpSpecConstantTrue %bool\n"
- "%2 = OpSpecConstantFalse %bool\n",
- // default values
- SpecIdToValueStrMap{{100, "false"}, {101, "true"}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "%bool = OpTypeBool\n"
- "%1 = OpSpecConstantFalse %bool\n"
- "%2 = OpSpecConstantTrue %bool\n",
- },
- // 3. 32-bit int type.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "%int = OpTypeInt 32 1\n"
- "%1 = OpSpecConstant %int 10\n"
- "%2 = OpSpecConstant %int 11\n"
- "%3 = OpSpecConstant %int 11\n",
- // default values
- SpecIdToValueStrMap{
- {100, "2147483647"}, {101, "0xffffffff"}, {102, "-42"}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "%int = OpTypeInt 32 1\n"
- "%1 = OpSpecConstant %int 2147483647\n"
- "%2 = OpSpecConstant %int -1\n"
- "%3 = OpSpecConstant %int -42\n",
- },
- // 4. 64-bit uint type.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "%ulong = OpTypeInt 64 0\n"
- "%1 = OpSpecConstant %ulong 10\n"
- "%2 = OpSpecConstant %ulong 11\n",
- // default values
- SpecIdToValueStrMap{{100, "18446744073709551614"}, {101, "0x100"}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "%ulong = OpTypeInt 64 0\n"
- "%1 = OpSpecConstant %ulong 18446744073709551614\n"
- "%2 = OpSpecConstant %ulong 256\n",
- },
- // 5. 32-bit float type.
- {
- // code
- "OpDecorate %1 SpecId 101\n"
- "OpDecorate %2 SpecId 102\n"
- "%float = OpTypeFloat 32\n"
- "%1 = OpSpecConstant %float 200\n"
- "%2 = OpSpecConstant %float 201\n",
- // default values
- SpecIdToValueStrMap{{101, "-0x1.fffffep+128"}, {102, "2.5"}},
- // expected
- "OpDecorate %1 SpecId 101\n"
- "OpDecorate %2 SpecId 102\n"
- "%float = OpTypeFloat 32\n"
- "%1 = OpSpecConstant %float -0x1.fffffep+128\n"
- "%2 = OpSpecConstant %float 2.5\n",
- },
- // 6. 64-bit float type.
- {
- // code
- "OpDecorate %1 SpecId 201\n"
- "OpDecorate %2 SpecId 202\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %double 3.14159265358979\n"
- "%2 = OpSpecConstant %double 0.14285\n",
- // default values
- SpecIdToValueStrMap{{201, "0x1.fffffffffffffp+1024"},
- {202, "-32.5"}},
- // expected
- "OpDecorate %1 SpecId 201\n"
- "OpDecorate %2 SpecId 202\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %double 0x1.fffffffffffffp+1024\n"
- "%2 = OpSpecConstant %double -32.5\n",
- },
- // 7. SpecId not found, expect no modification.
- {
- // code
- "OpDecorate %1 SpecId 201\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %double 3.14159265358979\n",
- // default values
- SpecIdToValueStrMap{{8888, "0.0"}},
- // expected
- "OpDecorate %1 SpecId 201\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %double 3.14159265358979\n",
- },
- // 8. Multiple types of spec constants.
- {
- // code
- "OpDecorate %1 SpecId 201\n"
- "OpDecorate %2 SpecId 202\n"
- "OpDecorate %3 SpecId 203\n"
- "%bool = OpTypeBool\n"
- "%int = OpTypeInt 32 1\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %double 3.14159265358979\n"
- "%2 = OpSpecConstant %int 1024\n"
- "%3 = OpSpecConstantTrue %bool\n",
- // default values
- SpecIdToValueStrMap{
- {201, "0x1.fffffffffffffp+1024"},
- {202, "2048"},
- {203, "false"},
- },
- // expected
- "OpDecorate %1 SpecId 201\n"
- "OpDecorate %2 SpecId 202\n"
- "OpDecorate %3 SpecId 203\n"
- "%bool = OpTypeBool\n"
- "%int = OpTypeInt 32 1\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %double 0x1.fffffffffffffp+1024\n"
- "%2 = OpSpecConstant %int 2048\n"
- "%3 = OpSpecConstantFalse %bool\n",
- },
- // 9. Ignore other decorations.
- {
- // code
- "OpDecorate %1 ArrayStride 4\n"
- "%int = OpTypeInt 32 1\n"
- "%1 = OpSpecConstant %int 100\n",
- // default values
- SpecIdToValueStrMap{{4, "0x7fffffff"}},
- // expected
- "OpDecorate %1 ArrayStride 4\n"
- "%int = OpTypeInt 32 1\n"
- "%1 = OpSpecConstant %int 100\n",
- },
- // 10. Distinguish from other decorations.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %1 ArrayStride 4\n"
- "%int = OpTypeInt 32 1\n"
- "%1 = OpSpecConstant %int 100\n",
- // default values
- SpecIdToValueStrMap{{4, "0x7fffffff"}, {100, "0xffffffff"}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %1 ArrayStride 4\n"
- "%int = OpTypeInt 32 1\n"
- "%1 = OpSpecConstant %int -1\n",
- },
- // 11. Decorate through decoration group.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 100\n",
- // default values
- SpecIdToValueStrMap{{100, "0x7fffffff"}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 2147483647\n",
- },
- // 12. Ignore other decorations in decoration group.
- {
- // code
- "OpDecorate %1 ArrayStride 4\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 100\n",
- // default values
- SpecIdToValueStrMap{{4, "0x7fffffff"}},
- // expected
- "OpDecorate %1 ArrayStride 4\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 100\n",
- },
- // 13. Distinguish from other decorations in decoration group.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %1 ArrayStride 4\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 100\n",
- // default values
- SpecIdToValueStrMap{{100, "0x7fffffff"}, {4, "0x00000001"}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %1 ArrayStride 4\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 2147483647\n",
- },
- // 14. Unchanged bool default value
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "%bool = OpTypeBool\n"
- "%1 = OpSpecConstantTrue %bool\n"
- "%2 = OpSpecConstantFalse %bool\n",
- // default values
- SpecIdToValueStrMap{{100, "true"}, {101, "false"}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "%bool = OpTypeBool\n"
- "%1 = OpSpecConstantTrue %bool\n"
- "%2 = OpSpecConstantFalse %bool\n",
- },
- // 15. Unchanged int default values
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "%int = OpTypeInt 32 1\n"
- "%ulong = OpTypeInt 64 0\n"
- "%1 = OpSpecConstant %int 10\n"
- "%2 = OpSpecConstant %ulong 11\n",
- // default values
- SpecIdToValueStrMap{{100, "10"}, {101, "11"}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "%int = OpTypeInt 32 1\n"
- "%ulong = OpTypeInt 64 0\n"
- "%1 = OpSpecConstant %int 10\n"
- "%2 = OpSpecConstant %ulong 11\n",
- },
- // 16. Unchanged float default values
- {
- // code
- "OpDecorate %1 SpecId 201\n"
- "OpDecorate %2 SpecId 202\n"
- "%float = OpTypeFloat 32\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %float 3.1415\n"
- "%2 = OpSpecConstant %double 0.14285\n",
- // default values
- SpecIdToValueStrMap{{201, "3.1415"}, {202, "0.14285"}},
- // expected
- "OpDecorate %1 SpecId 201\n"
- "OpDecorate %2 SpecId 202\n"
- "%float = OpTypeFloat 32\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %float 3.1415\n"
- "%2 = OpSpecConstant %double 0.14285\n",
- },
- // 17. OpGroupDecorate may have multiple target ids defined by the same
- // eligible spec constant
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2 %2 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 100\n",
- // default values
- SpecIdToValueStrMap{{100, "0xffffffff"}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2 %2 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int -1\n",
- },
- }));
- INSTANTIATE_TEST_SUITE_P(
- InvalidCases, SetSpecConstantDefaultValueInStringFormParamTest,
- ::testing::ValuesIn(std::vector<
- SetSpecConstantDefaultValueInStringFormTestCase>{
- // 0. Do not crash when decoration group is not used.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "%int = OpTypeInt 32 1\n"
- "%3 = OpSpecConstant %int 100\n",
- // default values
- SpecIdToValueStrMap{{100, "0x7fffffff"}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "%int = OpTypeInt 32 1\n"
- "%3 = OpSpecConstant %int 100\n",
- },
- // 1. Do not crash when target does not exist.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "%int = OpTypeInt 32 1\n",
- // default values
- SpecIdToValueStrMap{{100, "0x7fffffff"}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "%int = OpTypeInt 32 1\n",
- },
- // 2. Do nothing when SpecId decoration is not attached to a
- // non-spec-constant instruction.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "%int = OpTypeInt 32 1\n"
- "%int_101 = OpConstant %int 101\n",
- // default values
- SpecIdToValueStrMap{{100, "0x7fffffff"}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "%int = OpTypeInt 32 1\n"
- "%int_101 = OpConstant %int 101\n",
- },
- // 3. Do nothing when SpecId decoration is not attached to a
- // OpSpecConstant{|True|False} instruction.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "%int = OpTypeInt 32 1\n"
- "%3 = OpSpecConstant %int 101\n"
- "%1 = OpSpecConstantOp %int IAdd %3 %3\n",
- // default values
- SpecIdToValueStrMap{{100, "0x7fffffff"}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "%int = OpTypeInt 32 1\n"
- "%3 = OpSpecConstant %int 101\n"
- "%1 = OpSpecConstantOp %int IAdd %3 %3\n",
- },
- // 4. Do not crash and do nothing when SpecId decoration is applied to
- // multiple spec constants.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2 %3 %4\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 100\n"
- "%3 = OpSpecConstant %int 200\n"
- "%4 = OpSpecConstant %int 300\n",
- // default values
- SpecIdToValueStrMap{{100, "0xffffffff"}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2 %3 %4\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 100\n"
- "%3 = OpSpecConstant %int 200\n"
- "%4 = OpSpecConstant %int 300\n",
- },
- // 5. Do not crash and do nothing when SpecId decoration is attached to
- // non-spec-constants (invalid case).
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "%2 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%int_100 = OpConstant %int 100\n",
- // default values
- SpecIdToValueStrMap{{100, "0xffffffff"}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "%2 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%int_100 = OpConstant %int 100\n",
- },
- // 6. Boolean type spec constant cannot be set with numeric values in
- // string form. i.e. only 'true' and 'false' are acceptable for setting
- // boolean type spec constants. Nothing should be done if numeric values
- // in string form are provided.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "OpDecorate %4 SpecId 103\n"
- "OpDecorate %5 SpecId 104\n"
- "OpDecorate %6 SpecId 105\n"
- "%bool = OpTypeBool\n"
- "%1 = OpSpecConstantTrue %bool\n"
- "%2 = OpSpecConstantFalse %bool\n"
- "%3 = OpSpecConstantTrue %bool\n"
- "%4 = OpSpecConstantTrue %bool\n"
- "%5 = OpSpecConstantTrue %bool\n"
- "%6 = OpSpecConstantFalse %bool\n",
- // default values
- SpecIdToValueStrMap{{100, "0"},
- {101, "1"},
- {102, "0x0"},
- {103, "0.0"},
- {104, "-0.0"},
- {105, "0x12345678"}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "OpDecorate %4 SpecId 103\n"
- "OpDecorate %5 SpecId 104\n"
- "OpDecorate %6 SpecId 105\n"
- "%bool = OpTypeBool\n"
- "%1 = OpSpecConstantTrue %bool\n"
- "%2 = OpSpecConstantFalse %bool\n"
- "%3 = OpSpecConstantTrue %bool\n"
- "%4 = OpSpecConstantTrue %bool\n"
- "%5 = OpSpecConstantTrue %bool\n"
- "%6 = OpSpecConstantFalse %bool\n",
- },
- }));
- struct SetSpecConstantDefaultValueInBitPatternFormTestCase {
- const char* code;
- SpecIdToValueBitPatternMap default_values;
- const char* expected;
- };
- using SetSpecConstantDefaultValueInBitPatternFormParamTest =
- PassTest<::testing::TestWithParam<
- SetSpecConstantDefaultValueInBitPatternFormTestCase>>;
- TEST_P(SetSpecConstantDefaultValueInBitPatternFormParamTest, TestCase) {
- const auto& tc = GetParam();
- SinglePassRunAndCheck<SetSpecConstantDefaultValuePass>(
- tc.code, tc.expected, /* skip_nop = */ false, tc.default_values);
- }
- INSTANTIATE_TEST_SUITE_P(
- ValidCases, SetSpecConstantDefaultValueInBitPatternFormParamTest,
- ::testing::ValuesIn(std::vector<
- SetSpecConstantDefaultValueInBitPatternFormTestCase>{
- // 0. Empty.
- {"", SpecIdToValueBitPatternMap{}, ""},
- // 1. Empty with non-empty values to set.
- {"", SpecIdToValueBitPatternMap{{1, {100}}, {2, {200}}}, ""},
- // 2. Basic bool type.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "%bool = OpTypeBool\n"
- "%1 = OpSpecConstantTrue %bool\n"
- "%2 = OpSpecConstantFalse %bool\n",
- // default values
- SpecIdToValueBitPatternMap{{100, {0x0}}, {101, {0x1}}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "%bool = OpTypeBool\n"
- "%1 = OpSpecConstantFalse %bool\n"
- "%2 = OpSpecConstantTrue %bool\n",
- },
- // 3. 32-bit int type.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "%int = OpTypeInt 32 1\n"
- "%1 = OpSpecConstant %int 10\n"
- "%2 = OpSpecConstant %int 11\n"
- "%3 = OpSpecConstant %int 11\n",
- // default values
- SpecIdToValueBitPatternMap{
- {100, {2147483647}}, {101, {0xffffffff}}, {102, {0xffffffd6}}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "%int = OpTypeInt 32 1\n"
- "%1 = OpSpecConstant %int 2147483647\n"
- "%2 = OpSpecConstant %int -1\n"
- "%3 = OpSpecConstant %int -42\n",
- },
- // 4. 64-bit uint type.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "%ulong = OpTypeInt 64 0\n"
- "%1 = OpSpecConstant %ulong 10\n"
- "%2 = OpSpecConstant %ulong 11\n",
- // default values
- SpecIdToValueBitPatternMap{{100, {0xFFFFFFFE, 0xFFFFFFFF}},
- {101, {0x100, 0x0}}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "%ulong = OpTypeInt 64 0\n"
- "%1 = OpSpecConstant %ulong 18446744073709551614\n"
- "%2 = OpSpecConstant %ulong 256\n",
- },
- // 5. 32-bit float type.
- {
- // code
- "OpDecorate %1 SpecId 101\n"
- "OpDecorate %2 SpecId 102\n"
- "%float = OpTypeFloat 32\n"
- "%1 = OpSpecConstant %float 200\n"
- "%2 = OpSpecConstant %float 201\n",
- // default values
- SpecIdToValueBitPatternMap{{101, {0xffffffff}},
- {102, {0x40200000}}},
- // expected
- "OpDecorate %1 SpecId 101\n"
- "OpDecorate %2 SpecId 102\n"
- "%float = OpTypeFloat 32\n"
- "%1 = OpSpecConstant %float -0x1.fffffep+128\n"
- "%2 = OpSpecConstant %float 2.5\n",
- },
- // 6. 64-bit float type.
- {
- // code
- "OpDecorate %1 SpecId 201\n"
- "OpDecorate %2 SpecId 202\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %double 3.14159265358979\n"
- "%2 = OpSpecConstant %double 0.14285\n",
- // default values
- SpecIdToValueBitPatternMap{{201, {0xffffffff, 0x7fffffff}},
- {202, {0x00000000, 0xc0404000}}},
- // expected
- "OpDecorate %1 SpecId 201\n"
- "OpDecorate %2 SpecId 202\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %double 0x1.fffffffffffffp+1024\n"
- "%2 = OpSpecConstant %double -32.5\n",
- },
- // 7. SpecId not found, expect no modification.
- {
- // code
- "OpDecorate %1 SpecId 201\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %double 3.14159265358979\n",
- // default values
- SpecIdToValueBitPatternMap{{8888, {0x0}}},
- // expected
- "OpDecorate %1 SpecId 201\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %double 3.14159265358979\n",
- },
- // 8. Multiple types of spec constants.
- {
- // code
- "OpDecorate %1 SpecId 201\n"
- "OpDecorate %2 SpecId 202\n"
- "OpDecorate %3 SpecId 203\n"
- "%bool = OpTypeBool\n"
- "%int = OpTypeInt 32 1\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %double 3.14159265358979\n"
- "%2 = OpSpecConstant %int 1024\n"
- "%3 = OpSpecConstantTrue %bool\n",
- // default values
- SpecIdToValueBitPatternMap{
- {201, {0xffffffff, 0x7fffffff}},
- {202, {0x00000800}},
- {203, {0x0}},
- },
- // expected
- "OpDecorate %1 SpecId 201\n"
- "OpDecorate %2 SpecId 202\n"
- "OpDecorate %3 SpecId 203\n"
- "%bool = OpTypeBool\n"
- "%int = OpTypeInt 32 1\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %double 0x1.fffffffffffffp+1024\n"
- "%2 = OpSpecConstant %int 2048\n"
- "%3 = OpSpecConstantFalse %bool\n",
- },
- // 9. Ignore other decorations.
- {
- // code
- "OpDecorate %1 ArrayStride 4\n"
- "%int = OpTypeInt 32 1\n"
- "%1 = OpSpecConstant %int 100\n",
- // default values
- SpecIdToValueBitPatternMap{{4, {0x7fffffff}}},
- // expected
- "OpDecorate %1 ArrayStride 4\n"
- "%int = OpTypeInt 32 1\n"
- "%1 = OpSpecConstant %int 100\n",
- },
- // 10. Distinguish from other decorations.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %1 ArrayStride 4\n"
- "%int = OpTypeInt 32 1\n"
- "%1 = OpSpecConstant %int 100\n",
- // default values
- SpecIdToValueBitPatternMap{{4, {0x7fffffff}}, {100, {0xffffffff}}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %1 ArrayStride 4\n"
- "%int = OpTypeInt 32 1\n"
- "%1 = OpSpecConstant %int -1\n",
- },
- // 11. Decorate through decoration group.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 100\n",
- // default values
- SpecIdToValueBitPatternMap{{100, {0x7fffffff}}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 2147483647\n",
- },
- // 12. Ignore other decorations in decoration group.
- {
- // code
- "OpDecorate %1 ArrayStride 4\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 100\n",
- // default values
- SpecIdToValueBitPatternMap{{4, {0x7fffffff}}},
- // expected
- "OpDecorate %1 ArrayStride 4\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 100\n",
- },
- // 13. Distinguish from other decorations in decoration group.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %1 ArrayStride 4\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 100\n",
- // default values
- SpecIdToValueBitPatternMap{{100, {0x7fffffff}}, {4, {0x00000001}}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %1 ArrayStride 4\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 2147483647\n",
- },
- // 14. Unchanged bool default value
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "%bool = OpTypeBool\n"
- "%1 = OpSpecConstantTrue %bool\n"
- "%2 = OpSpecConstantFalse %bool\n",
- // default values
- SpecIdToValueBitPatternMap{{100, {0x1}}, {101, {0x0}}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "%bool = OpTypeBool\n"
- "%1 = OpSpecConstantTrue %bool\n"
- "%2 = OpSpecConstantFalse %bool\n",
- },
- // 15. Unchanged int default values
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "%int = OpTypeInt 32 1\n"
- "%ulong = OpTypeInt 64 0\n"
- "%1 = OpSpecConstant %int 10\n"
- "%2 = OpSpecConstant %ulong 11\n",
- // default values
- SpecIdToValueBitPatternMap{{100, {10}}, {101, {11, 0}}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "%int = OpTypeInt 32 1\n"
- "%ulong = OpTypeInt 64 0\n"
- "%1 = OpSpecConstant %int 10\n"
- "%2 = OpSpecConstant %ulong 11\n",
- },
- // 16. Unchanged float default values
- {
- // code
- "OpDecorate %1 SpecId 201\n"
- "OpDecorate %2 SpecId 202\n"
- "%float = OpTypeFloat 32\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %float 3.25\n"
- "%2 = OpSpecConstant %double 1.25\n",
- // default values
- SpecIdToValueBitPatternMap{{201, {0x40500000}},
- {202, {0x00000000, 0x3ff40000}}},
- // expected
- "OpDecorate %1 SpecId 201\n"
- "OpDecorate %2 SpecId 202\n"
- "%float = OpTypeFloat 32\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %float 3.25\n"
- "%2 = OpSpecConstant %double 1.25\n",
- },
- // 17. OpGroupDecorate may have multiple target ids defined by the same
- // eligible spec constant
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2 %2 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 100\n",
- // default values
- SpecIdToValueBitPatternMap{{100, {0xffffffff}}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2 %2 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int -1\n",
- },
- // 18. For Boolean type spec constants,if any word in the bit pattern
- // is not zero, it can be considered as a 'true', otherwise, it can be
- // considered as a 'false'.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "%bool = OpTypeBool\n"
- "%1 = OpSpecConstantTrue %bool\n"
- "%2 = OpSpecConstantFalse %bool\n"
- "%3 = OpSpecConstantFalse %bool\n",
- // default values
- SpecIdToValueBitPatternMap{
- {100, {0x0, 0x0, 0x0, 0x0}},
- {101, {0x10101010}},
- {102, {0x0, 0x0, 0x0, 0x2}},
- },
- // expected
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "%bool = OpTypeBool\n"
- "%1 = OpSpecConstantFalse %bool\n"
- "%2 = OpSpecConstantTrue %bool\n"
- "%3 = OpSpecConstantTrue %bool\n",
- },
- // 19. 16-bit signed int type.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "%short = OpTypeInt 16 1\n"
- "%1 = OpSpecConstant %short 10\n"
- "%2 = OpSpecConstant %short 11\n"
- "%3 = OpSpecConstant %short 11\n",
- // default values
- SpecIdToValueBitPatternMap{
- {100, {32767}}, {101, {0xffff}}, {102, {0xffffffd6}}},
- // expected. These are sign-extended
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "%short = OpTypeInt 16 1\n"
- "%1 = OpSpecConstant %short 32767\n"
- "%2 = OpSpecConstant %short -1\n"
- "%3 = OpSpecConstant %short -42\n",
- },
- // 20. 16-bit unsigned int type.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "%ushort = OpTypeInt 16 0\n"
- "%1 = OpSpecConstant %ushort 10\n"
- "%2 = OpSpecConstant %ushort 11\n"
- "%3 = OpSpecConstant %ushort 11\n",
- // default values
- SpecIdToValueBitPatternMap{
- {100, {32767}}, {101, {0xffff}}, {102, {0xffffffd6}}},
- // expected. Upper bits are always zero.
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "%ushort = OpTypeInt 16 0\n"
- "%1 = OpSpecConstant %ushort 32767\n"
- "%2 = OpSpecConstant %ushort 65535\n"
- "%3 = OpSpecConstant %ushort 65494\n",
- },
- // 21. 8-bit signed int type.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "%char = OpTypeInt 8 1\n"
- "%1 = OpSpecConstant %char 10\n"
- "%2 = OpSpecConstant %char 11\n"
- "%3 = OpSpecConstant %char 11\n",
- // default values
- SpecIdToValueBitPatternMap{
- {100, {127}}, {101, {128}}, {102, {0xd6}}},
- // expected. These are sign extended
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "%char = OpTypeInt 8 1\n"
- "%1 = OpSpecConstant %char 127\n"
- "%2 = OpSpecConstant %char -128\n"
- "%3 = OpSpecConstant %char -42\n",
- },
- // 22. 8-bit unsigned int type.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "OpDecorate %4 SpecId 103\n"
- "%uchar = OpTypeInt 8 0\n"
- "%1 = OpSpecConstant %uchar 10\n"
- "%2 = OpSpecConstant %uchar 11\n"
- "%3 = OpSpecConstant %uchar 11\n"
- "%4 = OpSpecConstant %uchar 11\n",
- // default values
- SpecIdToValueBitPatternMap{
- {100, {127}}, {101, {128}}, {102, {256}}, {103, {0xffffffd6}}},
- // expected. Upper bits are always zero.
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "OpDecorate %4 SpecId 103\n"
- "%uchar = OpTypeInt 8 0\n"
- "%1 = OpSpecConstant %uchar 127\n"
- "%2 = OpSpecConstant %uchar 128\n"
- "%3 = OpSpecConstant %uchar 0\n"
- "%4 = OpSpecConstant %uchar 214\n",
- },
- }));
- INSTANTIATE_TEST_SUITE_P(
- InvalidCases, SetSpecConstantDefaultValueInBitPatternFormParamTest,
- ::testing::ValuesIn(std::vector<
- SetSpecConstantDefaultValueInBitPatternFormTestCase>{
- // 0. Do not crash when decoration group is not used.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "%int = OpTypeInt 32 1\n"
- "%3 = OpSpecConstant %int 100\n",
- // default values
- SpecIdToValueBitPatternMap{{100, {0x7fffffff}}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "%int = OpTypeInt 32 1\n"
- "%3 = OpSpecConstant %int 100\n",
- },
- // 1. Do not crash when target does not exist.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "%int = OpTypeInt 32 1\n",
- // default values
- SpecIdToValueBitPatternMap{{100, {0x7fffffff}}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "%int = OpTypeInt 32 1\n",
- },
- // 2. Do nothing when SpecId decoration is not attached to a
- // non-spec-constant instruction.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "%int = OpTypeInt 32 1\n"
- "%int_101 = OpConstant %int 101\n",
- // default values
- SpecIdToValueBitPatternMap{{100, {0x7fffffff}}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "%int = OpTypeInt 32 1\n"
- "%int_101 = OpConstant %int 101\n",
- },
- // 3. Do nothing when SpecId decoration is not attached to a
- // OpSpecConstant{|True|False} instruction.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "%int = OpTypeInt 32 1\n"
- "%3 = OpSpecConstant %int 101\n"
- "%1 = OpSpecConstantOp %int IAdd %3 %3\n",
- // default values
- SpecIdToValueBitPatternMap{{100, {0x7fffffff}}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "%int = OpTypeInt 32 1\n"
- "%3 = OpSpecConstant %int 101\n"
- "%1 = OpSpecConstantOp %int IAdd %3 %3\n",
- },
- // 4. Do not crash and do nothing when SpecId decoration is applied to
- // multiple spec constants.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2 %3 %4\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 100\n"
- "%3 = OpSpecConstant %int 200\n"
- "%4 = OpSpecConstant %int 300\n",
- // default values
- SpecIdToValueBitPatternMap{{100, {0xffffffff}}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2 %3 %4\n"
- "%int = OpTypeInt 32 1\n"
- "%2 = OpSpecConstant %int 100\n"
- "%3 = OpSpecConstant %int 200\n"
- "%4 = OpSpecConstant %int 300\n",
- },
- // 5. Do not crash and do nothing when SpecId decoration is attached to
- // non-spec-constants (invalid case).
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "%2 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%int_100 = OpConstant %int 100\n",
- // default values
- SpecIdToValueBitPatternMap{{100, {0xffffffff}}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "%1 = OpDecorationGroup\n"
- "%2 = OpDecorationGroup\n"
- "OpGroupDecorate %1 %2\n"
- "%int = OpTypeInt 32 1\n"
- "%int_100 = OpConstant %int 100\n",
- },
- // 6. Incompatible input bit pattern with the type. Nothing should be
- // done in such a case.
- {
- // code
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "%int = OpTypeInt 32 1\n"
- "%ulong = OpTypeInt 64 0\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %int 100\n"
- "%2 = OpSpecConstant %ulong 200\n"
- "%3 = OpSpecConstant %double 3.141592653\n",
- // default values
- SpecIdToValueBitPatternMap{
- {100, {10, 0}}, {101, {11}}, {102, {0xffffffff}}},
- // expected
- "OpDecorate %1 SpecId 100\n"
- "OpDecorate %2 SpecId 101\n"
- "OpDecorate %3 SpecId 102\n"
- "%int = OpTypeInt 32 1\n"
- "%ulong = OpTypeInt 64 0\n"
- "%double = OpTypeFloat 64\n"
- "%1 = OpSpecConstant %int 100\n"
- "%2 = OpSpecConstant %ulong 200\n"
- "%3 = OpSpecConstant %double 3.141592653\n",
- },
- }));
- } // namespace
- } // namespace opt
- } // namespace spvtools
|