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

Incorrect handling of int128 values #572

Closed
ehaas opened this issue Nov 21, 2023 · 2 comments
Closed

Incorrect handling of int128 values #572

ehaas opened this issue Nov 21, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@ehaas
Copy link
Collaborator

ehaas commented Nov 21, 2023

The second _Static_assert here fails but passes on clang and gcc

#pragma GCC diagnostic ignored "-Wc23-extensions"

#define UINT128_MAX         ((unsigned __int128)-1)
#define INT128_MAX          ((__int128)+(UINT128_MAX/2))

_Static_assert(UINT128_MAX == 340282366920938463463374607431768211455WBU, "");
_Static_assert(INT128_MAX == 170141183460469231731687303715884105727WB, ""); // this fails, arocc thinks INT128_MAX is 0
@ehaas
Copy link
Collaborator Author

ehaas commented Nov 21, 2023

Possibly relevant:

void foo(void) {
    unsigned __int128 x = ((unsigned __int128)18446744073709551615UL)<< 64;
}
test.c:2:70: warning: overflow in expression; result is '-18446744073709551616' [-Winteger-overflow]
    unsigned __int128 x = ((unsigned __int128)18446744073709551615UL)<< 64;
                                                                     ^
1 warning generated.

(no diagnostics on clang)

@Vexu Vexu added the bug Something isn't working label Nov 21, 2023
@Vexu
Copy link
Owner

Vexu commented Nov 21, 2023

Bug is in Type.signedness:

diff --git a/src/aro/Type.zig b/src/aro/Type.zig
index 7e691bc..1369d7b 100644
--- a/src/aro/Type.zig
+++ b/src/aro/Type.zig
@@ -609,7 +609,7 @@ pub fn signedness(ty: Type, comp: *const Compilation) std.builtin.Signedness {
     return switch (ty.specifier) {
         // zig fmt: off
         .char, .complex_char => return comp.getCharSignedness(),
-        .uchar, .ushort, .uint, .ulong, .ulong_long, .bool, .complex_uchar, .complex_ushort,
+        .uchar, .ushort, .uint, .ulong, .ulong_long, .uint128, .bool, .complex_uchar, .complex_ushort,
         .complex_uint, .complex_ulong, .complex_ulong_long, .complex_uint128 => .unsigned,
         // zig fmt: on
         .bit_int, .complex_bit_int => ty.data.int.signedness,

@Vexu Vexu closed this as completed in 578f3a3 Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants