Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation: define char types and sig_atomic size #591

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/aro/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ fn generateSystemDefines(comp: *Compilation, w: anytype) !void {
try comp.generateIntMaxAndWidth(w, "PTRDIFF", comp.types.ptrdiff);
try comp.generateIntMaxAndWidth(w, "INTPTR", comp.types.intptr);
try comp.generateIntMaxAndWidth(w, "UINTPTR", comp.types.intptr.makeIntegerUnsigned());
try comp.generateIntMaxAndWidth(w, "SIG_ATOMIC", target_util.sigAtomicType(comp.target));

// int widths
try w.print("#define __BITINT_MAXWIDTH__ {d}\n", .{bit_int_max_bits});
Expand Down Expand Up @@ -493,6 +494,8 @@ fn generateSystemDefines(comp: *Compilation, w: anytype) !void {
try generateTypeMacro(w, mapper, "__PTRDIFF_TYPE__", comp.types.ptrdiff, comp.langopts);
try generateTypeMacro(w, mapper, "__SIZE_TYPE__", comp.types.size, comp.langopts);
try generateTypeMacro(w, mapper, "__WCHAR_TYPE__", comp.types.wchar, comp.langopts);
try generateTypeMacro(w, mapper, "__CHAR16_TYPE__", comp.types.uint_least16_t, comp.langopts);
try generateTypeMacro(w, mapper, "__CHAR32_TYPE__", comp.types.uint_least32_t, comp.langopts);

try comp.generateExactWidthTypes(w, mapper);
try comp.generateFastAndLeastWidthTypes(w, mapper);
Expand Down
10 changes: 10 additions & 0 deletions src/aro/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ pub fn int16Type(target: std.Target) Type {
};
}

/// sig_atomic_t for this target
pub fn sigAtomicType(target: std.Target) Type {
if (target.cpu.arch.isWasm()) return .{ .specifier = .long };
return switch (target.cpu.arch) {
.avr => .{ .specifier = .schar },
.msp430 => .{ .specifier = .long },
else => .{ .specifier = .int },
};
}

/// int64_t for this target
pub fn int64Type(target: std.Target) Type {
switch (target.cpu.arch) {
Expand Down
3 changes: 3 additions & 0 deletions test/cases/wide character constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ int Y = 'abc\E';
#pragma GCC diagnostic pop
int Z = 'ABC\D';

_Static_assert(sizeof(__CHAR16_TYPE__) == sizeof(u'A'), "");
_Static_assert(sizeof(__CHAR32_TYPE__) == sizeof(U'A'), "");

#define EXPECTED_ERRORS "wide character constants.c:9:27: error: character too large for enclosing character literal type" \
"wide character constants.c:10:16: error: wide character literals may not contain multiple characters" \
"wide character constants.c:11:16: error: Unicode character literals may not contain multiple characters" \
Expand Down
Loading