Skip to content

Commit

Permalink
emulate chosen compiler in integer literal promotion
Browse files Browse the repository at this point in the history
  • Loading branch information
wrongnull authored Jul 30, 2024
1 parent 06709d1 commit 4f574a6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/aro/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const StringId = StrInt.StringId;
const Builtins = @import("Builtins.zig");
const Builtin = Builtins.Builtin;
const evalBuiltin = @import("Builtins/eval.zig").eval;
const target_util = @import("target.zig");

const Switch = struct {
default: ?TokenIndex = null,
Expand Down Expand Up @@ -8448,7 +8449,17 @@ fn fixedSizeInt(p: *Parser, base: u8, buf: []const u8, suffix: NumberSuffix, tok
const max_int = try Value.maxInt(res.ty, p.comp);
if (interned_val.compare(.lte, max_int, p.comp)) break;
} else {
res.ty = .{ .specifier = .ulong_long };
res.ty = .{ .specifier = spec: {
if (p.comp.langopts.emulate == .gcc) {
if (target_util.hasInt128(p.comp.target)) {
break :spec .int128;
} else {
break :spec .long_long;
}
} else {
break :spec .ulong_long;
}
} };
}

res.node = try p.addNode(.{ .tag = .int_literal, .ty = res.ty, .data = undefined });
Expand Down
5 changes: 5 additions & 0 deletions test/cases/integer literal promotion warning clang.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//aro-args --emulate=clang

_Static_assert(__builtin_types_compatible_p(typeof(18446744073709550592), unsigned long long), "");

#define EXPECTED_ERRORS "integer literal promotion warning clang.c:3:52: warning: integer literal is too large to be represented in a signed integer type, interpreting as unsigned [-Wimplicitly-unsigned-literal]"
6 changes: 6 additions & 0 deletions test/cases/integer literal promotion warning gcc 32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//aro-args --emulate=gcc --target=riscv32-linux-gnu

_Static_assert(__builtin_types_compatible_p(typeof(18446744073709550592), long long int), "");

#define EXPECTED_ERRORS "integer literal promotion warning gcc 32.c:3:52: warning: integer literal is too large to be represented in a signed integer type, interpreting as unsigned [-Wimplicitly-unsigned-literal]"

6 changes: 6 additions & 0 deletions test/cases/integer literal promotion warning gcc 64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//aro-args --emulate=gcc --target=x86_64-linux-gnu

_Static_assert(__builtin_types_compatible_p(typeof(18446744073709550592), __int128), "");

#define EXPECTED_ERRORS "integer literal promotion warning gcc 64.c:3:52: warning: integer literal is too large to be represented in a signed integer type, interpreting as unsigned [-Wimplicitly-unsigned-literal]"

0 comments on commit 4f574a6

Please sign in to comment.