Skip to content

__builtin_setjmp miscompiles on x86_64-pc-windows-msvc #72908

@duk-37

Description

@duk-37

Clang relies on llvm.frameaddress(0) returning RBP, which isn't the case on X64 Windows (see X86IselLowering::LowerFRAMEADDR).

NOTE: I'm not sure whether this is a Clang implementation issue or if one could interpret it as LLVM making a bad assumption during codegen. I marked it as the former but this is up for debate and I'm starting to lean towards the latter.

Repro:

void *buf[5];

void foo() {
    __builtin_longjmp(buf, 1);
}

int main() {
   if (!__builtin_setjmp(buf)) {
        foo();
   }
}

Relevant assembly:

lea rax, [rbp - 128]
mov qword ptr [rip + buf], rax

Godbolt link

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions