Skip to content

Commit

Permalink
Implement desired functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
wrongnull committed Jul 25, 2024
1 parent d1c058c commit 16ea13e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 20 deletions.
6 changes: 1 addition & 5 deletions src/aro/Diagnostics/messages.def
Original file line number Diff line number Diff line change
Expand Up @@ -1294,15 +1294,11 @@ invalid_utf8
.msg = "source file is not valid UTF-8"
.kind = .@"error"

implicitly_unsigned_literal_clang
implicitly_unsigned_literal
.msg = "integer literal is too large to be represented in a signed integer type, interpreting as unsigned"
.opt = W("implicitly-unsigned-literal")
.kind = .warning

implicitly_unsigned_literal_gcc
.msg = "integer constant is so large that it is unsigned"
.kind = .warning

invalid_preproc_operator
.msg = "token is not a valid binary operator in a preprocessor subexpression"
.kind = .@"error"
Expand Down
15 changes: 13 additions & 2 deletions 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 @@ -8418,7 +8419,7 @@ fn fixedSizeInt(p: *Parser, base: u8, buf: []const u8, suffix: NumberSuffix, tok
if (suffix.isSignedInteger()) {
const max_int = try Value.maxInt(p.comp.types.intmax, p.comp);
if (interned_val.compare(.gt, max_int, p.comp)) {
try p.errTok(if (p.comp.langopts.emulate == .gcc) .implicitly_unsigned_literal_gcc else .implicitly_unsigned_literal_clang, tok_i);
try p.errTok(.implicitly_unsigned_literal, tok_i);
}
}

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 = if (p.comp.langopts.emulate == .gcc) .int128 else .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: 1 addition & 4 deletions test/cases/integer literal promotion warning clang.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//aro-args --emulate=clang

_Static_assert(__builtin_types_compatible_p(typeof(18446744073709550592), __int128), "");
_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]" \
"integer literal promotion warning clang.c:3:1: error: static assertion failed '__builtin_types_compatible_p(unsigned long long, __int128)' \"\"" \
"integer literal promotion warning clang.c:4:52: warning: integer literal is too large to be represented in a signed integer type, interpreting as unsigned [-Wimplicitly-unsigned-literal]"
#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]"

9 changes: 0 additions & 9 deletions test/cases/integer literal promotion warning gcc.c

This file was deleted.

0 comments on commit 16ea13e

Please sign in to comment.