144 changes: 72 additions & 72 deletions clang/include/clang/Basic/BuiltinsLoongArchLASX.def

Large diffs are not rendered by default.

130 changes: 65 additions & 65 deletions clang/include/clang/Basic/BuiltinsLoongArchLSX.def

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion clang/include/clang/Format/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ struct FormatStyle {

/// Control of individual brace wrapping cases.
///
/// If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
/// If ``BreakBeforeBraces`` is set to ``Custom``, use this to specify how
/// each individual brace case should be handled. Otherwise, this is ignored.
/// \code{.yaml}
/// # Example of usage:
Expand Down
11 changes: 10 additions & 1 deletion clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3063,7 +3063,16 @@ inline bool BitCast(InterpState &S, CodePtr OpPC, bool TargetIsUCharOrByte,

if constexpr (std::is_same_v<T, Floating>) {
assert(Sem);
S.Stk.push<Floating>(T::bitcastFromMemory(Buff.data(), *Sem));
ptrdiff_t Offset = 0;

if (llvm::sys::IsBigEndianHost) {
unsigned NumBits = llvm::APFloatBase::getSizeInBits(*Sem);
assert(NumBits % 8 == 0);
assert(NumBits <= ResultBitWidth);
Offset = (ResultBitWidth - NumBits) / 8;
}

S.Stk.push<Floating>(T::bitcastFromMemory(Buff.data() + Offset, *Sem));
} else {
assert(!Sem);
S.Stk.push<T>(T::bitcastFromMemory(Buff.data(), ResultBitWidth));
Expand Down
82 changes: 47 additions & 35 deletions clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,33 @@ static void swapBytes(std::byte *M, size_t N) {
/// have indeterminate value.
/// All offsets are in bits.
struct BitcastBuffer {
llvm::BitVector Data;
size_t SizeInBits = 0;
llvm::SmallVector<std::byte> Data;

BitcastBuffer() = default;

size_t size() const { return Data.size(); }
size_t size() const { return SizeInBits; }

const std::byte *data() const {
unsigned NBytes = Data.size() / 8;
unsigned BitVectorWordSize = sizeof(uintptr_t);
bool FullWord = (NBytes % BitVectorWordSize == 0);

// llvm::BitVector uses 64-bit fields internally, so when we have
// fewer bytes than that, we need to compensate for that on
// big endian hosts.
unsigned DataPlus;
if (llvm::sys::IsBigEndianHost)
DataPlus = BitVectorWordSize - (NBytes % BitVectorWordSize);
else
DataPlus = 0;

return reinterpret_cast<const std::byte *>(Data.getData().data()) +
(FullWord ? 0 : DataPlus);
}
const std::byte *data() const { return Data.data(); }

bool allInitialized() const {
// FIXME: Implement.
return true;
}

bool atByteBoundary() const { return (Data.size() * 8) == SizeInBits; }

void pushBit(bool Value) {
if (atByteBoundary())
Data.push_back(std::byte{0});

if (Value)
Data.back() |= (std::byte{1} << (SizeInBits % 8));
++SizeInBits;
}

void pushData(const std::byte *data, size_t BitOffset, size_t BitWidth,
bool BigEndianTarget) {
Data.reserve(BitOffset + BitWidth);

bool OnlyFullBytes = BitWidth % 8 == 0;
unsigned NBytes = BitWidth / 8;

Expand All @@ -125,7 +119,7 @@ struct BitcastBuffer {
std::byte B =
BigEndianTarget ? data[NBytes - OnlyFullBytes - I] : data[I];
for (unsigned X = 0; X != 8; ++X) {
Data.push_back(bitof(B, X));
pushBit(bitof(B, X));
++BitsHandled;
}
}
Expand All @@ -137,7 +131,7 @@ struct BitcastBuffer {
assert((BitWidth - BitsHandled) < 8);
std::byte B = BigEndianTarget ? data[0] : data[NBytes];
for (size_t I = 0, E = (BitWidth - BitsHandled); I != E; ++I) {
Data.push_back(bitof(B, I));
pushBit(bitof(B, I));
++BitsHandled;
}

Expand Down Expand Up @@ -321,19 +315,34 @@ static bool readPointerToBuffer(const Context &Ctx, const Pointer &FromPtr,
assert(false && "Implement casting to pointer types");

CharUnits ObjectReprChars = ASTCtx.getTypeSizeInChars(P.getType());
unsigned BitWidth;
if (const FieldDecl *FD = P.getField(); FD && FD->isBitField())
BitWidth = FD->getBitWidthValue(ASTCtx);
else
BitWidth = ASTCtx.toBits(ObjectReprChars);

unsigned BitWidth = ASTCtx.toBits(ObjectReprChars);
llvm::SmallVector<std::byte> Buff(ObjectReprChars.getQuantity());
BITCAST_TYPE_SWITCH_WITH_FLOAT(T, {
T Val = P.deref<T>();
Val.bitcastToMemory(Buff.data());
});
if (SwapData)
swapBytes(Buff.data(), ObjectReprChars.getQuantity());
// Work around floating point types that contain unused padding bytes.
// This is really just `long double` on x86, which is the only
// fundamental type with padding bytes.
if (T == PT_Float) {
Floating &F = P.deref<Floating>();
unsigned NumBits =
llvm::APFloatBase::getSizeInBits(F.getAPFloat().getSemantics());
assert(NumBits % 8 == 0);
assert(NumBits <= (ObjectReprChars.getQuantity() * 8));
F.bitcastToMemory(Buff.data());
// Now, only (maybe) swap the actual size of the float, excluding the
// padding bits.
if (SwapData)
swapBytes(Buff.data(), NumBits / 8);

} else {
if (const FieldDecl *FD = P.getField(); FD && FD->isBitField())
BitWidth = FD->getBitWidthValue(ASTCtx);

BITCAST_TYPE_SWITCH(T, {
T Val = P.deref<T>();
Val.bitcastToMemory(Buff.data());
});
if (SwapData)
swapBytes(Buff.data(), ObjectReprChars.getQuantity());
}

if (BitWidth != (Buff.size() * 8) && BigEndianTarget) {
Buffer.pushData(Buff.data() + (Buff.size() - 1 - (BitWidth / 8)),
Expand Down Expand Up @@ -363,5 +372,8 @@ bool clang::interp::DoBitCast(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
HasIndeterminateBits = !Buffer.allInitialized();
std::memcpy(Buff, Buffer.data(), BuffSize);

if (llvm::sys::IsBigEndianHost)
swapBytes(Buff, BuffSize);

return Success;
}
2 changes: 1 addition & 1 deletion clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ class AnnotatingParser {

bool parseConditional() {
while (CurrentToken) {
if (CurrentToken->is(tok::colon)) {
if (CurrentToken->is(tok::colon) && CurrentToken->is(TT_Unknown)) {
CurrentToken->setType(TT_ConditionalExpr);
next();
return true;
Expand Down
8 changes: 6 additions & 2 deletions clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,8 @@ void UnwrappedLineParser::parseStructuralElement(
case tok::kw_switch:
if (Style.Language == FormatStyle::LK_Java)
parseSwitch(/*IsExpr=*/true);
nextToken();
else
nextToken();
break;
case tok::kw_case:
// Proto: there are no switch/case statements.
Expand Down Expand Up @@ -2656,7 +2657,10 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
nextToken();
break;
case tok::kw_switch:
parseSwitch(/*IsExpr=*/true);
if (Style.Language == FormatStyle::LK_Java)
parseSwitch(/*IsExpr=*/true);
else
nextToken();
break;
case tok::kw_requires: {
auto RequiresToken = FormatTok;
Expand Down
13 changes: 6 additions & 7 deletions clang/lib/Sema/CheckExprLifetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,14 @@ using LocalVisitor = llvm::function_ref<bool(IndirectLocalPath &Path, Local L,
ReferenceKind RK)>;
} // namespace

static bool isVarOnPath(IndirectLocalPath &Path, VarDecl *VD) {
static bool isVarOnPath(const IndirectLocalPath &Path, VarDecl *VD) {
for (auto E : Path)
if (E.Kind == IndirectLocalPathEntry::VarInit && E.D == VD)
return true;
return false;
}

static bool pathContainsInit(IndirectLocalPath &Path) {
static bool pathContainsInit(const IndirectLocalPath &Path) {
return llvm::any_of(Path, [=](IndirectLocalPathEntry E) {
return E.Kind == IndirectLocalPathEntry::DefaultInit ||
E.Kind == IndirectLocalPathEntry::VarInit;
Expand Down Expand Up @@ -1076,7 +1076,7 @@ static SourceRange nextPathEntryRange(const IndirectLocalPath &Path, unsigned I,
return E->getSourceRange();
}

static bool pathOnlyHandlesGslPointer(IndirectLocalPath &Path) {
static bool pathOnlyHandlesGslPointer(const IndirectLocalPath &Path) {
for (const auto &It : llvm::reverse(Path)) {
switch (It.Kind) {
case IndirectLocalPathEntry::VarInit:
Expand Down Expand Up @@ -1124,24 +1124,23 @@ static void checkExprLifetimeImpl(Sema &SemaRef,

// FIXME: consider moving the TemporaryVisitor and visitLocalsRetained*
// functions to a dedicated class.
auto TemporaryVisitor = [&](IndirectLocalPath &Path, Local L,
auto TemporaryVisitor = [&](const IndirectLocalPath &Path, Local L,
ReferenceKind RK) -> bool {
SourceRange DiagRange = nextPathEntryRange(Path, 0, L);
SourceLocation DiagLoc = DiagRange.getBegin();

auto *MTE = dyn_cast<MaterializeTemporaryExpr>(L);

bool IsGslPtrValueFromGslTempOwner = false;
bool IsLocalGslOwner = false;
if (pathOnlyHandlesGslPointer(Path)) {
if (isa<DeclRefExpr>(L)) {
// We do not want to follow the references when returning a pointer
// originating from a local owner to avoid the following false positive:
// int &p = *localUniquePtr;
// someContainer.add(std::move(localUniquePtr));
// return p;
IsLocalGslOwner = isRecordWithAttr<OwnerAttr>(L->getType());
if (pathContainsInit(Path) || !IsLocalGslOwner)
if (pathContainsInit(Path) ||
!isRecordWithAttr<OwnerAttr>(L->getType()))
return false;
} else {
IsGslPtrValueFromGslTempOwner =
Expand Down
11 changes: 11 additions & 0 deletions clang/test/AST/ByteCode/builtin-bit-cast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ constexpr bool operator==(const struct bits<N, T, P>& lhs, const struct bits<N,
#ifdef __SIZEOF_INT128__
static_assert(check_round_trip<__int128_t>((__int128_t)34));
static_assert(check_round_trip<__int128_t>((__int128_t)-34));

constexpr unsigned char OneBit[] = {
0x1, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
};
constexpr __int128_t One = 1;
constexpr __int128_t Expected = One << 120;
static_assert(__builtin_bit_cast(__int128_t, OneBit) == (LITTLE_END ? 1 : Expected));

#endif

static_assert(check_round_trip<double>(17.0));
Expand Down
6 changes: 6 additions & 0 deletions clang/test/Headers/lasxintrin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %clang_cc1 %s -fsyntax-only -triple loongarch64 -target-feature +lasx
// RUN: not %clang_cc1 %s -fsyntax-only -triple loongarch64 -target-feature +lasx -flax-vector-conversions=none
// RUN: not %clang_cc1 %s -fsyntax-only -triple loongarch64 -target-feature +lasx -flax-vector-conversions=none -fno-signed-char
// FIXME: "not" should be removed once we fix GH#110834.

#include <lasxintrin.h>
6 changes: 6 additions & 0 deletions clang/test/Headers/lsxintrin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %clang_cc1 %s -fsyntax-only -triple loongarch64 -target-feature +lsx
// RUN: not %clang_cc1 %s -fsyntax-only -triple loongarch64 -target-feature +lsx -flax-vector-conversions=none
// RUN: not %clang_cc1 %s -fsyntax-only -triple loongarch64 -target-feature +lsx -flax-vector-conversions=none -fno-signed-char
// FIXME: "not" should be removed once we fix GH#110834.

#include <lsxintrin.h>
2 changes: 2 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24393,6 +24393,8 @@ TEST_F(FormatTest, DisableRegions) {
TEST_F(FormatTest, DoNotCrashOnInvalidInput) {
format("? ) =");
verifyNoCrash("#define a\\\n /**/}");
verifyNoCrash(" tst %o5 ! are we doing the gray case?\n"
"LY52: ! [internal]");
}

TEST_F(FormatTest, FormatsTableGenCode) {
Expand Down
7 changes: 7 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3571,6 +3571,13 @@ TEST_F(TokenAnnotatorTest, TemplateInstantiation) {
EXPECT_TOKEN(Tokens[18], tok::greater, TT_TemplateCloser);
}

TEST_F(TokenAnnotatorTest, SwitchInMacroArgument) {
auto Tokens = annotate("FOOBAR(switch);\n"
"void f() {}");
ASSERT_EQ(Tokens.size(), 12u) << Tokens;
EXPECT_TOKEN(Tokens[9], tok::l_brace, TT_FunctionLBrace);
}

} // namespace
} // namespace format
} // namespace clang
123 changes: 64 additions & 59 deletions compiler-rt/lib/tsan/rtl/tsan_interceptors_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
#include "sanitizer_common/sanitizer_platform.h"
#if SANITIZER_APPLE

#include "interception/interception.h"
#include "tsan_interceptors.h"
#include "tsan_interface.h"
#include "tsan_interface_ann.h"
#include "tsan_spinlock_defs_mac.h"
#include "sanitizer_common/sanitizer_addrhashmap.h"

#include <errno.h>
#include <libkern/OSAtomic.h>
#include <objc/objc-sync.h>
#include <os/lock.h>
#include <sys/ucontext.h>

#if defined(__has_include) && __has_include(<xpc/xpc.h>)
#include <xpc/xpc.h>
#endif // #if defined(__has_include) && __has_include(<xpc/xpc.h>)
# include <errno.h>
# include <libkern/OSAtomic.h>
# include <objc/objc-sync.h>
# include <os/lock.h>
# include <sys/ucontext.h>

# include "interception/interception.h"
# include "sanitizer_common/sanitizer_addrhashmap.h"
# include "tsan_interceptors.h"
# include "tsan_interface.h"
# include "tsan_interface_ann.h"
# include "tsan_spinlock_defs_mac.h"

# if defined(__has_include) && __has_include(<xpc/xpc.h>)
# include <xpc/xpc.h>
# endif // #if defined(__has_include) && __has_include(<xpc/xpc.h>)

typedef long long_t;

Expand Down Expand Up @@ -99,7 +99,7 @@ static constexpr morder kMacFailureOrder = morder::relaxed;

# pragma clang diagnostic push
// OSAtomic* functions are deprecated.
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
OSATOMIC_INTERCEPTORS_ARITHMETIC(OSAtomicAdd, fetch_add,
OSATOMIC_INTERCEPTOR_PLUS_X)
OSATOMIC_INTERCEPTORS_ARITHMETIC(OSAtomicIncrement, fetch_add,
Expand All @@ -113,25 +113,25 @@ OSATOMIC_INTERCEPTORS_BITWISE(OSAtomicAnd, fetch_and,
OSATOMIC_INTERCEPTORS_BITWISE(OSAtomicXor, fetch_xor,
OSATOMIC_INTERCEPTOR_PLUS_X, OSATOMIC_INTERCEPTOR)

#define OSATOMIC_INTERCEPTORS_CAS(f, tsan_atomic_f, tsan_t, t) \
TSAN_INTERCEPTOR(bool, f, t old_value, t new_value, t volatile *ptr) { \
SCOPED_TSAN_INTERCEPTOR(f, old_value, new_value, ptr); \
return tsan_atomic_f##_compare_exchange_strong( \
(volatile tsan_t *)ptr, (tsan_t *)&old_value, (tsan_t)new_value, \
kMacOrderNonBarrier, kMacFailureOrder); \
} \
\
TSAN_INTERCEPTOR(bool, f##Barrier, t old_value, t new_value, \
t volatile *ptr) { \
SCOPED_TSAN_INTERCEPTOR(f##Barrier, old_value, new_value, ptr); \
return tsan_atomic_f##_compare_exchange_strong( \
(volatile tsan_t *)ptr, (tsan_t *)&old_value, (tsan_t)new_value, \
kMacOrderBarrier, kMacFailureOrder); \
}
# define OSATOMIC_INTERCEPTORS_CAS(f, tsan_atomic_f, tsan_t, t) \
TSAN_INTERCEPTOR(bool, f, t old_value, t new_value, t volatile *ptr) { \
SCOPED_TSAN_INTERCEPTOR(f, old_value, new_value, ptr); \
return tsan_atomic_f##_compare_exchange_strong( \
(volatile tsan_t *)ptr, (tsan_t *)&old_value, (tsan_t)new_value, \
kMacOrderNonBarrier, kMacFailureOrder); \
} \
\
TSAN_INTERCEPTOR(bool, f##Barrier, t old_value, t new_value, \
t volatile *ptr) { \
SCOPED_TSAN_INTERCEPTOR(f##Barrier, old_value, new_value, ptr); \
return tsan_atomic_f##_compare_exchange_strong( \
(volatile tsan_t *)ptr, (tsan_t *)&old_value, (tsan_t)new_value, \
kMacOrderBarrier, kMacFailureOrder); \
}

#pragma clang diagnostic push
# pragma clang diagnostic push
// OSAtomicCompareAndSwap* functions are deprecated.
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
OSATOMIC_INTERCEPTORS_CAS(OSAtomicCompareAndSwapInt, __tsan_atomic32, a32, int)
OSATOMIC_INTERCEPTORS_CAS(OSAtomicCompareAndSwapLong, __tsan_atomic64, a64,
long_t)
Expand All @@ -141,21 +141,21 @@ OSATOMIC_INTERCEPTORS_CAS(OSAtomicCompareAndSwap32, __tsan_atomic32, a32,
int32_t)
OSATOMIC_INTERCEPTORS_CAS(OSAtomicCompareAndSwap64, __tsan_atomic64, a64,
int64_t)
#pragma clang diagnostic pop

#define OSATOMIC_INTERCEPTOR_BITOP(f, op, clear, mo) \
TSAN_INTERCEPTOR(bool, f, uint32_t n, volatile void *ptr) { \
SCOPED_TSAN_INTERCEPTOR(f, n, ptr); \
volatile char *byte_ptr = ((volatile char *)ptr) + (n >> 3); \
char bit = 0x80u >> (n & 7); \
char mask = clear ? ~bit : bit; \
char orig_byte = op((volatile a8 *)byte_ptr, mask, mo); \
return orig_byte & bit; \
}
# pragma clang diagnostic pop

# define OSATOMIC_INTERCEPTOR_BITOP(f, op, clear, mo) \
TSAN_INTERCEPTOR(bool, f, uint32_t n, volatile void *ptr) { \
SCOPED_TSAN_INTERCEPTOR(f, n, ptr); \
volatile char *byte_ptr = ((volatile char *)ptr) + (n >> 3); \
char bit = 0x80u >> (n & 7); \
char mask = clear ? ~bit : bit; \
char orig_byte = op((volatile a8 *)byte_ptr, mask, mo); \
return orig_byte & bit; \
}

#define OSATOMIC_INTERCEPTORS_BITOP(f, op, clear) \
OSATOMIC_INTERCEPTOR_BITOP(f, op, clear, kMacOrderNonBarrier) \
OSATOMIC_INTERCEPTOR_BITOP(f##Barrier, op, clear, kMacOrderBarrier)
# define OSATOMIC_INTERCEPTORS_BITOP(f, op, clear) \
OSATOMIC_INTERCEPTOR_BITOP(f, op, clear, kMacOrderNonBarrier) \
OSATOMIC_INTERCEPTOR_BITOP(f##Barrier, op, clear, kMacOrderBarrier)

OSATOMIC_INTERCEPTORS_BITOP(OSAtomicTestAndSet, __tsan_atomic8_fetch_or, false)
OSATOMIC_INTERCEPTORS_BITOP(OSAtomicTestAndClear, __tsan_atomic8_fetch_and,
Expand All @@ -171,12 +171,13 @@ TSAN_INTERCEPTOR(void, OSAtomicEnqueue, OSQueueHead *list, void *item,
TSAN_INTERCEPTOR(void *, OSAtomicDequeue, OSQueueHead *list, size_t offset) {
SCOPED_TSAN_INTERCEPTOR(OSAtomicDequeue, list, offset);
void *item = REAL(OSAtomicDequeue)(list, offset);
if (item) __tsan_acquire(item);
if (item)
__tsan_acquire(item);
return item;
}

// OSAtomicFifoEnqueue and OSAtomicFifoDequeue are only on OS X.
#if !SANITIZER_IOS
# if !SANITIZER_IOS

TSAN_INTERCEPTOR(void, OSAtomicFifoEnqueue, OSFifoQueueHead *list, void *item,
size_t offset) {
Expand All @@ -189,11 +190,12 @@ TSAN_INTERCEPTOR(void *, OSAtomicFifoDequeue, OSFifoQueueHead *list,
size_t offset) {
SCOPED_TSAN_INTERCEPTOR(OSAtomicFifoDequeue, list, offset);
void *item = REAL(OSAtomicFifoDequeue)(list, offset);
if (item) __tsan_acquire(item);
if (item)
__tsan_acquire(item);
return item;
}

#endif
# endif

TSAN_INTERCEPTOR(void, OSSpinLockLock, volatile OSSpinLock *lock) {
CHECK(!cur_thread()->is_dead);
Expand Down Expand Up @@ -298,7 +300,7 @@ TSAN_INTERCEPTOR(void, os_unfair_lock_unlock, os_unfair_lock_t lock) {
REAL(os_unfair_lock_unlock)(lock);
}

#if defined(__has_include) && __has_include(<xpc/xpc.h>)
# if defined(__has_include) && __has_include(<xpc/xpc.h>)

TSAN_INTERCEPTOR(void, xpc_connection_set_event_handler,
xpc_connection_t connection, xpc_handler_t handler) {
Expand Down Expand Up @@ -352,7 +354,7 @@ TSAN_INTERCEPTOR(void, xpc_connection_cancel, xpc_connection_t connection) {
REAL(xpc_connection_cancel)(connection);
}

#endif // #if defined(__has_include) && __has_include(<xpc/xpc.h>)
# endif // #if defined(__has_include) && __has_include(<xpc/xpc.h>)

// Determines whether the Obj-C object pointer is a tagged pointer. Tagged
// pointers encode the object data directly in their pointer bits and do not
Expand All @@ -375,7 +377,7 @@ static uptr GetOrCreateSyncAddress(uptr addr, ThreadState *thr, uptr pc) {
Map::Handle h(&Addresses, addr);
if (h.created()) {
ThreadIgnoreBegin(thr, pc);
*h = (uptr) user_alloc(thr, pc, /*size=*/1);
*h = (uptr)user_alloc(thr, pc, /*size=*/1);
ThreadIgnoreEnd(thr);
}
return *h;
Expand All @@ -393,7 +395,8 @@ static uptr SyncAddressForObjCObject(id obj, ThreadState *thr, uptr pc) {

TSAN_INTERCEPTOR(int, objc_sync_enter, id obj) {
SCOPED_TSAN_INTERCEPTOR(objc_sync_enter, obj);
if (!obj) return REAL(objc_sync_enter)(obj);
if (!obj)
return REAL(objc_sync_enter)(obj);
uptr addr = SyncAddressForObjCObject(obj, thr, pc);
MutexPreLock(thr, pc, addr, MutexFlagWriteReentrant);
int result = REAL(objc_sync_enter)(obj);
Expand All @@ -404,11 +407,13 @@ TSAN_INTERCEPTOR(int, objc_sync_enter, id obj) {

TSAN_INTERCEPTOR(int, objc_sync_exit, id obj) {
SCOPED_TSAN_INTERCEPTOR(objc_sync_exit, obj);
if (!obj) return REAL(objc_sync_exit)(obj);
if (!obj)
return REAL(objc_sync_exit)(obj);
uptr addr = SyncAddressForObjCObject(obj, thr, pc);
MutexUnlock(thr, pc, addr);
int result = REAL(objc_sync_exit)(obj);
if (result != OBJC_SYNC_SUCCESS) MutexInvalidAccess(thr, pc, addr);
if (result != OBJC_SYNC_SUCCESS)
MutexInvalidAccess(thr, pc, addr);
return result;
}

Expand Down Expand Up @@ -439,7 +444,7 @@ TSAN_INTERCEPTOR(int, swapcontext, ucontext_t *oucp, const ucontext_t *ucp) {

// On macOS, libc++ is always linked dynamically, so intercepting works the
// usual way.
#define STDCXX_INTERCEPTOR TSAN_INTERCEPTOR
# define STDCXX_INTERCEPTOR TSAN_INTERCEPTOR

namespace {
struct fake_shared_weak_count {
Expand Down
15 changes: 8 additions & 7 deletions compiler-rt/lib/tsan/rtl/tsan_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#define TSAN_INTERFACE_H

#include <sanitizer_common/sanitizer_internal_defs.h>
using __sanitizer::uptr;
using __sanitizer::tid_t;
using __sanitizer::uptr;

// This header should NOT include any other headers.
// All functions in this header are extern "C" and start with __tsan_.
Expand Down Expand Up @@ -203,17 +203,18 @@ int __tsan_get_alloc_stack(uptr addr, uptr *trace, uptr size, int *thread_id,
namespace __tsan {

// These should match declarations from public tsan_interface_atomic.h header.
typedef unsigned char a8;
typedef unsigned char a8;
typedef unsigned short a16;
typedef unsigned int a32;
typedef unsigned int a32;
typedef unsigned long long a64;
#if !SANITIZER_GO && (defined(__SIZEOF_INT128__) \
|| (__clang_major__ * 100 + __clang_minor__ >= 302)) && \
#if !SANITIZER_GO && \
(defined(__SIZEOF_INT128__) || \
(__clang_major__ * 100 + __clang_minor__ >= 302)) && \
!defined(__mips64) && !defined(__s390x__)
__extension__ typedef __int128 a128;
# define __TSAN_HAS_INT128 1
# define __TSAN_HAS_INT128 1
#else
# define __TSAN_HAS_INT128 0
# define __TSAN_HAS_INT128 0
#endif

// Part of ABI, do not change.
Expand Down
195 changes: 100 additions & 95 deletions compiler-rt/lib/tsan/rtl/tsan_interface_atomic.cpp

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions compiler-rt/test/asan/TestCases/alloca_vla_interact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
//
// REQUIRES: stable-runtime

// See https://github.com/llvm/llvm-project/issues/110956
// XFAIL: target=sparc{{.*}}

// This testcase checks correct interaction between VLAs and allocas.

#include <assert.h>
Expand Down
16 changes: 16 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,14 @@ if(LLVM_LIBC_INCLUDE_SCUDO)
endif()

set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
libc.src.complex.cimag
libc.src.complex.cimagf
libc.src.complex.cimagl

# fenv.h entrypoints
libc.src.fenv.feclearexcept
libc.src.fenv.fedisableexcept
Expand Down Expand Up @@ -603,6 +611,10 @@ set(TARGET_LIBM_ENTRYPOINTS

if(LIBC_TYPES_HAS_FLOAT16)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# complex.h C23 _Complex _Float16 entrypoints
# libc.src.complex.crealf16
# libc.src.complex.cimagf16

# math.h C23 _Float16 entrypoints
libc.src.math.canonicalizef16
libc.src.math.ceilf16
Expand Down Expand Up @@ -704,6 +716,10 @@ endif()

if(LIBC_TYPES_HAS_FLOAT128)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# complex.h C23 _Complex _Float128 entrypoints
libc.src.complex.crealf128
libc.src.complex.cimagf128

# math.h C23 _Float128 entrypoints
libc.src.math.canonicalizef128
libc.src.math.ceilf128
Expand Down
8 changes: 8 additions & 0 deletions libc/config/linux/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ if(LLVM_LIBC_INCLUDE_SCUDO)
endif()

set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
libc.src.complex.cimag
libc.src.complex.cimagf
libc.src.complex.cimagl

# fenv.h entrypoints
libc.src.fenv.feclearexcept
libc.src.fenv.fedisableexcept
Expand Down
12 changes: 12 additions & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,14 @@ if(LLVM_LIBC_INCLUDE_SCUDO)
endif()

set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
libc.src.complex.cimag
libc.src.complex.cimagf
libc.src.complex.cimagl

# fenv.h entrypoints
libc.src.fenv.feclearexcept
libc.src.fenv.fedisableexcept
Expand Down Expand Up @@ -606,6 +614,10 @@ set(TARGET_LIBM_ENTRYPOINTS

if(LIBC_TYPES_HAS_FLOAT128)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# complex.h C23 _Complex _Float128 entrypoints
libc.src.complex.crealf128
libc.src.complex.cimagf128

# math.h C23 _Float128 entrypoints
libc.src.math.canonicalizef128
libc.src.math.ceilf128
Expand Down
16 changes: 16 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,14 @@ if(LLVM_LIBC_INCLUDE_SCUDO)
endif()

set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
libc.src.complex.cimag
libc.src.complex.cimagf
libc.src.complex.cimagl

# fenv.h entrypoints
libc.src.fenv.feclearexcept
libc.src.fenv.fedisableexcept
Expand Down Expand Up @@ -606,6 +614,10 @@ set(TARGET_LIBM_ENTRYPOINTS

if(LIBC_TYPES_HAS_FLOAT16)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# complex.h C23 _Complex _Float16 entrypoints
libc.src.complex.crealf16
libc.src.complex.cimagf16

# math.h C23 _Float16 entrypoints
libc.src.math.canonicalizef16
libc.src.math.ceilf16
Expand Down Expand Up @@ -709,6 +721,10 @@ endif()

if(LIBC_TYPES_HAS_FLOAT128)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# complex.h C23 _Complex _Float128 entrypoints
# libc.src.complex.crealf128
# libc.src.complex.cimagf128

# math.h C23 _Float128 entrypoints
libc.src.math.canonicalizef128
libc.src.math.ceilf128
Expand Down
4 changes: 2 additions & 2 deletions libc/docs/complex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ Functions
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| carg | | | | | | 7.3.9.1 | N/A |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| cimag | | | | | | 7.3.9.2 | N/A |
| cimag | |check| | |check| | |check| | |check| | |check| | 7.3.9.2 | N/A |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| conj | | | | | | 7.3.9.4 | N/A |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| cproj | | | | | | 7.3.9.5 | N/A |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| creal | | | | | | 7.3.9.6 | N/A |
| creal | |check| | |check| | |check| | |check| | |check| | 7.3.9.6 | N/A |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
14 changes: 14 additions & 0 deletions libc/hdr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ add_proxy_header_library(
libc.include.signal
)

add_header_library(stdlib_overlay HDRS stdlib_overlay.h)

add_proxy_header_library(
stdlib_macros
HDRS
stdlib_macros.h
DEPENDS
.stdlib_overlay
FULL_BUILD_DEPENDS
libc.include.stdlib
libc.include.llvm-libc-macros.stdlib_macros
)

add_header_library(stdio_overlay HDRS stdio_overlay.h)

add_proxy_header_library(
Expand Down Expand Up @@ -182,3 +195,4 @@ add_proxy_header_library(
)

add_subdirectory(types)
add_subdirectory(func)
52 changes: 52 additions & 0 deletions libc/hdr/func/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
add_proxy_header_library(
aligned_alloc
HDRS
aligned_alloc.h
DEPENDS
libc.hdr.stdlib_overlay
FULL_BUILD_DEPENDS
libc.include.stdlib
libc.hdr.types.size_t
)

add_proxy_header_library(
malloc
HDRS
malloc.h
DEPENDS
libc.hdr.stdlib_overlay
FULL_BUILD_DEPENDS
libc.include.stdlib
libc.hdr.types.size_t
)

add_proxy_header_library(
realloc
HDRS
realloc.h
DEPENDS
libc.hdr.stdlib_overlay
FULL_BUILD_DEPENDS
libc.include.stdlib
libc.hdr.types.size_t
)

add_proxy_header_library(
free
HDRS
free.h
DEPENDS
libc.hdr.stdlib_overlay
FULL_BUILD_DEPENDS
libc.include.stdlib
)

add_proxy_header_library(
_Exit
HDRS
_Exit.h
DEPENDS
libc.hdr.stdlib_overlay
FULL_BUILD_DEPENDS
libc.include.stdlib
)
22 changes: 22 additions & 0 deletions libc/hdr/func/_Exit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Definition of the _Exit proxy -------------------------------------===//
//
// 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_HDR_FUNC_EXIT_H
#define LLVM_LIBC_HDR_FUNC_EXIT_H

#ifdef LIBC_FULL_BUILD
// We will use the `_Exit` declaration from our generated stdlib.h
#include <stdlib.h>

#else // Overlay mode

#include "hdr/stdlib_overlay.h"

#endif

#endif // LLVM_LIBC_HDR_EXIT_H
22 changes: 22 additions & 0 deletions libc/hdr/func/aligned_alloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Definition of the aligned_alloc.h proxy ---------------------------===//
//
// 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_HDR_FUNC_ALIGNED_ALLOC_H
#define LLVM_LIBC_HDR_FUNC_ALIGNED_ALLOC_H

#ifdef LIBC_FULL_BUILD
#include "hdr/types/size_t.h"
extern "C" void *aligned_alloc(size_t, size_t);

#else // Overlay mode

#include "hdr/stdlib_overlay.h"

#endif

#endif
21 changes: 21 additions & 0 deletions libc/hdr/func/free.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Definition of the free.h proxy ------------------------------------===//
//
// 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_HDR_FUNC_FREE_H
#define LLVM_LIBC_HDR_FUNC_FREE_H

#ifdef LIBC_FULL_BUILD
extern "C" void free(void *);

#else // Overlay mode

#include "hdr/stdlib_overlay.h"

#endif

#endif
22 changes: 22 additions & 0 deletions libc/hdr/func/malloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Definition of the malloc.h proxy ----------------------------------===//
//
// 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_HDR_FUNC_MALLOC_H
#define LLVM_LIBC_HDR_FUNC_MALLOC_H

#ifdef LIBC_FULL_BUILD
#include "hdr/types/size_t.h"
extern "C" void *malloc(size_t);

#else // Overlay mode

#include "hdr/stdlib_overlay.h"

#endif

#endif
22 changes: 22 additions & 0 deletions libc/hdr/func/realloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Definition of the realloc.h proxy ---------------------------------===//
//
// 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_HDR_FUNC_REALLOC_H
#define LLVM_LIBC_HDR_FUNC_REALLOC_H

#ifdef LIBC_FULL_BUILD
#include "hdr/types/size_t.h"
extern "C" void *realloc(void *ptr, size_t new_size);

#else // Overlay mode

#include "hdr/stdlib_overlay.h"

#endif

#endif
22 changes: 22 additions & 0 deletions libc/hdr/stdlib_macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Definition of macros from stdlib.h --------------------------------===//
//
// 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_HDR_STDLIB_MACROS_H
#define LLVM_LIBC_HDR_STDLIB_MACROS_H

#ifdef LIBC_FULL_BUILD

#include "include/llvm-libc-macros/stdlib-macros.h"

#else // Overlay mode

#include "stdlib_overlay.h"

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_STDLIB_MACROS_H
36 changes: 36 additions & 0 deletions libc/hdr/stdlib_overlay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===-- Including stdlib.h in overlay mode --------------------------------===//
//
// 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_HDR_STDLIB_OVERLAY_H
#define LLVM_LIBC_HDR_STDLIB_OVERLAY_H

#ifdef LIBC_FULL_BUILD
#error "This header should only be included in overlay mode"
#endif

// Overlay mode

// glibc <stdlib.h> header might provide extern inline definitions for few
// functions, causing external alias errors. They are guarded by
// `__USE_FORTIFY_LEVEL`, which will be temporarily disabled.

#ifdef __USE_FORTIFY_LEVEL
#define LIBC_OLD_USE_FORTIFY_LEVEL __USE_FORTIFY_LEVEL
#undef __USE_FORTIFY_LEVEL
#define __USE_FORTIFY_LEVEL 0
#endif

#include <stdlib.h>

#ifdef LIBC_OLD_USE_FORTIFY_LEVEL
#undef __USE_FORTIFY_LEVEL
#define __USE_FORTIFY_LEVEL LIBC_OLD_USE_FORTIFY_LEVEL
#undef LIBC_OLD_USE_FORTIFY_LEVEL
#endif

#endif
41 changes: 41 additions & 0 deletions libc/hdr/types/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
add_proxy_header_library(
div_t
HDRS
div_t.h
DEPENDS
libc.hdr.stdlib_overlay
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.div_t
libc.include.stdlib
)

add_proxy_header_library(
ldiv_t
HDRS
ldiv_t.h
DEPENDS
libc.hdr.stdlib_overlay
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.ldiv_t
libc.include.stdlib
)

add_proxy_header_library(
lldiv_t
HDRS
lldiv_t.h
DEPENDS
libc.hdr.stdlib_overlay
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.lldiv_t
libc.include.stdlib
)

add_proxy_header_library(
sigset_t
HDRS
Expand Down Expand Up @@ -46,6 +79,14 @@ add_proxy_header_library(
libc.include.llvm-libc-types.struct_timespec
)

add_proxy_header_library(
size_t
HDRS
size_t.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.size_t
)

add_proxy_header_library(
mode_t
HDRS
Expand Down
6 changes: 3 additions & 3 deletions libc/hdr/types/atexithandler_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_ATEXITHANDLER_T_H
#define LLVM_LIBC_HDR_ATEXITHANDLER_T_H
#ifndef LLVM_LIBC_HDR_TYPES_ATEXITHANDLER_T_H
#define LLVM_LIBC_HDR_TYPES_ATEXITHANDLER_T_H

#ifdef LIBC_FULL_BUILD

Expand All @@ -19,4 +19,4 @@

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_ATEXITHANDLER_T_H
#endif // LLVM_LIBC_HDR_TYPES_ATEXITHANDLER_T_H
22 changes: 22 additions & 0 deletions libc/hdr/types/div_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Definition of macros from div_t.h ---------------------------------===//
//
// 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_HDR_TYPES_DIV_T_H
#define LLVM_LIBC_HDR_TYPES_DIV_T_H

#ifdef LIBC_FULL_BUILD

#include "include/llvm-libc-types/div_t.h"

#else // Overlay mode

#include "hdr/stdlib_overlay.h"

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_TYPES_DIV_T_H
6 changes: 3 additions & 3 deletions libc/hdr/types/fenv_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_FENV_T_H
#define LLVM_LIBC_HDR_FENV_T_H
#ifndef LLVM_LIBC_HDR_TYPES_FENV_T_H
#define LLVM_LIBC_HDR_TYPES_FENV_T_H

#ifdef LIBC_FULL_BUILD

Expand All @@ -19,4 +19,4 @@

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_FENV_T_H
#endif // LLVM_LIBC_HDR_TYPES_FENV_T_H
6 changes: 3 additions & 3 deletions libc/hdr/types/fexcept_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_FEXCEPT_T_H
#define LLVM_LIBC_HDR_FEXCEPT_T_H
#ifndef LLVM_LIBC_HDR_TYPES_FEXCEPT_T_H
#define LLVM_LIBC_HDR_TYPES_FEXCEPT_T_H

#ifdef LIBC_FULL_BUILD

Expand All @@ -19,4 +19,4 @@

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_FENV_T_H
#endif // LLVM_LIBC_HDR_TYPES_FEXCEPT_T_H
4 changes: 2 additions & 2 deletions libc/hdr/types/jmp_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_JMP_BUF_H
#define LLVM_LIBC_HDR_JMP_BUF_H
#ifndef LLVM_LIBC_HDR_TYPES_JMP_BUF_H
#define LLVM_LIBC_HDR_TYPES_JMP_BUF_H

#ifdef LIBC_FULL_BUILD

Expand Down
22 changes: 22 additions & 0 deletions libc/hdr/types/ldiv_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Definition of macros from ldiv_t.h --------------------------------===//
//
// 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_HDR_TYPES_LDIV_T_H
#define LLVM_LIBC_HDR_TYPES_LDIV_T_H

#ifdef LIBC_FULL_BUILD

#include "include/llvm-libc-types/ldiv_t.h"

#else // Overlay mode

#include "hdr/stdlib_overlay.h"

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_TYPES_LDIV_T_H
22 changes: 22 additions & 0 deletions libc/hdr/types/lldiv_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Definition of macros from lldiv_t.h -------------------------------===//
//
// 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_HDR_TYPES_LLDIV_T_H
#define LLVM_LIBC_HDR_TYPES_LLDIV_T_H

#ifdef LIBC_FULL_BUILD

#include "include/llvm-libc-types/lldiv_t.h"

#else // Overlay mode

#include "hdr/stdlib_overlay.h"

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_TYPES_LLDIV_T_H
6 changes: 3 additions & 3 deletions libc/hdr/types/locale_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_LOCALE_T_H
#define LLVM_LIBC_HDR_LOCALE_T_H
#ifndef LLVM_LIBC_HDR_TYPES_LOCALE_T_H
#define LLVM_LIBC_HDR_TYPES_LOCALE_T_H

#ifdef LIBC_FULL_BUILD

Expand All @@ -19,4 +19,4 @@

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_LOCALE_T_H
#endif // LLVM_LIBC_HDR_TYPES_LOCALE_T_H
6 changes: 3 additions & 3 deletions libc/hdr/types/mode_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_MODE_T_H
#define LLVM_LIBC_HDR_MODE_T_H
#ifndef LLVM_LIBC_HDR_TYPES_MODE_T_H
#define LLVM_LIBC_HDR_TYPES_MODE_T_H

#ifdef LIBC_FULL_BUILD

Expand All @@ -19,4 +19,4 @@

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_MODE_T_H
#endif // LLVM_LIBC_HDR_TYPES_MODE_T_H
4 changes: 2 additions & 2 deletions libc/hdr/types/sighandler_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_SIGHANDLER_T_H
#define LLVM_LIBC_HDR_SIGHANDLER_T_H
#ifndef LLVM_LIBC_HDR_TYPES_SIGHANDLER_T_H
#define LLVM_LIBC_HDR_TYPES_SIGHANDLER_T_H

#ifdef LIBC_FULL_BUILD

Expand Down
23 changes: 23 additions & 0 deletions libc/hdr/types/size_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- Proxy for size_t --------------------------------------------------===//
//
// 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_HDR_TYPES_SIZE_T_H
#define LLVM_LIBC_HDR_TYPES_SIZE_T_H

#ifdef LIBC_FULL_BUILD

#include "include/llvm-libc-types/size_t.h"

#else

#define __need_size_t
#include <stddef.h>
#undef __need_size_t

#endif // LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_TYPES_SIZE_T_H
4 changes: 2 additions & 2 deletions libc/hdr/types/stack_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_STACK_T_H
#define LLVM_LIBC_HDR_STACK_T_H
#ifndef LLVM_LIBC_HDR_TYPES_STACK_T_H
#define LLVM_LIBC_HDR_TYPES_STACK_T_H

#ifdef LIBC_FULL_BUILD

Expand Down
6 changes: 3 additions & 3 deletions libc/hdr/types/suseconds_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_TIMES_SUSECONDS_T_H
#define LLVM_LIBC_HDR_TIMES_SUSECONDS_T_H
#ifndef LLVM_LIBC_HDR_TYPES_SUSECONDS_T_H
#define LLVM_LIBC_HDR_TYPES_SUSECONDS_T_H

#ifdef LIBC_FULL_BUILD

Expand All @@ -19,4 +19,4 @@

#endif // LLVM_LIBC_FULL_BUILD

#endif // #ifndef LLVM_LIBC_HDR_TIMES_SUSECONDS_T_H
#endif // #ifndef LLVM_LIBC_HDR_TYPES_SUSECONDS_T_H
1 change: 1 addition & 0 deletions libc/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_subdirectory(__support)

add_subdirectory(complex)
add_subdirectory(ctype)
add_subdirectory(dlfcn)
add_subdirectory(errno)
Expand Down
9 changes: 9 additions & 0 deletions libc/src/__support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ add_header_library(
libc.src.__support.CPP.limits
)

add_header_library(
complex_type
HDRS
complex_type.h
)

add_header_library(
integer_operations
HDRS
Expand Down Expand Up @@ -236,6 +242,9 @@ add_header_library(
HDRS
char_vector.h
DEPENDS
libc.hdr.func.free
libc.hdr.func.malloc
libc.hdr.func.realloc
libc.src.__support.common
)

Expand Down
8 changes: 6 additions & 2 deletions libc/src/__support/CPP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ add_header_library(
HDRS
string.h
DEPENDS
libc.include.stdlib
.string_view
libc.hdr.func.free
libc.hdr.func.malloc
libc.hdr.func.realloc
libc.src.__support.common
libc.src.__support.integer_to_string
libc.src.string.memory_utils.inline_memcpy
Expand Down Expand Up @@ -199,7 +201,9 @@ add_object_library(
HDRS
new.h
DEPENDS
libc.include.stdlib
libc.hdr.func.free
libc.hdr.func.malloc
libc.hdr.func.aligned_alloc
libc.src.__support.common
libc.src.__support.macros.properties.os
)
2 changes: 1 addition & 1 deletion libc/src/__support/CPP/new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//

#include "new.h"
#include <stdlib.h>
#include "hdr/func/free.h"

void operator delete(void *mem) noexcept { ::free(mem); }

Expand Down
4 changes: 3 additions & 1 deletion libc/src/__support/CPP/new.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_NEW_H
#define LLVM_LIBC_SRC___SUPPORT_CPP_NEW_H

#include "hdr/func/aligned_alloc.h"
#include "hdr/func/free.h"
#include "hdr/func/malloc.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/os.h"

#include <stddef.h> // For size_t
#include <stdlib.h> // For malloc, free etc.

// Defining members in the std namespace is not preferred. But, we do it here
// so that we can use it to define the operator new which takes std::align_val_t
Expand Down
4 changes: 3 additions & 1 deletion libc/src/__support/CPP/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_STRING_H
#define LLVM_LIBC_SRC___SUPPORT_CPP_STRING_H

#include "hdr/func/free.h"
#include "hdr/func/malloc.h"
#include "hdr/func/realloc.h"
#include "src/__support/CPP/string_view.h"
#include "src/__support/integer_to_string.h" // IntegerToString
#include "src/__support/macros/config.h"
Expand All @@ -17,7 +20,6 @@
#include "src/string/string_utils.h" // string_length

#include <stddef.h> // size_t
#include <stdlib.h> // malloc, free

namespace LIBC_NAMESPACE_DECL {
namespace cpp {
Expand Down
1 change: 1 addition & 0 deletions libc/src/__support/File/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ add_object_library(
libc.src.__support.error_or
libc.hdr.types.off_t
libc.hdr.stdio_macros
libc.hdr.func.realloc
)

add_object_library(
Expand Down
1 change: 0 additions & 1 deletion libc/src/__support/File/dir.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "src/__support/threads/mutex.h"

#include <dirent.h>
#include <stdlib.h>

namespace LIBC_NAMESPACE_DECL {

Expand Down
1 change: 1 addition & 0 deletions libc/src/__support/File/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "file.h"

#include "hdr/func/realloc.h"
#include "hdr/stdio_macros.h"
#include "hdr/types/off_t.h"
#include "src/__support/CPP/new.h"
Expand Down
4 changes: 3 additions & 1 deletion libc/src/__support/char_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_CHARVECTOR_H
#define LLVM_LIBC_SRC___SUPPORT_CHARVECTOR_H

#include "hdr/func/free.h"
#include "hdr/func/malloc.h"
#include "hdr/func/realloc.h"
#include "src/__support/common.h" // LIBC_INLINE
#include "src/__support/macros/config.h"

#include <stddef.h> // size_t
#include <stdlib.h> // malloc, realloc, free

namespace LIBC_NAMESPACE_DECL {

Expand Down
20 changes: 20 additions & 0 deletions libc/src/__support/complex_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- complex type --------------------------------------------*- 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___SUPPORT_COMPLEX_TYPE_H
#define LLVM_LIBC_SRC___SUPPORT_COMPLEX_TYPE_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {
template <typename T> struct Complex {
T real;
T imag;
};
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_COMPLEX_TYPE_H
26 changes: 26 additions & 0 deletions libc/src/complex/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
add_subdirectory(generic)

function(add_complex_entrypoint_object name)
get_fq_target_name("generic.${name}" fq_generic_target_name)
if(TARGET ${fq_generic_target_name})
add_entrypoint_object(
${name}
ALIAS
DEPENDS
.generic.${name}
)
return()
endif()
endfunction()

add_complex_entrypoint_object(creal)
add_complex_entrypoint_object(crealf)
add_complex_entrypoint_object(creall)
add_complex_entrypoint_object(crealf16)
add_complex_entrypoint_object(crealf128)

add_complex_entrypoint_object(cimag)
add_complex_entrypoint_object(cimagf)
add_complex_entrypoint_object(cimagl)
add_complex_entrypoint_object(cimagf16)
add_complex_entrypoint_object(cimagf128)
20 changes: 20 additions & 0 deletions libc/src/complex/cimag.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for cimag -------------------------*- 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_COMPLEX_CIMAG_H
#define LLVM_LIBC_SRC_COMPLEX_CIMAG_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

double cimag(_Complex double x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CIMAG_H
20 changes: 20 additions & 0 deletions libc/src/complex/cimagf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for cimagf ------------------------*- 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_COMPLEX_CIMAGF_H
#define LLVM_LIBC_SRC_COMPLEX_CIMAGF_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

float cimagf(_Complex float x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CIMAGF_H
27 changes: 27 additions & 0 deletions libc/src/complex/cimagf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===-- Implementation header for cimagf128 ---------------------*- 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
//
//===----------------------------------------------------------------------===//

#include "src/__support/macros/properties/complex_types.h"
#include "src/__support/macros/properties/types.h"

#if defined(LIBC_TYPES_HAS_CFLOAT128)

#ifndef LLVM_LIBC_SRC_COMPLEX_CIMAGF128_H
#define LLVM_LIBC_SRC_COMPLEX_CIMAGF128_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

float128 cimagf128(cfloat128 x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CIMAGF128_H

#endif // LIBC_TYPES_HAS_CFLOAT128
27 changes: 27 additions & 0 deletions libc/src/complex/cimagf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===-- Implementation header for cimagf16 ----------------------*- 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
//
//===----------------------------------------------------------------------===//

#include "src/__support/macros/properties/complex_types.h"
#include "src/__support/macros/properties/types.h"

#if defined(LIBC_TYPES_HAS_CFLOAT16)

#ifndef LLVM_LIBC_SRC_COMPLEX_CIMAGF16_H
#define LLVM_LIBC_SRC_COMPLEX_CIMAGF16_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

float16 cimagf16(cfloat16 x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CIMAGF16_H

#endif // LIBC_TYPES_HAS_CFLOAT16
20 changes: 20 additions & 0 deletions libc/src/complex/cimagl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for cimagl ------------------------*- 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_COMPLEX_CIMAGL_H
#define LLVM_LIBC_SRC_COMPLEX_CIMAGL_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

long double cimagl(_Complex long double x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CIMAGL_H
20 changes: 20 additions & 0 deletions libc/src/complex/creal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for creal -------------------------*- 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_COMPLEX_CREAL_H
#define LLVM_LIBC_SRC_COMPLEX_CREAL_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

double creal(_Complex double x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CREAL_H
20 changes: 20 additions & 0 deletions libc/src/complex/crealf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for crealf ------------------------*- 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_COMPLEX_CREALF_H
#define LLVM_LIBC_SRC_COMPLEX_CREALF_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

float crealf(_Complex float x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CREALF_H
27 changes: 27 additions & 0 deletions libc/src/complex/crealf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===-- Implementation header for crealf128 ---------------------*- 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
//
//===----------------------------------------------------------------------===//

#include "src/__support/macros/properties/complex_types.h"
#include "src/__support/macros/properties/types.h"

#if defined(LIBC_TYPES_HAS_CFLOAT128)

#ifndef LLVM_LIBC_SRC_COMPLEX_CREALF128_H
#define LLVM_LIBC_SRC_COMPLEX_CREALF128_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

float128 crealf128(cfloat128 x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CREALF128_H

#endif // LIBC_TYPES_HAS_CFLOAT128
27 changes: 27 additions & 0 deletions libc/src/complex/crealf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===-- Implementation header for crealf16 ----------------------*- 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
//
//===----------------------------------------------------------------------===//

#include "src/__support/macros/properties/complex_types.h"
#include "src/__support/macros/properties/types.h"

#if defined(LIBC_TYPES_HAS_CFLOAT16)

#ifndef LLVM_LIBC_SRC_COMPLEX_CREALF16_H
#define LLVM_LIBC_SRC_COMPLEX_CREALF16_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

float16 crealf16(cfloat16 x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CREALF16_H

#endif // LIBC_TYPES_HAS_CFLOAT16
20 changes: 20 additions & 0 deletions libc/src/complex/creall.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for creall ------------------------*- 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_COMPLEX_CREALL_H
#define LLVM_LIBC_SRC_COMPLEX_CREALL_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

long double creall(_Complex long double x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CREALL_H
137 changes: 137 additions & 0 deletions libc/src/complex/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
add_entrypoint_object(
creal
SRCS
creal.cpp
HDRS
../creal.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.CPP.bit
libc.src.__support.complex_type
)

add_entrypoint_object(
crealf
SRCS
crealf.cpp
HDRS
../crealf.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.CPP.bit
libc.src.__support.complex_type
)

add_entrypoint_object(
creall
SRCS
creall.cpp
HDRS
../creall.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.CPP.bit
libc.src.__support.complex_type
)

add_entrypoint_object(
crealf16
SRCS
crealf16.cpp
HDRS
../crealf16.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.CPP.bit
libc.src.__support.complex_type
libc.src.__support.macros.properties.types
libc.src.__support.macros.properties.complex_types
)

add_entrypoint_object(
crealf128
SRCS
crealf128.cpp
HDRS
../crealf128.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.CPP.bit
libc.src.__support.complex_type
libc.src.__support.macros.properties.types
libc.src.__support.macros.properties.complex_types
)

add_entrypoint_object(
cimag
SRCS
cimag.cpp
HDRS
../cimag.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.CPP.bit
libc.src.__support.complex_type
)

add_entrypoint_object(
cimagf
SRCS
cimagf.cpp
HDRS
../cimagf.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.CPP.bit
libc.src.__support.complex_type
)

add_entrypoint_object(
cimagl
SRCS
cimagl.cpp
HDRS
../cimagl.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.CPP.bit
libc.src.__support.complex_type
)

add_entrypoint_object(
cimagf16
SRCS
cimagf16.cpp
HDRS
../cimagf16.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.CPP.bit
libc.src.__support.complex_type
libc.src.__support.macros.properties.types
libc.src.__support.macros.properties.complex_types
)

add_entrypoint_object(
cimagf128
SRCS
cimagf128.cpp
HDRS
../cimagf128.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.CPP.bit
libc.src.__support.complex_type
libc.src.__support.macros.properties.types
libc.src.__support.macros.properties.complex_types
)
21 changes: 21 additions & 0 deletions libc/src/complex/generic/cimag.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation of cimag function ----------------------------------===//
//
// 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/complex/cimag.h"
#include "src/__support/CPP/bit.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(double, cimag, (_Complex double x)) {
Complex<double> x_c = cpp::bit_cast<Complex<double>>(x);
return x_c.imag;
}

} // namespace LIBC_NAMESPACE_DECL
21 changes: 21 additions & 0 deletions libc/src/complex/generic/cimagf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation of cimagf function ---------------------------------===//
//
// 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/complex/cimagf.h"
#include "src/__support/CPP/bit.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float, cimagf, (_Complex float x)) {
Complex<float> x_c = cpp::bit_cast<Complex<float>>(x);
return x_c.imag;
}

} // namespace LIBC_NAMESPACE_DECL
25 changes: 25 additions & 0 deletions libc/src/complex/generic/cimagf128.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===-- Implementation of cimagf128 function ------------------------------===//
//
// 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/complex/cimagf128.h"
#if defined(LIBC_TYPES_HAS_CFLOAT128)

#include "src/__support/CPP/bit.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float128, cimagf128, (cfloat128 x)) {
Complex<float128> x_c = cpp::bit_cast<Complex<float128>>(x);
return x_c.imag;
}

} // namespace LIBC_NAMESPACE_DECL

#endif // LIBC_TYPES_HAS_CFLOAT128
25 changes: 25 additions & 0 deletions libc/src/complex/generic/cimagf16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===-- Implementation of cimagf16 function -------------------------------===//
//
// 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/complex/cimagf16.h"
#if defined(LIBC_TYPES_HAS_CFLOAT16)

#include "src/__support/CPP/bit.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float16, cimagf16, (cfloat16 x)) {
Complex<float16> x_c = cpp::bit_cast<Complex<float16>>(x);
return x_c.imag;
}

} // namespace LIBC_NAMESPACE_DECL

#endif // LIBC_TYPES_HAS_CFLOAT16
21 changes: 21 additions & 0 deletions libc/src/complex/generic/cimagl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation of cimagl function ---------------------------------===//
//
// 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/complex/cimagl.h"
#include "src/__support/CPP/bit.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(long double, cimagl, (_Complex long double x)) {
Complex<long double> x_c = cpp::bit_cast<Complex<long double>>(x);
return x_c.imag;
}

} // namespace LIBC_NAMESPACE_DECL
21 changes: 21 additions & 0 deletions libc/src/complex/generic/creal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation of creal function ----------------------------------===//
//
// 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/complex/creal.h"
#include "src/__support/CPP/bit.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(double, creal, (_Complex double x)) {
Complex<double> x_c = cpp::bit_cast<Complex<double>>(x);
return x_c.real;
}

} // namespace LIBC_NAMESPACE_DECL
21 changes: 21 additions & 0 deletions libc/src/complex/generic/crealf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation of crealf function ---------------------------------===//
//
// 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/complex/crealf.h"
#include "src/__support/CPP/bit.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float, crealf, (_Complex float x)) {
Complex<float> x_c = cpp::bit_cast<Complex<float>>(x);
return x_c.real;
}

} // namespace LIBC_NAMESPACE_DECL
25 changes: 25 additions & 0 deletions libc/src/complex/generic/crealf128.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===-- Implementation of crealf128 function ------------------------------===//
//
// 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/complex/crealf128.h"
#if defined(LIBC_TYPES_HAS_CFLOAT128)

#include "src/__support/CPP/bit.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float128, crealf128, (cfloat128 x)) {
Complex<float128> x_c = cpp::bit_cast<Complex<float128>>(x);
return x_c.real;
}

} // namespace LIBC_NAMESPACE_DECL

#endif // LIBC_TYPES_HAS_CFLOAT128
25 changes: 25 additions & 0 deletions libc/src/complex/generic/crealf16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===-- Implementation of crealf16 function -------------------------------===//
//
// 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/complex/crealf16.h"
#if defined(LIBC_TYPES_HAS_CFLOAT16)

#include "src/__support/CPP/bit.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float16, crealf16, (cfloat16 x)) {
Complex<float16> x_c = cpp::bit_cast<Complex<float16>>(x);
return x_c.real;
}

} // namespace LIBC_NAMESPACE_DECL

#endif // LIBC_TYPES_HAS_CFLOAT16
21 changes: 21 additions & 0 deletions libc/src/complex/generic/creall.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation of creall function ---------------------------------===//
//
// 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/complex/creall.h"
#include "src/__support/CPP/bit.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(long double, creall, (_Complex long double x)) {
Complex<long double> x_c = cpp::bit_cast<Complex<long double>>(x);
return x_c.real;
}

} // namespace LIBC_NAMESPACE_DECL
5 changes: 3 additions & 2 deletions libc/src/stdio/printf_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ add_header_library(
HDRS
vasprintf_internal.h
DEPENDS
libc.hdr.func.malloc
libc.hdr.func.free
libc.hdr.func.realloc
libc.src.__support.arg_list
libc.src.stdio.printf_core.printf_main
libc.src.stdio.printf_core.writer
libc.src.stdlib.malloc
libc.src.stdlib.realloc
)

if(NOT (TARGET libc.src.__support.File.file) AND LLVM_LIBC_FULL_BUILD)
Expand Down
4 changes: 3 additions & 1 deletion libc/src/stdio/printf_core/vasprintf_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
//
//===----------------------------------------------------------------------===//

#include "hdr/func/free.h"
#include "hdr/func/malloc.h"
#include "hdr/func/realloc.h"
#include "src/__support/arg_list.h"
#include "src/stdio/printf.h"
#include "src/stdio/printf_core/core_structs.h"
#include "src/stdio/printf_core/printf_main.h"
#include "src/stdio/printf_core/writer.h"
#include <stdlib.h> // malloc, realloc, free

namespace LIBC_NAMESPACE_DECL {
namespace printf_core {
Expand Down
13 changes: 6 additions & 7 deletions libc/src/stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ add_entrypoint_object(
HDRS
div.h
DEPENDS
libc.include.stdlib
libc.hdr.types.div_t
libc.src.__support.integer_operations
)

Expand All @@ -232,7 +232,7 @@ add_entrypoint_object(
HDRS
ldiv.h
DEPENDS
libc.include.stdlib
libc.hdr.types.ldiv_t
libc.src.__support.integer_operations
)

Expand All @@ -243,7 +243,7 @@ add_entrypoint_object(
HDRS
lldiv.h
DEPENDS
libc.include.stdlib
libc.hdr.types.lldiv_t
libc.src.__support.integer_operations
)

Expand Down Expand Up @@ -277,7 +277,7 @@ add_entrypoint_object(
qsort.h
DEPENDS
.qsort_util
libc.include.stdlib
libc.hdr.types.size_t
)

add_entrypoint_object(
Expand All @@ -288,7 +288,7 @@ add_entrypoint_object(
qsort_r.h
DEPENDS
.qsort_util
libc.include.stdlib
libc.hdr.types.size_t
)

add_object_library(
Expand All @@ -309,7 +309,7 @@ add_entrypoint_object(
rand.h
DEPENDS
.rand_util
libc.include.stdlib
libc.hdr.stdlib_macros
libc.src.__support.threads.sleep
)

Expand All @@ -321,7 +321,6 @@ add_entrypoint_object(
srand.h
DEPENDS
.rand_util
libc.include.stdlib
)

if(NOT LIBC_TARGET_OS_IS_GPU)
Expand Down
2 changes: 1 addition & 1 deletion libc/src/stdlib/div.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_SRC_STDLIB_DIV_H
#define LLVM_LIBC_SRC_STDLIB_DIV_H

#include "hdr/types/div_t.h"
#include "src/__support/macros/config.h"
#include <stdlib.h>

namespace LIBC_NAMESPACE_DECL {

Expand Down
1 change: 0 additions & 1 deletion libc/src/stdlib/exit.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define LLVM_LIBC_SRC_STDLIB_EXIT_H

#include "src/__support/macros/config.h"
#include <stdlib.h>

namespace LIBC_NAMESPACE_DECL {

Expand Down
1 change: 0 additions & 1 deletion libc/src/stdlib/free.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//

#include "src/__support/macros/config.h"
#include <stdlib.h>

#ifndef LLVM_LIBC_SRC_STDLIB_FREE_H
#define LLVM_LIBC_SRC_STDLIB_FREE_H
Expand Down
2 changes: 1 addition & 1 deletion libc/src/stdlib/ldiv.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_SRC_STDLIB_LDIV_H
#define LLVM_LIBC_SRC_STDLIB_LDIV_H

#include "hdr/types/ldiv_t.h"
#include "src/__support/macros/config.h"
#include <stdlib.h>

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/stdlib/lldiv.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#ifndef LLVM_LIBC_SRC_STDLIB_LLDIV_H
#define LLVM_LIBC_SRC_STDLIB_LLDIV_H

#include "hdr/types/lldiv_t.h"
#include "src/__support/macros/config.h"
#include <stdlib.h>

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/stdlib/malloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#include "hdr/types/size_t.h"
#include "src/__support/macros/config.h"
#include <stdlib.h>

#ifndef LLVM_LIBC_SRC_STDLIB_MALLOC_H
#define LLVM_LIBC_SRC_STDLIB_MALLOC_H
Expand Down
2 changes: 1 addition & 1 deletion libc/src/stdlib/qsort.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_SRC_STDLIB_QSORT_H
#define LLVM_LIBC_SRC_STDLIB_QSORT_H

#include "hdr/types/size_t.h"
#include "src/__support/macros/config.h"
#include <stdlib.h>

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/stdlib/qsort_r.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_SRC_STDLIB_QSORT_R_H
#define LLVM_LIBC_SRC_STDLIB_QSORT_R_H

#include "hdr/types/size_t.h"
#include "src/__support/macros/config.h"
#include <stdlib.h>

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/stdlib/rand.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_SRC_STDLIB_RAND_H
#define LLVM_LIBC_SRC_STDLIB_RAND_H

#include "hdr/stdlib_macros.h"
#include "src/__support/macros/config.h"
#include <stdlib.h>

namespace LIBC_NAMESPACE_DECL {

Expand Down
1 change: 0 additions & 1 deletion libc/src/stdlib/srand.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define LLVM_LIBC_SRC_STDLIB_SRAND_H

#include "src/__support/macros/config.h"
#include <stdlib.h>

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ add_entrypoint_object(
DEPENDS
.memory_utils.inline_memcpy
.string_utils
libc.include.stdlib
libc.hdr.stdlib_macros
libc.src.errno.errno
libc.include.llvm-libc-types.size_t
)
Expand Down
3 changes: 1 addition & 2 deletions libc/src/string/strdup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
//===----------------------------------------------------------------------===//

#include "src/string/strdup.h"
#include "hdr/stdlib_macros.h"
#include "src/__support/macros/config.h"
#include "src/errno/libc_errno.h"
#include "src/string/allocating_string_utils.h"
#include "src/string/memory_utils/inline_memcpy.h"

#include "src/__support/common.h"

#include <stdlib.h>

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(char *, strdup, (const char *src)) {
Expand Down
1 change: 0 additions & 1 deletion libc/src/unistd/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ add_entrypoint_object(
HDRS
../getcwd.h
DEPENDS
libc.include.stdlib
libc.include.unistd
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
Expand Down
1 change: 0 additions & 1 deletion libc/src/unistd/linux/getcwd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include "src/errno/libc_errno.h"
#include <linux/limits.h> // This is safe to include without any name pollution.
#include <stdlib.h>
#include <sys/syscall.h> // For syscall numbers.

namespace LIBC_NAMESPACE_DECL {
Expand Down
1 change: 1 addition & 0 deletions libc/test/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function(add_fp_unittest name)
endfunction(add_fp_unittest)

add_subdirectory(__support)
add_subdirectory(complex)
add_subdirectory(ctype)
add_subdirectory(errno)
add_subdirectory(fenv)
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/__support/File/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ add_libc_test(
LibcMemoryHelpers
DEPENDS
libc.include.stdio
libc.include.stdlib
libc.hdr.types.size_t
libc.src.errno.errno
libc.src.__support.CPP.new
libc.src.__support.File.file
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/__support/File/file_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "test/UnitTest/MemoryMatcher.h"
#include "test/UnitTest/Test.h"

#include <stdlib.h>
#include "hdr/types/size_t.h"

using ModeFlags = LIBC_NAMESPACE::File::ModeFlags;
using MemoryView = LIBC_NAMESPACE::testing::MemoryView;
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/__support/str_to_float_comparison_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// #include "src/__support/str_float_conv_utils.h"

#include <stdlib.h>
#include <stdlib.h> // For string to float functions

// #include "src/__support/FPUtil/FPBits.h"

Expand Down
74 changes: 74 additions & 0 deletions libc/test/src/complex/CImagTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//===-- Utility class to test different flavors of cimag --------*- 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_TEST_SRC_COMPLEX_CIMAGTEST_H
#define LLVM_LIBC_TEST_SRC_COMPLEX_CIMAGTEST_H

#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"

#include "hdr/math_macros.h"

template <typename CFPT, typename FPT>
class CImagTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {

DECLARE_SPECIAL_CONSTANTS(FPT)

public:
typedef FPT (*CImagFunc)(CFPT);

void testSpecialNumbers(CImagFunc func) {
EXPECT_FP_EQ(func(CFPT(67.123 + aNaN * 1.0i)), aNaN);
EXPECT_FP_EQ(func(CFPT(78.319 + neg_aNaN * 1.0i)), neg_aNaN);
EXPECT_FP_EQ(func(CFPT(7813.131 + sNaN * 1.0i)), sNaN);
EXPECT_FP_EQ(func(CFPT(7824.152 + neg_sNaN * 1.0i)), neg_sNaN);
EXPECT_FP_EQ(func(CFPT(9024.2442 + inf * 1.0i)), inf);
EXPECT_FP_EQ(func(CFPT(8923.124 + neg_inf * 1.0i)), neg_inf);
EXPECT_FP_EQ(func(CFPT(782.124 + min_normal * 1.0i)), min_normal);
EXPECT_FP_EQ(func(CFPT(2141.2352 + max_normal * 1.0i)), max_normal);
EXPECT_FP_EQ(func(CFPT(341.134 + neg_max_normal * 1.0i)), neg_max_normal);
EXPECT_FP_EQ(func(CFPT(781.142 + min_denormal * 1.0i)), min_denormal);
EXPECT_FP_EQ(func(CFPT(781.134 + neg_min_denormal * 1.0i)),
neg_min_denormal);
EXPECT_FP_EQ(func(CFPT(1241.112 + max_denormal * 1.0i)), max_denormal);
EXPECT_FP_EQ(func(CFPT(121.121 + zero * 1.0i)), zero);
EXPECT_FP_EQ(func(CFPT(neg_zero + zero * 1.0i)), zero);
EXPECT_FP_EQ(func(CFPT(neg_zero + neg_zero * 1.0i)), neg_zero);
EXPECT_FP_EQ(func(CFPT(zero + neg_zero * 1.0i)), neg_zero);
}

void testRoundedNumbers(CImagFunc func) {
EXPECT_FP_EQ(func((CFPT)(4523.1413 + 12413.1414i)), (FPT)(12413.1414));
EXPECT_FP_EQ(func((CFPT)(-4523.1413 + 12413.1414i)), (FPT)(12413.1414));
EXPECT_FP_EQ(func((CFPT)(4523.1413 - 12413.1414i)), (FPT)(-12413.1414));
EXPECT_FP_EQ(func((CFPT)(-4523.1413 - 12413.1414i)), (FPT)(-12413.1414));

EXPECT_FP_EQ(func((CFPT)(3210.5678 + 9876.5432i)), (FPT)(9876.5432));
EXPECT_FP_EQ(func((CFPT)(-3210.5678 + 9876.5432i)), (FPT)(9876.5432));
EXPECT_FP_EQ(func((CFPT)(3210.5678 - 9876.5432i)), (FPT)(-9876.5432));
EXPECT_FP_EQ(func((CFPT)(-3210.5678 - 9876.5432i)), (FPT)(-9876.5432));

EXPECT_FP_EQ(func((CFPT)(1234.4321 + 4321.1234i)), (FPT)(4321.1234));
EXPECT_FP_EQ(func((CFPT)(-1234.4321 + 4321.1234i)), (FPT)(4321.1234));
EXPECT_FP_EQ(func((CFPT)(1234.4321 - 4321.1234i)), (FPT)(-4321.1234));
EXPECT_FP_EQ(func((CFPT)(-1234.4321 - 4321.1234i)), (FPT)(-4321.1234));

EXPECT_FP_EQ(func((CFPT)(6789.1234 + 8765.6789i)), (FPT)(8765.6789));
EXPECT_FP_EQ(func((CFPT)(-6789.1234 + 8765.6789i)), (FPT)(8765.6789));
EXPECT_FP_EQ(func((CFPT)(6789.1234 - 8765.6789i)), (FPT)(-8765.6789));
EXPECT_FP_EQ(func((CFPT)(-6789.1234 - 8765.6789i)), (FPT)(-8765.6789));
}
};

#define LIST_CIMAG_TESTS(U, T, func) \
using LlvmLibcCImagTest = CImagTest<U, T>; \
TEST_F(LlvmLibcCImagTest, SpecialNumbers) { testSpecialNumbers(&func); } \
TEST_F(LlvmLibcCImagTest, RoundedNumbers) { testRoundedNumbers(&func); }

#endif // LLVM_LIBC_TEST_SRC_COMPLEX_CIMAGTEST_H
121 changes: 121 additions & 0 deletions libc/test/src/complex/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
add_custom_target(libc-complex-unittests)

add_libc_test(
creal_test
SUITE
libc-complex-unittests
SRCS
creal_test.cpp
DEPENDS
libc.src.complex.creal
LINK_LIBRARIES
LibcFPTestHelpers
)

add_libc_test(
crealf_test
SUITE
libc-complex-unittests
SRCS
crealf_test.cpp
DEPENDS
libc.src.complex.crealf
LINK_LIBRARIES
LibcFPTestHelpers
)

add_libc_test(
creall_test
SUITE
libc-complex-unittests
SRCS
creall_test.cpp
DEPENDS
libc.src.complex.creall
LINK_LIBRARIES
LibcFPTestHelpers
)

add_libc_test(
crealf16_test
SUITE
libc-complex-unittests
SRCS
crealf16_test.cpp
DEPENDS
libc.src.complex.crealf16
LINK_LIBRARIES
LibcFPTestHelpers
)

add_libc_test(
crealf128_test
SUITE
libc-complex-unittests
SRCS
crealf128_test.cpp
DEPENDS
libc.src.complex.crealf128
LINK_LIBRARIES
LibcFPTestHelpers
)

add_libc_test(
cimag_test
SUITE
libc-complex-unittests
SRCS
cimag_test.cpp
DEPENDS
libc.src.complex.cimag
LINK_LIBRARIES
LibcFPTestHelpers
)

add_libc_test(
cimagf_test
SUITE
libc-complex-unittests
SRCS
cimagf_test.cpp
DEPENDS
libc.src.complex.cimagf
LINK_LIBRARIES
LibcFPTestHelpers
)

add_libc_test(
cimagl_test
SUITE
libc-complex-unittests
SRCS
cimagl_test.cpp
DEPENDS
libc.src.complex.cimagl
LINK_LIBRARIES
LibcFPTestHelpers
)

add_libc_test(
cimagf16_test
SUITE
libc-complex-unittests
SRCS
cimagf16_test.cpp
DEPENDS
libc.src.complex.cimagf16
LINK_LIBRARIES
LibcFPTestHelpers
)

add_libc_test(
cimagf128_test
SUITE
libc-complex-unittests
SRCS
cimagf128_test.cpp
DEPENDS
libc.src.complex.cimagf128
LINK_LIBRARIES
LibcFPTestHelpers
)
72 changes: 72 additions & 0 deletions libc/test/src/complex/CRealTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//===-- Utility class to test different flavors of creal --------*- 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_TEST_SRC_COMPLEX_CREALTEST_H
#define LLVM_LIBC_TEST_SRC_COMPLEX_CREALTEST_H

#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"

#include "hdr/math_macros.h"

template <typename CFPT, typename FPT>
class CRealTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {

DECLARE_SPECIAL_CONSTANTS(FPT)

public:
typedef FPT (*CRealFunc)(CFPT);

void testSpecialNumbers(CRealFunc func) {
EXPECT_FP_EQ(func(CFPT(aNaN + 67.123i)), aNaN);
EXPECT_FP_EQ(func(CFPT(neg_aNaN + 78.319i)), neg_aNaN);
EXPECT_FP_EQ(func(CFPT(sNaN + 7813.131i)), sNaN);
EXPECT_FP_EQ(func(CFPT(neg_sNaN + 7824.152i)), neg_sNaN);
EXPECT_FP_EQ(func(CFPT(inf + 9024.2442i)), inf);
EXPECT_FP_EQ(func(CFPT(neg_inf + 8923.124i)), neg_inf);
EXPECT_FP_EQ(func(CFPT(min_normal + 782.124i)), min_normal);
EXPECT_FP_EQ(func(CFPT(max_normal + 2141.2352i)), max_normal);
EXPECT_FP_EQ(func(CFPT(neg_max_normal + 341.134i)), neg_max_normal);
EXPECT_FP_EQ(func(CFPT(min_denormal + 781.142i)), min_denormal);
EXPECT_FP_EQ(func(CFPT(neg_min_denormal + 781.134i)), neg_min_denormal);
EXPECT_FP_EQ(func(CFPT(max_denormal + 1241.112i)), max_denormal);
EXPECT_FP_EQ(func(CFPT(zero + 121.121i)), zero);
EXPECT_FP_EQ(func(CFPT(neg_zero + neg_zero * 1.0i)), neg_zero);
EXPECT_FP_EQ(func(CFPT(neg_zero + zero * 1.0i)), zero);
}

void testRoundedNumbers(CRealFunc func) {
EXPECT_FP_EQ(func((CFPT)(4523.1413 + 12413.1414i)), (FPT)(4523.1413));
EXPECT_FP_EQ(func((CFPT)(-4523.1413 + 12413.1414i)), (FPT)(-4523.1413));
EXPECT_FP_EQ(func((CFPT)(4523.1413 - 12413.1414i)), (FPT)(4523.1413));
EXPECT_FP_EQ(func((CFPT)(-4523.1413 - 12413.1414i)), (FPT)(-4523.1413));

EXPECT_FP_EQ(func((CFPT)(3210.5678 + 9876.5432i)), (FPT)(3210.5678));
EXPECT_FP_EQ(func((CFPT)(-3210.5678 + 9876.5432i)), (FPT)(-3210.5678));
EXPECT_FP_EQ(func((CFPT)(3210.5678 - 9876.5432i)), (FPT)(3210.5678));
EXPECT_FP_EQ(func((CFPT)(-3210.5678 - 9876.5432i)), (FPT)(-3210.5678));

EXPECT_FP_EQ(func((CFPT)(1234.4321 + 4321.1234i)), (FPT)(1234.4321));
EXPECT_FP_EQ(func((CFPT)(-1234.4321 + 4321.1234i)), (FPT)(-1234.4321));
EXPECT_FP_EQ(func((CFPT)(1234.4321 - 4321.1234i)), (FPT)(1234.4321));
EXPECT_FP_EQ(func((CFPT)(-1234.4321 - 4321.1234i)), (FPT)(-1234.4321));

EXPECT_FP_EQ(func((CFPT)(6789.1234 + 8765.6789i)), (FPT)(6789.1234));
EXPECT_FP_EQ(func((CFPT)(-6789.1234 + 8765.6789i)), (FPT)(-6789.1234));
EXPECT_FP_EQ(func((CFPT)(6789.1234 - 8765.6789i)), (FPT)(6789.1234));
EXPECT_FP_EQ(func((CFPT)(-6789.1234 - 8765.6789i)), (FPT)(-6789.1234));
}
};

#define LIST_CREAL_TESTS(U, T, func) \
using LlvmLibcCRealTest = CRealTest<U, T>; \
TEST_F(LlvmLibcCRealTest, SpecialNumbers) { testSpecialNumbers(&func); } \
TEST_F(LlvmLibcCRealTest, RoundedNumbers) { testRoundedNumbers(&func); }

#endif // LLVM_LIBC_TEST_SRC_COMPLEX_CREALTEST_H
13 changes: 13 additions & 0 deletions libc/test/src/complex/cimag_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for cimag -----------------------------------------------===//
//
// 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 "CImagTest.h"

#include "src/complex/cimag.h"

LIST_CIMAG_TESTS(_Complex double, double, LIBC_NAMESPACE::cimag)
17 changes: 17 additions & 0 deletions libc/test/src/complex/cimagf128_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===-- Unittests for cimagf128 -------------------------------------------===//
//
// 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 "CImagTest.h"

#include "src/complex/cimagf128.h"

#if defined(LIBC_TYPES_HAS_CFLOAT128)

LIST_CIMAG_TESTS(cfloat128, float128, LIBC_NAMESPACE::cimagf128)

#endif // LIBC_TYPES_HAS_CFLOAT128
17 changes: 17 additions & 0 deletions libc/test/src/complex/cimagf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===-- Unittests for cimagf16 --------------------------------------------===//
//
// 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 "CImagTest.h"

#include "src/complex/cimagf16.h"

#if defined(LIBC_TYPES_HAS_CFLOAT16)

LIST_CIMAG_TESTS(cfloat16, float16, LIBC_NAMESPACE::cimagf16)

#endif // LIBC_TYPES_HAS_CFLOAT16
13 changes: 13 additions & 0 deletions libc/test/src/complex/cimagf_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for cimagf ----------------------------------------------===//
//
// 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 "CImagTest.h"

#include "src/complex/cimagf.h"

LIST_CIMAG_TESTS(_Complex float, float, LIBC_NAMESPACE::cimagf)
13 changes: 13 additions & 0 deletions libc/test/src/complex/cimagl_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for cimagl ----------------------------------------------===//
//
// 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 "CImagTest.h"

#include "src/complex/cimagl.h"

LIST_CIMAG_TESTS(_Complex long double, long double, LIBC_NAMESPACE::cimagl)
13 changes: 13 additions & 0 deletions libc/test/src/complex/creal_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for creal -----------------------------------------------===//
//
// 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 "CRealTest.h"

#include "src/complex/creal.h"

LIST_CREAL_TESTS(_Complex double, double, LIBC_NAMESPACE::creal)
17 changes: 17 additions & 0 deletions libc/test/src/complex/crealf128_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===-- Unittests for crealf128 -------------------------------------------===//
//
// 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 "CRealTest.h"

#include "src/complex/crealf128.h"

#if defined(LIBC_TYPES_HAS_CFLOAT128)

LIST_CREAL_TESTS(cfloat128, float128, LIBC_NAMESPACE::crealf128)

#endif // LIBC_TYPES_HAS_CFLOAT128
17 changes: 17 additions & 0 deletions libc/test/src/complex/crealf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===-- Unittests for crealf16 --------------------------------------------===//
//
// 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 "CRealTest.h"

#include "src/complex/crealf16.h"

#if defined(LIBC_TYPES_HAS_CFLOAT16)

LIST_CREAL_TESTS(cfloat16, float16, LIBC_NAMESPACE::crealf16)

#endif // LIBC_TYPES_HAS_CFLOAT16
13 changes: 13 additions & 0 deletions libc/test/src/complex/crealf_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for crealf ----------------------------------------------===//
//
// 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 "CRealTest.h"

#include "src/complex/crealf.h"

LIST_CREAL_TESTS(_Complex float, float, LIBC_NAMESPACE::crealf)
13 changes: 13 additions & 0 deletions libc/test/src/complex/creall_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for creall ----------------------------------------------===//
//
// 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 "CRealTest.h"

#include "src/complex/creall.h"

LIST_CREAL_TESTS(_Complex long double, long double, LIBC_NAMESPACE::creall)
2 changes: 1 addition & 1 deletion libc/test/src/stdio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ add_libc_test(
fopencookie_test.cpp
DEPENDS
libc.include.stdio
libc.include.stdlib
libc.hdr.types.size_t
libc.src.errno.errno
libc.src.stdio.clearerr
libc.src.stdio.fclose
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/stdio/fopencookie_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "test/UnitTest/Test.h"

#include "hdr/stdio_macros.h"
#include "hdr/types/size_t.h"
#include "src/errno/libc_errno.h"
#include <stdlib.h>

using MemoryView = LIBC_NAMESPACE::testing::MemoryView;

Expand Down
16 changes: 7 additions & 9 deletions libc/test/src/stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ add_libc_test(
HDRS
DivTest.h
DEPENDS
libc.include.stdlib
libc.hdr.types.div_t
libc.src.stdlib.div
)

Expand All @@ -272,7 +272,7 @@ add_libc_test(
HDRS
DivTest.h
DEPENDS
libc.include.stdlib
libc.hdr.types.ldiv_t
libc.src.stdlib.ldiv
)

Expand All @@ -285,7 +285,7 @@ add_libc_test(
HDRS
DivTest.h
DEPENDS
libc.include.stdlib
libc.hdr.types.lldiv_t
libc.src.stdlib.lldiv
)

Expand All @@ -296,7 +296,7 @@ add_libc_test(
SRCS
bsearch_test.cpp
DEPENDS
libc.include.stdlib
libc.hdr.types.size_t
libc.src.stdlib.bsearch
)

Expand Down Expand Up @@ -343,7 +343,7 @@ add_libc_test(
SRCS
qsort_r_test.cpp
DEPENDS
libc.include.stdlib
libc.hdr.types.size_t
libc.src.stdlib.qsort_r
)

Expand All @@ -354,7 +354,6 @@ add_libc_test(
SRCS
rand_test.cpp
DEPENDS
libc.include.stdlib
libc.src.stdlib.rand
libc.src.stdlib.srand
)
Expand All @@ -370,7 +369,6 @@ if(LLVM_LIBC_FULL_BUILD)
SRCS
_Exit_test.cpp
DEPENDS
libc.include.stdlib
libc.src.stdlib._Exit
libc.src.stdlib.exit
)
Expand All @@ -384,7 +382,7 @@ if(LLVM_LIBC_FULL_BUILD)
SRCS
atexit_test.cpp
DEPENDS
libc.include.stdlib
libc.hdr.func._Exit
libc.src.stdlib._Exit
libc.src.stdlib.exit
libc.src.stdlib.atexit
Expand All @@ -400,6 +398,7 @@ if(LLVM_LIBC_FULL_BUILD)
SRCS
at_quick_exit_test.cpp
DEPENDS
libc.hdr.func._Exit
libc.src.stdlib.quick_exit
libc.src.stdlib.at_quick_exit
libc.src.__support.CPP.array
Expand All @@ -414,7 +413,6 @@ if(LLVM_LIBC_FULL_BUILD)
SRCS
abort_test.cpp
DEPENDS
libc.include.stdlib
libc.include.signal
libc.src.stdlib.abort
libc.src.stdlib._Exit
Expand Down
2 changes: 0 additions & 2 deletions libc/test/src/stdlib/_Exit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include "src/stdlib/exit.h"
#include "test/UnitTest/Test.h"

#include <stdlib.h>

TEST(LlvmLibcStdlib, _Exit) {
EXPECT_EXITS([] { LIBC_NAMESPACE::_Exit(1); }, 1);
EXPECT_EXITS([] { LIBC_NAMESPACE::_Exit(65); }, 65);
Expand Down
1 change: 0 additions & 1 deletion libc/test/src/stdlib/abort_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "test/UnitTest/Test.h"

#include <signal.h>
#include <stdlib.h>

TEST(LlvmLibcStdlib, abort) {
// -1 matches against any signal, which is necessary for now until
Expand Down
1 change: 1 addition & 0 deletions libc/test/src/stdlib/at_quick_exit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "hdr/func/_Exit.h"
#include "src/__support/CPP/array.h"
#include "src/__support/CPP/utility.h"
#include "src/stdlib/at_quick_exit.h"
Expand Down
1 change: 1 addition & 0 deletions libc/test/src/stdlib/atexit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "hdr/func/_Exit.h"
#include "src/__support/CPP/array.h"
#include "src/__support/CPP/utility.h"
#include "src/stdlib/atexit.h"
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/stdlib/bsearch_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "test/UnitTest/Test.h"

#include <stdlib.h>
#include "hdr/types/size_t.h"

static int int_compare(const void *l, const void *r) {
int li = *reinterpret_cast<const int *>(l);
Expand Down
3 changes: 1 addition & 2 deletions libc/test/src/stdlib/div_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

#include "DivTest.h"

#include "hdr/types/div_t.h"
#include "src/stdlib/div.h"

#include <stdlib.h>

LIST_DIV_TESTS(int, div_t, LIBC_NAMESPACE::div)
3 changes: 1 addition & 2 deletions libc/test/src/stdlib/ldiv_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

#include "DivTest.h"

#include "hdr/types/ldiv_t.h"
#include "src/stdlib/ldiv.h"

#include <stdlib.h>

LIST_DIV_TESTS(long, ldiv_t, LIBC_NAMESPACE::ldiv)
3 changes: 1 addition & 2 deletions libc/test/src/stdlib/lldiv_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

#include "DivTest.h"

#include "hdr/types/lldiv_t.h"
#include "src/stdlib/lldiv.h"

#include <stdlib.h>

LIST_DIV_TESTS(long long, lldiv_t, LIBC_NAMESPACE::lldiv)
2 changes: 1 addition & 1 deletion libc/test/src/stdlib/qsort_r_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "test/UnitTest/Test.h"

#include <stdlib.h>
#include "hdr/types/size_t.h"

static int int_compare_count(const void *l, const void *r, void *count_arg) {
int li = *reinterpret_cast<const int *>(l);
Expand Down
1 change: 0 additions & 1 deletion libc/test/src/stdlib/rand_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "test/UnitTest/Test.h"

#include <stddef.h>
#include <stdlib.h>

TEST(LlvmLibcRandTest, UnsetSeed) {
static int vals[1000];
Expand Down
2 changes: 0 additions & 2 deletions libc/test/src/string/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ add_libc_test(
SRCS
strdup_test.cpp
DEPENDS
libc.include.stdlib
libc.src.string.strdup
libc.src.errno.errno
)
Expand Down Expand Up @@ -315,7 +314,6 @@ add_libc_test(
SRCS
strndup_test.cpp
DEPENDS
libc.include.stdlib
libc.src.string.strndup
)

Expand Down
2 changes: 0 additions & 2 deletions libc/test/src/string/strdup_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include "src/string/strdup.h"
#include "test/UnitTest/Test.h"

#include <stdlib.h>

TEST(LlvmLibcStrDupTest, EmptyString) {
const char *empty = "";

Expand Down
1 change: 0 additions & 1 deletion libc/test/src/string/strlcat_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "src/string/strlcat.h"
#include "test/UnitTest/Test.h"
#include <stdlib.h>

TEST(LlvmLibcStrlcatTest, TooBig) {
const char *str = "cd";
Expand Down
1 change: 0 additions & 1 deletion libc/test/src/string/strlcpy_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "src/string/strlcpy.h"
#include "test/UnitTest/Test.h"
#include <stdlib.h>

TEST(LlvmLibcStrlcpyTest, TooBig) {
const char *str = "abc";
Expand Down
1 change: 0 additions & 1 deletion libc/test/src/string/strndup_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "src/string/strndup.h"
#include "test/UnitTest/Test.h"
#include <stdlib.h>

TEST(LlvmLibcstrndupTest, EmptyString) {
const char *empty = "";
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__memory/shared_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ struct __unbounded_array_control_block<_Tp[], _Alloc> : __shared_weak_count {
template <class _Array, class _Alloc, class... _Arg>
_LIBCPP_HIDE_FROM_ABI shared_ptr<_Array>
__allocate_shared_unbounded_array(const _Alloc& __a, size_t __n, _Arg&&... __arg) {
static_assert(__libcpp_is_unbounded_array<_Array>::value);
static_assert(__is_unbounded_array_v<_Array>);
// We compute the number of bytes necessary to hold the control block and the
// array elements. Then, we allocate an array of properly-aligned dummy structs
// large enough to hold the control block and array. This allows shifting the
Expand Down Expand Up @@ -1034,7 +1034,7 @@ struct __bounded_array_control_block<_Tp[_Count], _Alloc> : __shared_weak_count

template <class _Array, class _Alloc, class... _Arg>
_LIBCPP_HIDE_FROM_ABI shared_ptr<_Array> __allocate_shared_bounded_array(const _Alloc& __a, _Arg&&... __arg) {
static_assert(__libcpp_is_bounded_array<_Array>::value);
static_assert(__is_bounded_array_v<_Array>);
using _ControlBlock = __bounded_array_control_block<_Array, _Alloc>;
using _ControlBlockAlloc = __allocator_traits_rebind_t<_Alloc, _ControlBlock>;

Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__memory/uninitialized_algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ __allocator_destroy_multidimensional(_Alloc& __alloc, _BidirIter __first, _Bidir
return;

if constexpr (is_array_v<_ValueType>) {
static_assert(!__libcpp_is_unbounded_array<_ValueType>::value,
static_assert(!__is_unbounded_array_v<_ValueType>,
"arrays of unbounded arrays don't exist, but if they did we would mess up here");

using _Element = remove_extent_t<_ValueType>;
Expand Down
Loading