Skip to content

[aarch64][win] Applying alignment to a stack object causes a mis-compilation when using exception on Arm64 Windows #146973

Open
@dpaoliello

Description

@dpaoliello

Given the following code:

// Large object: alignment seems to be important?
struct alignas(128) BigObj {
    int value;
    // Destructor so it's kept alive.
    ~BigObj() { }
};

// Exception type need to be large enough to not fit in a register.
struct Error {
    int value;
    int padding[3];
};

int main() {
    BigObj bo{};

    try {
        throw Error { 42, {0, 0, 0} };
    } catch (const Error& e) {
        return e.value;
    }
    return 0;
}

This program crashes when built and run on Arm64 Windows:

> & 'C:\Program Files\LLVM\bin\clang.exe' .\test.cpp
> .\a.exe
> $LASTEXITCODE
-1073741819

The alignas seems to be important: if I remove that and replace it with a very large array within BigObj then the issue no longer reproduces.

When debugging, the slot for the exception in the catch is still null and nothing writes to it. In the VC Runtime during unwind, it writes the pointer to the exception to a completely different location.

I'm guessing that asjusting for the alignment may happen after calculating the CatchObjOffset in the exception data?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions