Skip to content

Requirements for function return calls #305

@dj2

Description

@dj2

I can't find in the spec where it mentions when a function with a return value must call return. Playing around in godbot with glslang it appears that a single return is required but not all control paths must return, it injects an undef in those cases?

int foo() {
}

Produces an error that the function must return a value.

int foo() {
    if (true) {
        return 1;
    }
}

Compiles correctly with the end of the function return an OpUndef %int value.

int foo() {
    if (true) {
        return 1;
    } else {
        return 2;
    }
}

Injects an OpUnreachable at the end of the function since all control paths return.

It seems like, there must be a single return call at any nesting level inside a function to be valid (according to glslang) and any other paths out of the function will return an OpUndef value.

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