Skip to content

Commit 6a2dd8a

Browse files
committed
[LLVMSupport] Re-apply all post-import modifications on LLVMSupport that the Swift's fork has
Since the previous commits re-imported "vanilla" versions of LLVMSupport, we need to re-apply all modifications that the Swift's fork has made since the last import. More precisely: 1) git diff 7b70120..origin/main -- stdlib/include/llvm stdlib/public/LLVMSupport | git apply -3 --exclude "stdlib/include/llvm/Support/DataTypes.h" --exclude "stdlib/include/llvm/Config/llvm-config.h.cmake" 2) manually resolve conflict in STLExtras.h by applying the "__swift::__runtime" prefix to HEAD's version 3) manually resolve conflicts in StringSwitch.h by keeping HEAD's version (removing the Unicode BOM marker at the beginning of the file, keeping LLVM's version of the string functions) 4) manually resolve conflict in SwapByteOrder.h by adding the `defined(__wasi__)` part into the #if
1 parent 043cd20 commit 6a2dd8a

File tree

8 files changed

+46
-20
lines changed

8 files changed

+46
-20
lines changed

stdlib/include/llvm/ADT/Hashing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@
4444
#ifndef LLVM_ADT_HASHING_H
4545
#define LLVM_ADT_HASHING_H
4646

47-
#include "llvm/Support/DataTypes.h"
4847
#include "llvm/Support/ErrorHandling.h"
4948
#include "llvm/Support/SwapByteOrder.h"
5049
#include "llvm/Support/type_traits.h"
5150
#include <algorithm>
5251
#include <cassert>
5352
#include <cstring>
53+
#include <cstdint>
5454
#include <string>
5555
#include <tuple>
5656
#include <utility>

stdlib/include/llvm/ADT/STLExtras.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,8 @@ Iter next_or_end(const Iter &I, const Iter &End) {
724724
}
725725

726726
template <typename Iter>
727-
auto deref_or_none(const Iter &I, const Iter &End) -> llvm::Optional<
727+
auto deref_or_none(const Iter &I, const Iter &End)
728+
-> __swift::__runtime::llvm::Optional<
728729
std::remove_const_t<std::remove_reference_t<decltype(*I)>>> {
729730
if (I == End)
730731
return None;

stdlib/include/llvm/Support/Atomic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#ifndef LLVM_SUPPORT_ATOMIC_H
1818
#define LLVM_SUPPORT_ATOMIC_H
1919

20-
#include "llvm/Support/DataTypes.h"
20+
#include <stdint.h>
2121

2222
// Windows will at times define MemoryFence.
2323
#ifdef MemoryFence

stdlib/include/llvm/Support/Compiler.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#ifndef LLVM_SUPPORT_COMPILER_H
1616
#define LLVM_SUPPORT_COMPILER_H
1717

18-
#include "llvm/Config/llvm-config.h"
19-
2018
#ifdef __cplusplus
2119
#include <new>
2220
#endif

stdlib/include/llvm/Support/MathExtras.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ extern const float huge_valf;
880880

881881

882882
/// Add two signed integers, computing the two's complement truncated result,
883-
/// returning true if overflow occured.
883+
/// returning true if overflow occurred.
884884
template <typename T>
885885
std::enable_if_t<std::is_signed<T>::value, T> AddOverflow(T X, T Y, T &Result) {
886886
#if __has_builtin(__builtin_add_overflow)

stdlib/include/llvm/Support/PointerLikeTypeTraits.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#ifndef LLVM_SUPPORT_POINTERLIKETYPETRAITS_H
1515
#define LLVM_SUPPORT_POINTERLIKETYPETRAITS_H
1616

17-
#include "llvm/Support/DataTypes.h"
1817
#include <cassert>
18+
#include <cstdint>
1919
#include <type_traits>
2020

2121
inline namespace __swift { inline namespace __runtime {

stdlib/include/llvm/Support/SwapByteOrder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <stdlib.h>
2222
#endif
2323

24-
#if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) || \
24+
#if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) || defined(__wasi__) || \
2525
defined(__Fuchsia__) || defined(__EMSCRIPTEN__)
2626
#include <endian.h>
2727
#elif defined(_AIX)

stdlib/public/LLVMSupport/ErrorHandling.cpp

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,55 @@
1515
#include "llvm/ADT/StringRef.h"
1616
#include <cassert>
1717
#include <cstdlib>
18+
#include <cstdio>
1819

1920
#if defined(_MSC_VER)
2021
# include <io.h>
2122
# include <fcntl.h>
23+
#endif
24+
25+
#include <stdarg.h>
26+
27+
#if SWIFT_STDLIB_HAS_ASL
28+
#include <asl.h>
29+
#elif defined(__ANDROID__)
30+
#include <android/log.h>
31+
#endif
32+
33+
namespace {
34+
void error(const char *fmt, ...) {
35+
char buffer[1024];
36+
va_list argp;
37+
38+
va_start(argp, fmt);
39+
vsnprintf(buffer, sizeof(buffer), fmt, argp);
40+
va_end(argp);
41+
42+
#if SWIFT_STDLIB_HAS_ASL
43+
asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", buffer);
44+
#elif defined(__ANDROID__)
45+
__android_log_print(ANDROID_LOG_FATAL, "SwiftRuntime", "%s", buffer);
46+
#elif defined(_WIN32)
47+
#define STDERR_FILENO 2
48+
_write(STDERR_FILENO, buffer, strlen(buffer));
2249
#else
23-
# include <stdio.h>
50+
fputs(buffer, stderr);
51+
fflush(stderr);
2452
#endif
53+
}
54+
}
2555

2656
using namespace llvm;
2757

2858
void __swift::__runtime::llvm::report_fatal_error(const char *Reason,
2959
bool GenCrashDiag) {
30-
report_fatal_error(std::string(Reason), GenCrashDiag);
60+
error("LLVM ERROR: %s\n", Reason);
61+
abort();
3162
}
3263

3364
void __swift::__runtime::llvm::report_fatal_error(const std::string &Reason,
3465
bool GenCrashDiag) {
35-
// Blast the result out to stderr. We don't try hard to make sure this
36-
// succeeds (e.g. handling EINTR) and we can't use errs() here because
37-
// raw ostreams can call report_fatal_error.
38-
fprintf(stderr, "LLVM ERROR: %s\n", Reason.c_str());
39-
abort();
66+
report_fatal_error(Reason.c_str(), GenCrashDiag);
4067
}
4168

4269
void __swift::__runtime::llvm::report_fatal_error(StringRef Reason,
@@ -48,7 +75,7 @@ void __swift::__runtime::llvm::report_bad_alloc_error(const char *Reason,
4875
bool GenCrashDiag) {
4976
// Don't call the normal error handler. It may allocate memory. Directly write
5077
// an OOM to stderr and abort.
51-
fprintf(stderr, "LLVM ERROR: out of memory\n");
78+
error("LLVM ERROR: out of memory\n");
5279
abort();
5380
}
5481

@@ -58,11 +85,11 @@ void __swift::__runtime::llvm::llvm_unreachable_internal(
5885
// llvm_unreachable is intended to be used to indicate "impossible"
5986
// situations, and not legitimate runtime errors.
6087
if (msg)
61-
fprintf(stderr, "%s\n", msg);
62-
fprintf(stderr, "UNREACHABLE executed");
88+
error("%s\n", msg);
89+
error("UNREACHABLE executed");
6390
if (file)
64-
fprintf(stderr, " at %s:%u", file, line);
65-
fprintf(stderr, "!\n");
91+
error(" at %s:%u", file, line);
92+
error("!\n");
6693
abort();
6794
#ifdef LLVM_BUILTIN_UNREACHABLE
6895
// Windows systems and possibly others don't declare abort() to be noreturn,

0 commit comments

Comments
 (0)