| author | |
| committer | |
| log | e283a40d17bbbeeafda84fad9b75bbc458950934 |
| tree | 8750bfe9dfcda5321848d2d055510aea821f054b |
| parent | e2bb92b2e27dc54852a0227345e294ae383358fd |
Closes #125493 files changed, 21 insertions(+), 1 deletions(-)
src/translate_c.zig+8-1| ... | ... | @@ -5799,7 +5799,7 @@ fn zigifyEscapeSequences(ctx: *Context, m: *MacroCtx) ![]const u8 { |
| 5799 | 5799 | } |
| 5800 | 5800 | } |
| 5801 | 5801 | for (source) |c| { |
| 5802 | if (c == '\\') { | |
| 5802 | if (c == '\\' or c == '\t') { | |
| 5803 | 5803 | break; |
| 5804 | 5804 | } |
| 5805 | 5805 | } else return source; |
| ... | ... | @@ -5876,6 +5876,13 @@ fn zigifyEscapeSequences(ctx: *Context, m: *MacroCtx) ![]const u8 { |
| 5876 | 5876 | state = .Start; |
| 5877 | 5877 | }, |
| 5878 | 5878 | .Start => { |
| 5879 | if (c == '\t') { | |
| 5880 | bytes[i] = '\\'; | |
| 5881 | i += 1; | |
| 5882 | bytes[i] = 't'; | |
| 5883 | i += 1; | |
| 5884 | continue; | |
| 5885 | } | |
| 5879 | 5886 | if (c == '\\') { |
| 5880 | 5887 | state = .Escape; |
| 5881 | 5888 | } |
test/behavior/translate_c_macros.h+2| ... | ... | @@ -50,3 +50,5 @@ typedef _Bool uintptr_t; |
| 50 | 50 | #define CAST_TO_UINTPTR(X) (uintptr_t)(X) |
| 51 | 51 | |
| 52 | 52 | #define LARGE_INT 18446744073709550592 |
| 53 | ||
| 54 | #define EMBEDDED_TAB "hello	" |
test/behavior/translate_c_macros.zig+11| ... | ... | @@ -2,6 +2,7 @@ const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const expect = std.testing.expect; |
| 4 | 4 | const expectEqual = std.testing.expectEqual; |
| 5 | const expectEqualStrings = std.testing.expectEqualStrings; | |
| 5 | 6 | |
| 6 | 7 | const h = @cImport(@cInclude("behavior/translate_c_macros.h")); |
| 7 | 8 | |
| ... | ... | @@ -123,3 +124,13 @@ test "large integer macro" { |
| 123 | 124 | |
| 124 | 125 | try expectEqual(@as(c_ulonglong, 18446744073709550592), h.LARGE_INT); |
| 125 | 126 | } |
| 127 | ||
| 128 | test "string literal macro with embedded tab character" { | |
| 129 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | |
| 130 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | |
| 131 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | |
| 132 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 133 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 134 | ||
| 135 | try expectEqualStrings("hello\t", h.EMBEDDED_TAB); | |
| 136 | } |