Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When noexcept is violated clang should call __cxa_begin_catch(unwind_arg) prior to calling std::terminate #12265

Closed
llvmbot opened this issue Jan 31, 2012 · 5 comments
Labels
bugzilla Issues migrated from bugzilla c++11

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 31, 2012

Bugzilla Link 11893
Resolution FIXED
Resolved on Jun 20, 2013 20:53
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@rjmccall

Extended Description

This test:

#include <iostream>
#include <stdexcept>
#include <exception>
#include <cstdlib>

void handler1()
{
    std::cout << "handler 1\n";
    std::abort();
}

void handler2()
{
    std::cout << "handler 2\n";
    std::abort();
}

struct A
{
    ~A() {std::set_terminate(handler2);}
};

void f2()
{
    std::set_terminate(handler1);
    throw std::runtime_error("throw in f2");
}

void f1() noexcept
{
    A a;
    f2();
}

int main()
{
    f1();
}

Should output:

handler 1

When run against the trunk libc++abi. Note that the trunk libc++abi won't run with the trunk libc++, but this will change soon (within a few days).

When the noexcept is violated, clang currently outputs a call to std::terminate(). Just prior to that call clang needs to call __cxa_begin_catch(unwind_arg) to make this work.

Reference [except.handle]/p7:

Also, an implicit handler is considered active when std::terminate() or std::unexpected() is entered due to a throw.

With the Itanium ABI, the way you make a handler active is by calling __cxa_begin_catch(unwind_arg).

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 31, 2012

I'm just now noticing that we have the same issue when ever clang calls terminate for any reason during stack unwinding. I.e. if a cleanup section throws when it shouldn't, and clang calls terminate, call __cxa_begin_catch first!

@rjmccall
Copy link
Contributor

I see what you're saying, but for what it's worth, I think every existing compiler does this. You might just want to make std::terminate more robust.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Sep 25, 2012

How?

@rjmccall
Copy link
Contributor

Do you not already track the exception curently being thrown? I suppose you don't.

@rjmccall
Copy link
Contributor

Fixed in r174939, r174940, and r184475.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++11
Projects
None yet
Development

No branches or pull requests

2 participants