authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-12-03 03:30:43-05:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-12-03 08:21:03-05:00
log2cfc08ba0d5ad2f0f4cef71ad4365dfd0e71b9bd
tree248ec23d993b2547dcd97edf747773088b321eab
parentf68bfe2eb70065b76e187c85a203493be5b4959e

cbe: fix named constraints without modifiers


1 files changed, 29 insertions(+), 15 deletions(-)

src/codegen/c.zig+29-15
......@@ -4195,7 +4195,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
41954195 }
41964196 }
41974197 {
4198 const asm_source = std.mem.sliceAsBytes(f.air.extra[extra_i..])[0..extra.data.source_len];
4198 const asm_source = mem.sliceAsBytes(f.air.extra[extra_i..])[0..extra.data.source_len];
41994199
42004200 var stack = std.heap.stackFallback(256, f.object.dg.gpa);
42014201 const allocator = stack.get();
......@@ -4204,29 +4204,43 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
42044204
42054205 var src_i: usize = 0;
42064206 var dst_i: usize = 0;
4207 while (src_i < asm_source.len) : (src_i += 1) {
4208 fixed_asm_source[dst_i] = asm_source[src_i];
4209 dst_i += 1;
4210 if (asm_source[src_i] != '%' or src_i + 1 >= asm_source.len) continue;
4207 while (true) {
4208 const literal = mem.sliceTo(asm_source[src_i..], '%');
4209 src_i += literal.len;
4210
4211 mem.copy(u8, fixed_asm_source[dst_i..], literal);
4212 dst_i += literal.len;
4213
4214 if (src_i >= asm_source.len) break;
4215
42114216 src_i += 1;
4217 if (src_i >= asm_source.len)
4218 return f.fail("CBE: invalid inline asm string '{s}'", .{asm_source});
4219
4220 fixed_asm_source[dst_i] = '%';
4221 dst_i += 1;
4222
42124223 if (asm_source[src_i] != '[') {
4213 // This handles %%
4224 // This also handles %%
42144225 fixed_asm_source[dst_i] = asm_source[src_i];
4226 src_i += 1;
42154227 dst_i += 1;
42164228 continue;
42174229 }
4218 const len = std.mem.indexOfScalar(u8, asm_source[src_i + 1 ..], ']') orelse
4219 return f.fail("CBE: invalid inline asm string '{s}'", .{asm_source});
4220 if (std.mem.indexOfScalar(u8, asm_source[src_i + 1 ..][0..len], ':')) |colon| {
4221 const modifier = asm_source[src_i + 1 + colon + 1 .. src_i + 1 + len];
4222 std.mem.copy(u8, fixed_asm_source[dst_i..], modifier);
4223 dst_i += modifier.len;
42244230
4225 const name = asm_source[src_i .. src_i + 1 + colon];
4226 std.mem.copy(u8, fixed_asm_source[dst_i..], name);
4231 const desc = mem.sliceTo(asm_source[src_i..], ']');
4232 if (mem.indexOfScalar(u8, desc, ':')) |colon| {
4233 const name = desc[0..colon];
4234 const modifier = desc[colon + 1 ..];
4235
4236 mem.copy(u8, fixed_asm_source[dst_i..], modifier);
4237 dst_i += modifier.len;
4238 mem.copy(u8, fixed_asm_source[dst_i..], name);
42274239 dst_i += name.len;
42284240
4229 src_i += len;
4241 src_i += desc.len;
4242 if (src_i >= asm_source.len)
4243 return f.fail("CBE: invalid inline asm string '{s}'", .{asm_source});
42304244 }
42314245 }
42324246