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

[Bug]: Generate trap due to failure to identify return stmt in function decl body #767

Open
kumarak opened this issue Jan 26, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@kumarak
Copy link
Member

kumarak commented Jan 26, 2025

VAST version

v0.0.66

LLVM version

19

Operating system

MacOS

Description

Vast codegen fails to identify return stmt in the function body because it only looks into the last effective stmt of the scope. Ref:

operation get_last_effective_operation(block_t &block) {

It can be reproduced with following snippet of code

static unsigned int var_error;
static unsigned int var_1;

unsigned int func(void) {
    unsigned int local_c;
    goto basic_0;
  basic_3:
    return local_c;
  basic_2:
    local_c = 0U;
    goto basic_3;
  basic_0:
    if (var_error == 0U)
        goto basic_1;
    else
        goto basic_2;
  basic_1:
    local_c = var_1;
    goto basic_3;
}  

Steps to Reproduce

cat << EOF > test.c
static unsigned int var_error;
static unsigned int var_1;

unsigned int func(void) {
    unsigned int local_c;
    goto basic_0;
  basic_3:
    return local_c;
  basic_2:
    local_c = 0U;
    goto basic_3;
  basic_0:
    if (var_error == 0U)
        goto basic_1;
    else
        goto basic_2;
  basic_1:
    local_c = var_1;
    goto basic_3;
}  
EOF

// Emit hl mlir 
./tools/vast-front/vast-front -vast-emit-mlir=hl test.c -o test.mlir
@kumarak kumarak added the bug Something isn't working label Jan 26, 2025
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

1 participant