diff --git a/src/aro/Diagnostics/messages.def b/src/aro/Diagnostics/messages.def index 9ecd49b7..119e72a2 100644 --- a/src/aro/Diagnostics/messages.def +++ b/src/aro/Diagnostics/messages.def @@ -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" diff --git a/src/aro/Parser.zig b/src/aro/Parser.zig index 6498e2e7..db2c0c61 100644 --- a/src/aro/Parser.zig +++ b/src/aro/Parser.zig @@ -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, @@ -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); } } @@ -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 }); diff --git a/test/cases/integer literal promotion warning clang.c b/test/cases/integer literal promotion warning clang.c index 25c6de76..b5b1e145 100644 --- a/test/cases/integer literal promotion warning clang.c +++ b/test/cases/integer literal promotion warning clang.c @@ -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]" diff --git a/test/cases/integer literal promotion warning gcc 32.c b/test/cases/integer literal promotion warning gcc 32.c new file mode 100644 index 00000000..07ce4064 --- /dev/null +++ b/test/cases/integer literal promotion warning gcc 32.c @@ -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]" + diff --git a/test/cases/integer literal promotion warning gcc 64.c b/test/cases/integer literal promotion warning gcc 64.c new file mode 100644 index 00000000..3cab7da6 --- /dev/null +++ b/test/cases/integer literal promotion warning gcc 64.c @@ -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]" + diff --git a/test/cases/integer literal promotion warning gcc.c b/test/cases/integer literal promotion warning gcc.c deleted file mode 100644 index 96acba16..00000000 --- a/test/cases/integer literal promotion warning gcc.c +++ /dev/null @@ -1,9 +0,0 @@ -//aro-args --emulate=gcc - -_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 gcc.c:3:52: warning: integer constant is so large that it is unsigned" \ - "integer literal promotion warning gcc.c:4:52: warning: integer constant is so large that it is unsigned" \ - "integer literal promotion warning gcc.c:4:1: error: static assertion failed '__builtin_types_compatible_p(__int128, unsigned long long)' \"\"" -