Skip to content

Bug in mips64el: Varied Output by Clang Optimization Levels #69328

Open
@godjhh

Description

@godjhh

Proof of Concept

#include <stdio.h>

long long var_0 = 9129318035724831661LL;
unsigned long long var_6 = 15327265744474054469ULL;
int var_14 = 0;
unsigned int var_17 = 1;
unsigned int arr_0 [8];
unsigned char arr_1 [8] = { 0 };
unsigned long long arr_9 [8] [8] ;
unsigned long long  var_24 = 1;
signed char arr_4 [8] [8];
unsigned int arr_22 [20] [20] ;

void test(unsigned long long var_6, int var_14, unsigned int var_17, unsigned int arr_0 [8] , unsigned char arr_1 [8]) {
    for (unsigned int i_0 = var_14; i_0 < ((((unsigned int) var_0)) - (1626475429U))/*8*/; i_0 += 4) 
    {
        printf("var0: %d\n", ((unsigned int)(var_0)-(1626475429U)));
        arr_4[i_0][i_0] = arr_1 [i_0];

        for (int i_1 = (int)((( arr_0 [i_0])) - (2482776649ULL))/*2*/; i_1 < 4; i_1 += 2) 
        {
            printf("i_1: %llu\n", ((size_t)(2482776651U))-(2482776649ULL));
        }
    }
    var_24 = (int) ((var_6));
    for (long long int i_4 = 0; i_4 < 20; i_4 += 4) 
    {
        arr_22 [i_4] [i_4] = var_17;
    } 
}

int main() {
    for (size_t i_0 = 0; i_0 < 8; ++i_0) 
        arr_0 [i_0] = 2482776651U;

    test(var_6, var_14, var_17, arr_0 , arr_1 );
    printf("var_24 value: %llu\n", var_24);
}

Expected Behavior

In the first for loop, the result of the condition expression ((((unsigned int) var_0)) - (1626475429U)) is 8. This is verified through the output of the following printf() function, which consequently determines the number of loop iterations.

In the second for loop, the calculation (int)((( arr_0 [i_0])) - (2482776649ULL)) results in a value of 2 for i_1. This is also confirmed through the output of the printf() function, which aids in determining the number of times the loop will execute.

This code also performs unknown behavior.
Can you tell me why these results are coming out?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions