-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[llvm-libc] Import setjmp from llvm-libc #24765
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#ifdef __EMSCRIPTEN__ | ||
#define sigsetjmp(buf, x) setjmp((buf)) | ||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#ifdef __EMSCRIPTEN__ | ||
#define siglongjmp(buf, val) longjmp(buf, val) | ||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//===-- Implementation header for longjmp -----------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SRC_SETJMP_LONGJMP_H | ||
#define LLVM_LIBC_SRC_SETJMP_LONGJMP_H | ||
|
||
#include "hdr/types/jmp_buf.h" | ||
#include "src/__support/macros/config.h" | ||
#include "src/__support/macros/properties/compiler.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
// TODO(https://github.com/llvm/llvm-project/issues/112427) | ||
// Some of the architecture-specific definitions are marked `naked`, which in | ||
// GCC implies `nothrow`. | ||
// | ||
// Right now, our aliases aren't marked `nothrow`, so we wind up in a situation | ||
// where clang will emit -Wmissing-exception-spec if we add `nothrow` here, but | ||
// GCC will emit -Wmissing-attributes here without `nothrow`. We need to update | ||
// LLVM_LIBC_FUNCTION to denote when a function throws or not. | ||
|
||
#ifdef LIBC_COMPILER_IS_GCC | ||
[[gnu::nothrow]] | ||
#endif | ||
void longjmp(jmp_buf buf, int val); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_SETJMP_LONGJMP_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//===-- Implementation header for setjmp ------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SRC_SETJMP_SETJMP_IMPL_H | ||
#define LLVM_LIBC_SRC_SETJMP_SETJMP_IMPL_H | ||
|
||
// This header has the _impl prefix in its name to avoid conflict with the | ||
// public header setjmp.h which is also included. here. | ||
#include "hdr/types/jmp_buf.h" | ||
#include "src/__support/macros/config.h" | ||
#include "src/__support/macros/properties/compiler.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
// TODO(https://github.com/llvm/llvm-project/issues/112427) | ||
// Some of the architecture-specific definitions are marked `naked`, which in | ||
// GCC implies `nothrow`. | ||
// | ||
// Right now, our aliases aren't marked `nothrow`, so we wind up in a situation | ||
// where clang will emit -Wmissing-exception-spec if we add `nothrow` here, but | ||
// GCC will emit -Wmissing-attributes here without `nothrow`. We need to update | ||
// LLVM_LIBC_FUNCTION to denote when a function throws or not. | ||
|
||
#ifdef LIBC_COMPILER_IS_GCC | ||
[[gnu::nothrow]] | ||
#endif | ||
[[gnu::returns_twice]] int | ||
setjmp(jmp_buf buf); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_SETJMP_SETJMP_IMPL_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//===-- Implementation of siglongjmp --------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/setjmp/siglongjmp.h" | ||
#include "src/__support/common.h" | ||
#include "src/setjmp/longjmp.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
// siglongjmp is the same as longjmp. The additional recovery work is done in | ||
// the epilogue of the sigsetjmp function. | ||
// TODO: move this inside the TU of longjmp and making it an alias after | ||
// sigsetjmp is implemented for all architectures. | ||
LLVM_LIBC_FUNCTION(void, siglongjmp, (jmp_buf buf, int val)) { | ||
return LIBC_NAMESPACE::longjmp(buf, val); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//===-- Implementation header for siglongjmp --------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SRC_SETJMP_SIGLONGJMP_H | ||
#define LLVM_LIBC_SRC_SETJMP_SIGLONGJMP_H | ||
|
||
#include "hdr/types/jmp_buf.h" | ||
#include "src/__support/macros/config.h" | ||
#include "src/__support/macros/properties/compiler.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
#ifdef LIBC_COMPILER_IS_GCC | ||
[[gnu::nothrow]] | ||
#endif | ||
void siglongjmp(jmp_buf buf, int val); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_SETJMP_SIGLONGJMP_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//===-- Implementation header for sigsetjmp ---------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SRC_SETJMP_SIGSETJMP_H | ||
#define LLVM_LIBC_SRC_SETJMP_SIGSETJMP_H | ||
|
||
#include "hdr/types/jmp_buf.h" | ||
#include "src/__support/macros/config.h" | ||
#include "src/__support/macros/properties/compiler.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
#ifdef LIBC_COMPILER_IS_GCC | ||
[[gnu::nothrow]] | ||
#endif | ||
[[gnu::returns_twice]] int | ||
sigsetjmp(sigjmp_buf buf, int savesigs); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_SETJMP_SIGSETJMP_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//===-- Implementation header for sigsetjmp epilogue ------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SRC_SETJMP_SIGSETJMP_EPILOGUE_H | ||
#define LLVM_LIBC_SRC_SETJMP_SIGSETJMP_EPILOGUE_H | ||
|
||
#include "hdr/types/jmp_buf.h" | ||
#include "src/__support/common.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
[[gnu::returns_twice]] int sigsetjmp_epilogue(jmp_buf buffer, int retval); | ||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_SETJMP_SIGSETJMP_EPILOGUE_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "src/setjmp/sigsetjmp.h" | ||
#include "hdr/offsetof_macros.h" | ||
#include "src/__support/common.h" | ||
#include "src/__support/macros/config.h" | ||
|
||
#if !defined(LIBC_TARGET_ARCH_IS_WASM) | ||
#error "Invalid file include" | ||
#endif | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
[[gnu::returns_twice]] int sigsetjmp(jmp_buf sigjmp_buf, int savesigs) { | ||
return setjmp(sigjmp_buf); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could remove this musl patch and instead do this redirection in source files, then our musl patch would be smaller and we could avoid the need for this new LLVM_LIBC macro.
I'm fine landing this patch either way, we can always clean this up as a followup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine either way as well.
On the hand, this should no longer be of any issue once we switch over to use llvm-libc public headers over the musl ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but I honestly think that process will take O(years). We can't delete musl until llvm-libc is has complete parity, or at least close enough that we accept some minor regressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly. As I expect to see more of these as we import more llvm-libc, I feel like we should probably try to address this properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL. The forwarding is now done in source files.