Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Clang 20 i686-pc-windows-msvc regression, silent bad codegen for std::current_exception() #158302

@StephanTLavavej

Description

@StephanTLavavej

This is a regression from Clang 19 to Clang 20 and is specific to 32-bit x86 Windows.

MSVC 19.50 Preview 1 (in VS 2026 Insiders) accepts the following code, while Clang 20.1.8 generates code that AVs.

C:\Temp>type meow.cpp
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <cassert>
#include <cstdio>
#include <cstring>
#include <exception>
#include <stdexcept>

using namespace std;

struct A {
    ~A() noexcept {
        assert(uncaught_exceptions() == 2);
        try {
            assert(uncaught_exceptions() == 2);
            throw runtime_error("say what?");
        } catch (const exception&) {
            assert(uncaught_exceptions() == 2);
            auto c = current_exception();
            try {
                assert(uncaught_exceptions() == 2);
                rethrow_exception(c);
            } catch (const runtime_error& e) {
                assert(uncaught_exceptions() == 2);
                assert(strcmp("say what?", e.what()) == 0);
            }

            assert(uncaught_exceptions() == 2);

            try {
                assert(uncaught_exceptions() == 2);
                throw;
            } catch (const runtime_error& e) {
                assert(uncaught_exceptions() == 2);
                assert(strcmp("say what?", e.what()) == 0);
            }
        }
    }
};

struct B {
    ~B() noexcept {
        assert(uncaught_exceptions() == 1);
        try {
            assert(uncaught_exceptions() == 1);
            A aa;
            throw runtime_error("oh no!");
        } catch (const exception&) {
            assert(uncaught_exceptions() == 1);
            auto c = current_exception();
            try {
                assert(uncaught_exceptions() == 1);
                rethrow_exception(c);
            } catch (const runtime_error& e) {
                assert(uncaught_exceptions() == 1);
                assert(strcmp("oh no!", e.what()) == 0);
            }

            assert(uncaught_exceptions() == 1);

            try {
                assert(uncaught_exceptions() == 1);
                throw;
            } catch (const runtime_error& e) {
                assert(uncaught_exceptions() == 1);
                assert(strcmp("oh no!", e.what()) == 0);
            }
        }
    }
};

void meow() {
    B bb;
    throw runtime_error("oh no");
}

int main() {
    try {
        meow();
    } catch (...) {
        assert(uncaught_exceptions() == 0);
        assert(current_exception());
    }
    puts("Done.");
}
C:\Temp>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od meow.cpp
meow.cpp

C:\Temp>meow
Done.

C:\Temp>echo %ERRORLEVEL%
0

C:\Temp>clang-cl /EHsc /nologo /W4 /std:c++latest /MTd /Od meow.cpp

C:\Temp>meow

C:\Temp>echo %ERRORLEVEL%
-1073741819

Metadata

Metadata

Assignees

No one assigned

    Labels

    clangClang issues not falling into any other categorymiscompilationregression:20Regression in 20 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions