Skip to content

Commit 84c4a9d

Browse files
[llvm-libc] Import assert and complex into Emscripten (#24818)
This checks assert and complex submodules into Emscripten. f16 related sources in complex are dropped.
1 parent 8f638f8 commit 84c4a9d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+870
-15
lines changed
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
#ifdef __EMSCRIPTEN__
2-
#define sigsetjmp(buf, x) setjmp((buf))
3-
#endif
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
#ifdef __EMSCRIPTEN__
2-
#define siglongjmp(buf, val) longjmp(buf, val)
3-
#endif
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Internal header for __assert_fail -----------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_ASSERT___ASSERT_FAIL_H
10+
#define LLVM_LIBC_SRC_ASSERT___ASSERT_FAIL_H
11+
12+
#include "src/__support/macros/config.h"
13+
#include <stddef.h>
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
[[noreturn]] void __assert_fail(const char *assertion, const char *file,
18+
unsigned line, const char *function);
19+
20+
} // namespace LIBC_NAMESPACE_DECL
21+
22+
#endif // LLVM_LIBC_SRC_ASSERT___ASSERT_FAIL_H
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// NOLINT(llvm-header-guard) https://github.com/llvm/llvm-project/issues/83339
2+
//===-- Internal header for assert ------------------------------*- C++ -*-===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#include "src/assert/__assert_fail.h"
11+
12+
// There is no header guard here since assert is intended to be capable of being
13+
// included multiple times with NDEBUG defined differently, causing different
14+
// behavior.
15+
16+
#undef assert
17+
18+
#ifdef NDEBUG
19+
#define assert(e) (void)0
20+
#else
21+
22+
#ifdef __has_builtin
23+
#if __has_builtin(__builtin_expect)
24+
#define __LIBC_ASSERT_LIKELY(e) __builtin_expect(e, 1)
25+
#endif
26+
#endif
27+
#ifndef __LIBC_ASSERT_LIKELY
28+
#define __LIBC_ASSERT_LIKELY(e) e
29+
#endif
30+
31+
#define assert(e) \
32+
(__LIBC_ASSERT_LIKELY(e) ? (void)0 \
33+
: LIBC_NAMESPACE::__assert_fail( \
34+
#e, __FILE__, __LINE__, __PRETTY_FUNCTION__))
35+
#endif // NDEBUG
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===-- Implementation of __assert_fail -----------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/assert/__assert_fail.h"
10+
#include "src/__support/OSUtil/io.h"
11+
#include "src/__support/libc_assert.h"
12+
#include "src/__support/macros/config.h"
13+
#include "src/stdlib/abort.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
LLVM_LIBC_FUNCTION(void, __assert_fail,
18+
(const char *assertion, const char *file, unsigned line,
19+
const char *function)) {
20+
LIBC_NAMESPACE::report_assertion_failure(assertion, file, line, function);
21+
LIBC_NAMESPACE::abort();
22+
}
23+
24+
} // namespace LIBC_NAMESPACE_DECL
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===-- GPU definition of a libc internal assert macro ----------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/assert/__assert_fail.h"
10+
11+
#include "src/__support/CPP/atomic.h"
12+
#include "src/__support/GPU/utils.h"
13+
#include "src/__support/libc_assert.h"
14+
#include "src/__support/macros/config.h"
15+
#include "src/stdlib/abort.h"
16+
17+
namespace LIBC_NAMESPACE_DECL {
18+
19+
// A single-use lock to allow only a single thread to print the assertion.
20+
static cpp::Atomic<uint32_t> lock = 0;
21+
22+
LLVM_LIBC_FUNCTION(void, __assert_fail,
23+
(const char *assertion, const char *file, unsigned line,
24+
const char *function)) {
25+
uint64_t mask = gpu::get_lane_mask();
26+
// We only want a single work group or warp to handle the assertion. Each
27+
// group attempts to claim the lock, if it is already claimed we simply exit.
28+
uint32_t claimed = gpu::is_first_lane(mask)
29+
? !lock.fetch_or(1, cpp::MemoryOrder::ACQUIRE)
30+
: 0;
31+
if (!gpu::broadcast_value(mask, claimed))
32+
gpu::end_program();
33+
34+
// Only a single line should be printed if an assertion is hit.
35+
if (gpu::is_first_lane(mask))
36+
LIBC_NAMESPACE::report_assertion_failure(assertion, file, line, function);
37+
gpu::sync_lane(mask);
38+
LIBC_NAMESPACE::abort();
39+
}
40+
41+
} // namespace LIBC_NAMESPACE_DECL
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for cimag -------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_COMPLEX_CIMAG_H
10+
#define LLVM_LIBC_SRC_COMPLEX_CIMAG_H
11+
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
double cimag(_Complex double x);
17+
18+
} // namespace LIBC_NAMESPACE_DECL
19+
20+
#endif // LLVM_LIBC_SRC_COMPLEX_CIMAG_H
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for cimagf ------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_COMPLEX_CIMAGF_H
10+
#define LLVM_LIBC_SRC_COMPLEX_CIMAGF_H
11+
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
float cimagf(_Complex float x);
17+
18+
} // namespace LIBC_NAMESPACE_DECL
19+
20+
#endif // LLVM_LIBC_SRC_COMPLEX_CIMAGF_H
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation header for cimagf128 ---------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_COMPLEX_CIMAGF128_H
10+
#define LLVM_LIBC_SRC_COMPLEX_CIMAGF128_H
11+
12+
#include "src/__support/macros/config.h"
13+
#include "src/__support/macros/properties/complex_types.h"
14+
#include "src/__support/macros/properties/types.h"
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
float128 cimagf128(cfloat128 x);
19+
20+
} // namespace LIBC_NAMESPACE_DECL
21+
22+
#endif // LLVM_LIBC_SRC_COMPLEX_CIMAGF128_H
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation header for cimagf16 ----------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_COMPLEX_CIMAGF16_H
10+
#define LLVM_LIBC_SRC_COMPLEX_CIMAGF16_H
11+
12+
#include "src/__support/macros/config.h"
13+
#include "src/__support/macros/properties/complex_types.h"
14+
#include "src/__support/macros/properties/types.h"
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
float16 cimagf16(cfloat16 x);
19+
20+
} // namespace LIBC_NAMESPACE_DECL
21+
22+
#endif // LLVM_LIBC_SRC_COMPLEX_CIMAGF16_H

0 commit comments

Comments
 (0)