Skip to content

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

@kumarak

Description

@kumarak

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions