Skip to content

Commit 3bdef6a

Browse files
authored
Merge branch 'main' into fix-source-location-current
2 parents e253d07 + 646d185 commit 3bdef6a

File tree

51 files changed

+5655
-1184
lines changed

Some content is hidden

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

51 files changed

+5655
-1184
lines changed

.github/workflows/libcxx-restart-preempted-jobs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ jobs:
145145
with:
146146
script: |
147147
const FAILURE_REGEX = /Process completed with exit code 1./
148-
const PREEMPTION_REGEX = /The runner has received a shutdown signal|The operation was canceled/
148+
const PREEMPTION_REGEX = /(The runner has received a shutdown signal)|(The operation was canceled)/
149149
150150
function log(msg) {
151151
core.notice(msg)

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,19 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
197197
const Pointer &A = getParam<Pointer>(Frame, 0);
198198
const Pointer &B = getParam<Pointer>(Frame, 1);
199199

200-
if (ID == Builtin::BIstrcmp)
200+
if (ID == Builtin::BIstrcmp || ID == Builtin::BIstrncmp)
201201
diagnoseNonConstexprBuiltin(S, OpPC, ID);
202202

203+
uint64_t Limit = ~static_cast<uint64_t>(0);
204+
if (ID == Builtin::BIstrncmp || ID == Builtin::BI__builtin_strncmp)
205+
Limit = peekToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(2)))
206+
.getZExtValue();
207+
208+
if (Limit == 0) {
209+
pushInteger(S, 0, Call->getType());
210+
return true;
211+
}
212+
203213
if (!CheckLive(S, OpPC, A, AK_Read) || !CheckLive(S, OpPC, B, AK_Read))
204214
return false;
205215

@@ -212,7 +222,11 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
212222
unsigned IndexA = A.getIndex();
213223
unsigned IndexB = B.getIndex();
214224
int32_t Result = 0;
215-
for (;; ++IndexA, ++IndexB) {
225+
uint64_t Steps = 0;
226+
for (;; ++IndexA, ++IndexB, ++Steps) {
227+
228+
if (Steps >= Limit)
229+
break;
216230
const Pointer &PA = A.atIndex(IndexA);
217231
const Pointer &PB = B.atIndex(IndexB);
218232
if (!CheckRange(S, OpPC, PA, AK_Read) ||
@@ -259,7 +273,7 @@ static bool interp__builtin_strlen(InterpState &S, CodePtr OpPC,
259273
unsigned ElemSize = StrPtr.getFieldDesc()->getElemSize();
260274

261275
if (ID == Builtin::BI__builtin_wcslen || ID == Builtin::BIwcslen) {
262-
const ASTContext &AC = S.getASTContext();
276+
[[maybe_unused]] const ASTContext &AC = S.getASTContext();
263277
assert(ElemSize == AC.getTypeSizeInChars(AC.getWCharType()).getQuantity());
264278
}
265279

@@ -1873,6 +1887,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
18731887
break;
18741888
case Builtin::BI__builtin_strcmp:
18751889
case Builtin::BIstrcmp:
1890+
case Builtin::BI__builtin_strncmp:
1891+
case Builtin::BIstrncmp:
18761892
if (!interp__builtin_strcmp(S, OpPC, Frame, F, Call))
18771893
return false;
18781894
break;

clang/test/AST/ByteCode/builtin-functions.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ namespace strcmp {
5151
return __builtin_strcmp(buffer, "mutable") == 0;
5252
}
5353
static_assert(char_memchr_mutable(), "");
54+
55+
static_assert(__builtin_strncmp("abaa", "abba", 5) == -1);
56+
static_assert(__builtin_strncmp("abaa", "abba", 4) == -1);
57+
static_assert(__builtin_strncmp("abaa", "abba", 3) == -1);
58+
static_assert(__builtin_strncmp("abaa", "abba", 2) == 0);
59+
static_assert(__builtin_strncmp("abaa", "abba", 1) == 0);
60+
static_assert(__builtin_strncmp("abaa", "abba", 0) == 0);
61+
static_assert(__builtin_strncmp(0, 0, 0) == 0);
62+
static_assert(__builtin_strncmp("abab\0banana", "abab\0canada", 100) == 0);
5463
}
5564

5665
/// Copied from constant-expression-cxx11.cpp

libc/src/__support/macros/properties/os.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,6 @@
2525
#define LIBC_TARGET_OS_IS_WINDOWS
2626
#endif
2727

28-
#if (defined(__apple__) || defined(__APPLE__) || defined(__MACH__))
29-
// From https://stackoverflow.com/a/49560690
30-
#include "TargetConditionals.h"
31-
#if defined(TARGET_OS_OSX)
32-
#define LIBC_TARGET_OS_IS_MACOS
33-
#endif
34-
#if defined(TARGET_OS_IPHONE)
35-
// This is set for any non-Mac Apple products (IOS, TV, WATCH)
36-
#define LIBC_TARGET_OS_IS_IPHONE
37-
#endif
38-
#endif
39-
4028
#if defined(__Fuchsia__)
4129
#define LIBC_TARGET_OS_IS_FUCHSIA
4230
#endif

libcxx/include/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,13 @@ set(files
212212
__atomic/atomic_sync.h
213213
__atomic/check_memory_order.h
214214
__atomic/contention_t.h
215-
__atomic/cxx_atomic_impl.h
216215
__atomic/fence.h
217216
__atomic/is_always_lock_free.h
218217
__atomic/kill_dependency.h
219218
__atomic/memory_order.h
219+
__atomic/support.h
220+
__atomic/support/c11.h
221+
__atomic/support/gcc.h
220222
__atomic/to_gcc_order.h
221223
__bit/bit_cast.h
222224
__bit/bit_ceil.h
@@ -358,6 +360,7 @@ set(files
358360
__filesystem/space_info.h
359361
__filesystem/u8path.h
360362
__flat_map/flat_map.h
363+
__flat_map/key_value_iterator.h
361364
__flat_map/sorted_unique.h
362365
__format/buffer.h
363366
__format/concepts.h

libcxx/include/__atomic/atomic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
#include <__atomic/atomic_sync.h>
1313
#include <__atomic/check_memory_order.h>
14-
#include <__atomic/cxx_atomic_impl.h>
1514
#include <__atomic/is_always_lock_free.h>
1615
#include <__atomic/memory_order.h>
16+
#include <__atomic/support.h>
1717
#include <__config>
1818
#include <__cstddef/ptrdiff_t.h>
1919
#include <__memory/addressof.h>

libcxx/include/__atomic/atomic_flag.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
#include <__atomic/atomic_sync.h>
1313
#include <__atomic/contention_t.h>
14-
#include <__atomic/cxx_atomic_impl.h>
1514
#include <__atomic/memory_order.h>
15+
#include <__atomic/support.h>
1616
#include <__chrono/duration.h>
1717
#include <__config>
1818
#include <__memory/addressof.h>

libcxx/include/__atomic/atomic_sync.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define _LIBCPP___ATOMIC_ATOMIC_SYNC_H
1111

1212
#include <__atomic/contention_t.h>
13-
#include <__atomic/cxx_atomic_impl.h>
1413
#include <__atomic/memory_order.h>
1514
#include <__atomic/to_gcc_order.h>
1615
#include <__chrono/duration.h>

libcxx/include/__atomic/contention_t.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef _LIBCPP___ATOMIC_CONTENTION_T_H
1010
#define _LIBCPP___ATOMIC_CONTENTION_T_H
1111

12-
#include <__atomic/cxx_atomic_impl.h>
12+
#include <__atomic/support.h>
1313
#include <__config>
1414
#include <cstdint>
1515

libcxx/include/__atomic/fence.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef _LIBCPP___ATOMIC_FENCE_H
1010
#define _LIBCPP___ATOMIC_FENCE_H
1111

12-
#include <__atomic/cxx_atomic_impl.h>
1312
#include <__atomic/memory_order.h>
13+
#include <__atomic/support.h>
1414
#include <__config>
1515

1616
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

0 commit comments

Comments
 (0)