Skip to content

Commit 9eacdf5

Browse files
authored
Merge branch 'main' into issue_165161
2 parents 3ce9b61 + 6a10d1d commit 9eacdf5

File tree

25 files changed

+576
-246
lines changed

25 files changed

+576
-246
lines changed

clang/docs/Modules.rst

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,7 @@ As an example, the module map file for the C standard library might look a bit l
421421

422422
.. parsed-literal::
423423
424-
module std [system] [extern_c] {
425-
module assert {
426-
textual header "assert.h"
427-
header "bits/assert-decls.h"
428-
export *
429-
}
430-
424+
module std [system] {
431425
module complex {
432426
header "complex.h"
433427
export *
@@ -440,7 +434,6 @@ As an example, the module map file for the C standard library might look a bit l
440434
441435
module errno {
442436
header "errno.h"
443-
header "sys/errno.h"
444437
export *
445438
}
446439
@@ -673,14 +666,14 @@ of checking *use-declaration*\s, and must still be a lexically-valid header
673666
file. In the future, we intend to pre-tokenize such headers and include the
674667
token sequence within the prebuilt module representation.
675668

676-
A header with the ``exclude`` specifier is excluded from the module. It will not be included when the module is built, nor will it be considered to be part of the module, even if an ``umbrella`` header or directory would otherwise make it part of the module.
669+
A header with the ``exclude`` specifier is excluded from the module. It will not be included when the module is built, nor will it be considered to be part of the module, even if an ``umbrella`` directory would otherwise make it part of the module.
677670

678-
**Example:** The C header ``assert.h`` is an excellent candidate for a textual header, because it is meant to be included multiple times (possibly with different ``NDEBUG`` settings). However, declarations within it should typically be split into a separate modular header.
671+
**Example:** A "X macro" header is an excellent candidate for a textual header, because it is can't be compiled standalone, and by itself does not contain any declarations.
679672

680673
.. parsed-literal::
681674
682-
module std [system] {
683-
textual header "assert.h"
675+
module MyLib [system] {
676+
textual header "xmacros.h"
684677
}
685678
686679
A given header shall not be referenced by more than one *header-declaration*.

libc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ elseif(LLVM_LIBC_FULL_BUILD)
363363
message(FATAL_ERROR "${LIBC_CONFIG_PATH}/headers.txt file not found and fullbuild requested.")
364364
endif()
365365

366-
# Check exclude.txt that appends to LIBC_EXCLUDE_ENTRYPOINTS list
366+
# Check exclude.txt that appends to TARGET_LLVMLIBC_REMOVED_ENTRYPOINTS list
367367
if(EXISTS "${LIBC_CONFIG_PATH}/exclude.txt")
368368
include("${LIBC_CONFIG_PATH}/exclude.txt")
369369
endif()

libc/config/linux/x86_64/exclude.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ if(NOT has_sys_random)
1919
)
2020
endif()
2121
endif()
22+
23+
include(CheckSymbolExists)
24+
check_symbol_exists(SYS_faccessat2 "sys/syscall.h" HAVE_SYS_FACCESSAT2)
25+
if(NOT HAVE_SYS_FACCESSAT2)
26+
list(APPEND TARGET_LLVMLIBC_REMOVED_ENTRYPOINTS
27+
libc.src.unistd.faccessat
28+
)
29+
endif()

libc/src/time/strftime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ LLVM_LIBC_FUNCTION(size_t, strftime,
2626
int ret = strftime_core::strftime_main(&writer, format, timeptr);
2727
if (buffsz > 0) // if the buffsz is 0 the buffer may be a null pointer.
2828
wb.buff[wb.buff_cur] = '\0';
29-
return (ret < 0 || static_cast<size_t>(ret) > buffsz) ? 0 : ret;
29+
return (ret < 0 || static_cast<size_t>(ret) >= buffsz) ? 0 : ret;
3030
}
3131

3232
} // namespace LIBC_NAMESPACE_DECL

libc/src/time/strftime_l.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ LLVM_LIBC_FUNCTION(size_t, strftime_l,
2929
int ret = strftime_core::strftime_main(&writer, format, timeptr);
3030
if (buffsz > 0) // if the buffsz is 0 the buffer may be a null pointer.
3131
wb.buff[wb.buff_cur] = '\0';
32-
return (ret < 0 || static_cast<size_t>(ret) > buffsz) ? 0 : ret;
32+
return (ret < 0 || static_cast<size_t>(ret) >= buffsz) ? 0 : ret;
3333
}
3434

3535
} // namespace LIBC_NAMESPACE_DECL

libc/test/src/time/strftime_test.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,3 +2326,23 @@ TEST(LlvmLibcStrftimeTest, TimeFormatFullDateTime) {
23262326
// size_t written = 0;
23272327
// SimplePaddedNum spn;
23282328
// }
2329+
2330+
TEST(LlvmLibcStrftimeTest, BufferTooSmall) {
2331+
struct tm time;
2332+
char buffer[1];
2333+
2334+
time.tm_year = get_adjusted_year(2025);
2335+
time.tm_mon = 10;
2336+
time.tm_mday = 24;
2337+
2338+
size_t written =
2339+
LIBC_NAMESPACE::strftime(buffer, sizeof(buffer), "%F", &time);
2340+
EXPECT_EQ(written, size_t{0});
2341+
2342+
char buffer2[10];
2343+
2344+
// The string "2025-11-24" is 10 chars,
2345+
// so strftime needs 10 + 1 bytes to write the string and the null terminator.
2346+
written = LIBC_NAMESPACE::strftime(buffer, sizeof(buffer2), "%F", &time);
2347+
EXPECT_EQ(written, size_t{0});
2348+
}

0 commit comments

Comments
 (0)