Skip to content

Sign-extension error in RV64 when build optimization is enabled #1808

@zhengaooo

Description

@zhengaooo

my toolchain was built by command ./configure && make linux on unbuntu.
And when compile bellow code, the result is quite different with/without build optimization (-O1 or higher level)

#include <stdio.h>
#define TEE_ERROR_ITEM_NOT_FOUND          (0xFFFF0008U)

unsigned int do_something(unsigned long tmp);

asm(
    ".globl do_something              \n\t"
    "do_something:                    \n\t"
    "ret                     \n\t"
);

int main() {

        unsigned int res = TEE_ERROR_ITEM_NOT_FOUND;
        unsigned long test = res;
       if(test == res)
                printf("a. %s %llx %llx\n",__TIMESTAMP__, res, test);

        if (test == TEE_ERROR_ITEM_NOT_FOUND)
                printf("b. %s %llx %llx\n",__TIMESTAMP__, res, test);

        res = do_something(test);

        if (res != TEE_ERROR_ITEM_NOT_FOUND)
                printf("c. %s %llx %llx\n",__TIMESTAMP__, res, test);
        return res;
}

it shouldn't print "c. %s %llx...", but when use -O1, it will print this sentence, seems it will ignore sign-extension when enable optimization.
it easy to verify.
look forward for your opinion

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions