Skip to content

signed integer overflow UB and integer conversion with clang #48

Description

@jxy

Optimization in clang will give you different sequence of random numbers on x86_64. I have it open at https://bugs.llvm.org/show_bug.cgi?id=52100 We'll see what the compiler developers say.

At the mean time, I have a brute force workaround for clang and icx.

diff --git a/generic/ranstuff.c b/generic/ranstuff.c
index dfd3816a..dc1e4e93 100644
--- a/generic/ranstuff.c
+++ b/generic/ranstuff.c
@@ -87,7 +87,7 @@ void initialize_prn(double_prn *prn_pt, int seed, int index) {
     seed = (69607+8*index)*seed+12345;
     prn_pt->r6 = (seed>>8) & 0xffffff;
     seed = (69607+8*index)*seed+12345;
-    prn_pt->ic_state = seed;
+    prn_pt->ic_state = seed & 0x80000000ULL ? 0xffffffff00000000ULL | seed : 0x00000000ffffffffULL & seed;
     prn_pt->multiplier = 100000005 + 8*index;
     prn_pt->addend = 12345;
     prn_pt->scale = 1.0/((Real)0x1000000);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions