Skip to content

-aot: a goto past a var declaration emits a C++ goto that bypasses variable initialization (clang++ refuses); a constant-true condition drops the declaration #18

Closed

Description

@lookibed

-aot writes a das goto that jumps past a var declaration as a C++ goto past an initialized local, and clang++ refuses the generated file:

error: cannot jump from this goto statement to its label
note: jump bypasses variable initialization

A local with no initializer fails the same way, since the AOT output writes = 0 for it. The interpreter runs the program (it prints 3); the C standard and das both allow the jump (the skipped variable is simply indeterminate until its next store).

Minimal repro, goto_decl.das:

options gen2

var k = 3

def skip_init(n : int) : int {
    if (n > 1) {
        goto label 1
    }
    var g = n * 2
    label 1:
    g = n
    return g
}

[export]
def main : int {
    print("{skip_init(k)}\n")
    return 0
}
daslang goto_decl.das            # prints 3
daslang -aot goto_decl.das       # emits goto_decl.das.cpp; clang++ fails on it with the error above

A second variant: with a constant-true condition in place of n > 1 (so the goto always runs) the AOT optimizer drops the declaration of g but keeps its uses, and the C++ fails with use of undeclared identifier 'g'.

Context: this is the shape C's switch and goto lowerings produce (a jump into a block past a declaration), so the AOT lane of such programs cannot be built; the interpreter, -jit and -exe lanes run them. A workable AOT form is to declare every local the function's labels can bypass at the top of the function (C++ allows jumping past a declaration without an initializer of a trivial type), or to wrap the initialization in a block the goto does not enter.

Activity

  1. lookibed commented on Nov 9, 2026

    @lookibed
    OwnerAuthor

    Re-checked on daScript abf1d40 (0.6.5): AOT of a goto past a declaration still fails with 2 clang errors, although upstream GaijinEntertainment#4450 is closed. Keeping this open.

  2. lookibed commented on Nov 9, 2026

    @lookibed
    OwnerAuthor

    Not reproducible on master abf1d40e35 (0.6.5): -aot of this repro, of the constant-true variant and of a variant with an uninitialized local past the goto all compile with clang++ -std=c++17 -fsyntax-only, 0 errors. The emitter now hoists every local of a block that holds labels to the block top (int32_t __g_rename_at_9_1; memset(...)) and the declaration site becomes an assignment, so the goto crosses no initializer - commit 6394f60 (GaijinEntertainment#4475). The 11-09 comment claiming 2 clang errors was measured against something else; the earlier "2 errors" readings here came from running the wrong code block. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions