@@ -96,8 +96,10 @@ uint32_t Pass::GenerateCopy(Instruction* object_to_copy, uint32_t new_type_id,
96
96
97
97
Instruction* original_type = get_def_use_mgr ()->GetDef (original_type_id);
98
98
Instruction* new_type = get_def_use_mgr ()->GetDef (new_type_id);
99
- assert (new_type->opcode () == original_type->opcode () &&
100
- " Can't copy an aggragate type unless the type correspond." );
99
+
100
+ if (new_type->opcode () != original_type->opcode ()) {
101
+ return 0 ;
102
+ }
101
103
102
104
switch (original_type->opcode ()) {
103
105
case spv::Op::OpTypeArray: {
@@ -114,8 +116,12 @@ uint32_t Pass::GenerateCopy(Instruction* object_to_copy, uint32_t new_type_id,
114
116
for (uint32_t i = 0 ; i < array_length; i++) {
115
117
Instruction* extract = ir_builder.AddCompositeExtract (
116
118
original_element_type_id, object_to_copy->result_id (), {i});
117
- element_ids.push_back (
118
- GenerateCopy (extract, new_element_type_id, insertion_position));
119
+ uint32_t new_id =
120
+ GenerateCopy (extract, new_element_type_id, insertion_position);
121
+ if (new_id == 0 ) {
122
+ return 0 ;
123
+ }
124
+ element_ids.push_back (new_id);
119
125
}
120
126
121
127
return ir_builder.AddCompositeConstruct (new_type_id, element_ids)
@@ -128,20 +134,23 @@ uint32_t Pass::GenerateCopy(Instruction* object_to_copy, uint32_t new_type_id,
128
134
uint32_t new_member_type_id = new_type->GetSingleWordInOperand (i);
129
135
Instruction* extract = ir_builder.AddCompositeExtract (
130
136
orig_member_type_id, object_to_copy->result_id (), {i});
131
- element_ids.push_back (
132
- GenerateCopy (extract, new_member_type_id, insertion_position));
137
+ uint32_t new_id =
138
+ GenerateCopy (extract, new_member_type_id, insertion_position);
139
+ if (new_id == 0 ) {
140
+ return 0 ;
141
+ }
142
+ element_ids.push_back (new_id);
133
143
}
134
144
return ir_builder.AddCompositeConstruct (new_type_id, element_ids)
135
145
->result_id ();
136
146
}
137
147
default :
138
148
// If we do not have an aggregate type, then we have a problem. Either we
139
149
// found multiple instances of the same type, or we are copying to an
140
- // incompatible type. Either way the code is illegal.
141
- assert ( false &&
142
- " Don't know how to copy this type. Code is likely illegal. " ) ;
150
+ // incompatible type. Either way the code is illegal. Leave the code as
151
+ // is and let the caller deal with it.
152
+ return 0 ;
143
153
}
144
- return 0 ;
145
154
}
146
155
147
156
} // namespace opt
0 commit comments