Skip to content

Commit 345ce9d

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:7fcbb64fca5e into amd-gfx:b56d6b265611
Local branch amd-gfx b56d6b2 Merged main:eb31208be153 into amd-gfx:62f2f3a34f76 Remote branch main 7fcbb64 [runtimes] Workaround a subtle linker issue on macOS in the CI
2 parents b56d6b2 + 7fcbb64 commit 345ce9d

File tree

23 files changed

+592
-332
lines changed

23 files changed

+592
-332
lines changed

clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,41 @@ using namespace clang::ast_matchers;
1414

1515
namespace clang::tidy::llvm_libc {
1616

17-
const static StringRef RequiredNamespace = "__llvm_libc";
17+
const static StringRef RequiredNamespaceStart = "__llvm_libc";
18+
const static StringRef RequiredNamespaceMacroName = "LIBC_NAMESPACE";
19+
1820
void ImplementationInNamespaceCheck::registerMatchers(MatchFinder *Finder) {
1921
Finder->addMatcher(
20-
decl(hasParent(translationUnitDecl()), unless(linkageSpecDecl()))
21-
.bind("child_of_translation_unit"),
22+
translationUnitDecl(
23+
forEach(decl(isExpansionInMainFile(), unless(linkageSpecDecl()),
24+
// anonymous namespaces generate usingDirective
25+
unless(usingDirectiveDecl(isImplicit())))
26+
.bind("child_of_translation_unit"))),
2227
this);
2328
}
2429

2530
void ImplementationInNamespaceCheck::check(
2631
const MatchFinder::MatchResult &Result) {
2732
const auto *MatchedDecl =
2833
Result.Nodes.getNodeAs<Decl>("child_of_translation_unit");
29-
if (!Result.SourceManager->isInMainFile(MatchedDecl->getLocation()))
34+
MatchedDecl->dump();
35+
const auto *NS = dyn_cast<NamespaceDecl>(MatchedDecl);
36+
if (NS == nullptr || NS->isAnonymousNamespace()) {
37+
diag(MatchedDecl->getLocation(),
38+
"declaration must be enclosed within the '%0' namespace")
39+
<< RequiredNamespaceMacroName;
3040
return;
31-
32-
if (const auto *NS = dyn_cast<NamespaceDecl>(MatchedDecl)) {
33-
if (NS->getName() != RequiredNamespace) {
34-
diag(NS->getLocation(), "'%0' needs to be the outermost namespace")
35-
<< RequiredNamespace;
36-
}
41+
}
42+
if (Result.SourceManager->isMacroBodyExpansion(NS->getLocation()) == false) {
43+
diag(NS->getLocation(), "the outermost namespace should be the '%0' macro")
44+
<< RequiredNamespaceMacroName;
45+
return;
46+
}
47+
if (NS->getName().starts_with(RequiredNamespaceStart) == false) {
48+
diag(NS->getLocation(), "the '%0' macro should start with '%1'")
49+
<< RequiredNamespaceMacroName << RequiredNamespaceStart;
3750
return;
3851
}
39-
diag(MatchedDecl->getLocation(),
40-
"declaration must be declared within the '%0' namespace")
41-
<< RequiredNamespace;
4252
}
4353

4454
} // namespace clang::tidy::llvm_libc

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ Changes in existing checks
241241
<clang-tidy/checks/llvm/namespace-comment>` check to provide fixes for
242242
``inline`` namespaces in the same format as :program:`clang-format`.
243243

244+
- Improved :doc:`llvmlibc-implementation-in-namespace
245+
<clang-tidy/checks/llvmlibc/implementation-in-namespace>` to support
246+
customizable namespace. This further allows for testing the libc when the
247+
system-libc is also LLVM's libc.
248+
244249
- Improved :doc:`misc-include-cleaner
245250
<clang-tidy/checks/misc/include-cleaner>` check by adding option
246251
`DeduplicateFindings` to output one finding per symbol occurrence.

clang-tools-extra/docs/clang-tidy/checks/llvmlibc/implementation-in-namespace.rst

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,30 @@ correct namespace.
88

99
.. code-block:: c++
1010

11-
// Correct: implementation inside the correct namespace.
12-
namespace __llvm_libc {
11+
// Implementation inside the LIBC_NAMESPACE namespace.
12+
// Correct if:
13+
// - LIBC_NAMESPACE is a macro
14+
// - LIBC_NAMESPACE expansion starts with `__llvm_libc`
15+
namespace LIBC_NAMESPACE {
1316
void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
14-
// Namespaces within __llvm_libc namespace are allowed.
15-
namespace inner{
17+
// Namespaces within LIBC_NAMESPACE namespace are allowed.
18+
namespace inner {
1619
int localVar = 0;
1720
}
1821
// Functions with C linkage are allowed.
19-
extern "C" void str_fuzz(){}
22+
extern "C" void str_fuzz() {}
2023
}
2124
22-
// Incorrect: implementation not in a namespace.
25+
// Incorrect: implementation not in the LIBC_NAMESPACE namespace.
2326
void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
2427
25-
// Incorrect: outer most namespace is not correct.
28+
// Incorrect: outer most namespace is not the LIBC_NAMESPACE macro.
2629
namespace something_else {
2730
void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
2831
}
32+
33+
// Incorrect: outer most namespace expansion does not start with `__llvm_libc`.
34+
#define LIBC_NAMESPACE custom_namespace
35+
namespace LIBC_NAMESPACE {
36+
void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
37+
}

clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,30 @@
33
#define MACRO_A "defining macros outside namespace is valid"
44

55
class ClassB;
6-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be declared within the '__llvm_libc' namespace
6+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace
77
struct StructC {};
8-
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: declaration must be declared within the '__llvm_libc' namespace
8+
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace
99
char *VarD = MACRO_A;
10-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be declared within the '__llvm_libc' namespace
10+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace
1111
typedef int typeE;
12-
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: declaration must be declared within the '__llvm_libc' namespace
12+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace
1313
void funcF() {}
14-
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration must be declared within the '__llvm_libc' namespace
14+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace
15+
16+
namespace outer_most {
17+
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the outermost namespace should be the 'LIBC_NAMESPACE' macro
18+
class A {};
19+
}
20+
21+
// Wrapped in anonymous namespace.
22+
namespace {
23+
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace
24+
class A {};
25+
}
1526

1627
namespace namespaceG {
17-
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: '__llvm_libc' needs to be the outermost namespace
18-
namespace __llvm_libc{
28+
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the outermost namespace should be the 'LIBC_NAMESPACE' macro
29+
namespace __llvm_libc {
1930
namespace namespaceH {
2031
class ClassB;
2132
} // namespace namespaceH
@@ -26,9 +37,20 @@ typedef int typeE;
2637
void funcF() {}
2738
} // namespace namespaceG
2839

29-
// Wrapped in correct namespace.
30-
namespace __llvm_libc {
31-
// Namespaces within __llvim_libc namespace allowed.
40+
// Wrapped in macro namespace but with an incorrect name
41+
#define LIBC_NAMESPACE custom_namespace
42+
namespace LIBC_NAMESPACE {
43+
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the 'LIBC_NAMESPACE' macro should start with '__llvm_libc'
44+
namespace namespaceH {
45+
class ClassB;
46+
} // namespace namespaceH
47+
} // namespace LIBC_NAMESPACE
48+
49+
50+
// Wrapped in macro namespace with a valid name, LIBC_NAMESPACE starts with '__llvm_libc'
51+
#undef LIBC_NAMESPACE
52+
#define LIBC_NAMESPACE __llvm_libc_xyz
53+
namespace LIBC_NAMESPACE {
3254
namespace namespaceI {
3355
class ClassB;
3456
} // namespace namespaceI
@@ -37,4 +59,4 @@ char *VarD = MACRO_A;
3759
typedef int typeE;
3860
void funcF() {}
3961
extern "C" void extern_funcJ() {}
40-
} // namespace __llvm_libc
62+
} // namespace LIBC_NAMESPACE

libc/include/llvm-libc-types/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ add_header(struct_rusage HDR struct_rusage.h DEPENDS .struct_timeval)
6363
add_header(struct_dirent HDR struct_dirent.h DEPENDS .ino_t .off_t)
6464
add_header(struct_sched_param HDR struct_sched_param.h)
6565
add_header(union_sigval HDR union_sigval.h)
66-
add_header(siginfo_t HDR siginfo_t.h DEPENDS .union_sigval .pid_t .uid_t)
66+
add_header(siginfo_t HDR siginfo_t.h DEPENDS .union_sigval .pid_t .uid_t .clock_t)
6767
add_header(sig_atomic_t HDR sig_atomic_t.h)
6868
add_header(sigset_t HDR sigset_t.h DEPENDS libc.include.llvm-libc-macros.signal_macros)
6969
add_header(struct_sigaction HDR struct_sigaction.h DEPENDS .sigset_t .siginfo_t)

libc/include/llvm-libc-types/siginfo_t.h

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,101 @@
99
#ifndef __LLVM_LIBC_TYPES_SIGINFO_T_H__
1010
#define __LLVM_LIBC_TYPES_SIGINFO_T_H__
1111

12+
#include <llvm-libc-types/clock_t.h>
1213
#include <llvm-libc-types/pid_t.h>
1314
#include <llvm-libc-types/uid_t.h>
1415
#include <llvm-libc-types/union_sigval.h>
1516

17+
#define SI_MAX_SIZE 128
18+
1619
typedef struct {
17-
int si_signo;
18-
int si_code;
19-
int si_errno;
20-
pid_t si_pid;
21-
uid_t si_uid;
22-
void *si_addr;
23-
int si_status;
24-
long si_band;
25-
union sigval si_value;
20+
int si_signo; /* Signal number. */
21+
int si_errno; /* If non-zero, an errno value associated with
22+
this signal, as defined in <errno.h>. */
23+
int si_code; /* Signal code. */
24+
union {
25+
int _si_pad[SI_MAX_SIZE / sizeof(int)];
26+
27+
/* kill() */
28+
struct {
29+
pid_t si_pid; /* sender's pid */
30+
uid_t si_uid; /* sender's uid */
31+
} _kill;
32+
33+
/* POSIX.1b timers */
34+
struct {
35+
int si_tid; /* timer id */
36+
int _overrun; /* overrun count */
37+
union sigval si_sigval; /* same as below */
38+
} _timer;
39+
40+
/* POSIX.1b signals */
41+
struct {
42+
pid_t si_pid; /* sender's pid */
43+
uid_t si_uid; /* sender's uid */
44+
union sigval si_sigval;
45+
} _rt;
46+
47+
/* SIGCHLD */
48+
struct {
49+
pid_t si_pid; /* which child */
50+
uid_t si_uid; /* sender's uid */
51+
int si_status; /* exit code */
52+
clock_t si_utime;
53+
clock_t si_stime;
54+
} _sigchld;
55+
56+
/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */
57+
struct {
58+
void *si_addr; /* faulting insn/memory ref. */
59+
short int si_addr_lsb; /* Valid LSB of the reported address. */
60+
union {
61+
/* used when si_code=SEGV_BNDERR */
62+
struct {
63+
void *_lower;
64+
void *_upper;
65+
} _addr_bnd;
66+
/* used when si_code=SEGV_PKUERR */
67+
__UINT32_TYPE__ _pkey;
68+
} _bounds;
69+
} _sigfault;
70+
71+
/* SIGPOLL */
72+
struct {
73+
long int si_band; /* POLL_IN, POLL_OUT, POLL_MSG */
74+
int si_fd;
75+
} _sigpoll;
76+
77+
/* SIGSYS */
78+
struct {
79+
void *_call_addr; /* calling user insn */
80+
int _syscall; /* triggering system call number */
81+
unsigned int _arch; /* AUDIT_ARCH_* of syscall */
82+
} _sigsys;
83+
} _sifields;
2684
} siginfo_t;
2785

86+
#undef SI_MAX_SIZE
87+
88+
#define si_pid _sifields._kill.si_pid
89+
#define si_uid _sifields._kill.si_uid
90+
#define si_timerid _sifields._timer.si_tid
91+
#define si_overrun _sifields._timer.si_overrun
92+
#define si_status _sifields._sigchld.si_status
93+
#define si_utime _sifields._sigchld.si_utime
94+
#define si_stime _sifields._sigchld.si_stime
95+
#define si_value _sifields._rt.si_sigval
96+
#define si_int _sifields._rt.si_sigval.sival_int
97+
#define si_ptr _sifields._rt.si_sigval.sival_ptr
98+
#define si_addr _sifields._sigfault.si_addr
99+
#define si_addr_lsb _sifields._sigfault.si_addr_lsb
100+
#define si_lower _sifields._sigfault._bounds._addr_bnd._lower
101+
#define si_upper _sifields._sigfault._bounds._addr_bnd._upper
102+
#define si_pkey _sifields._sigfault._bounds._pkey
103+
#define si_band _sifields._sigpoll.si_band
104+
#define si_fd _sifields._sigpoll.si_fd
105+
#define si_call_addr _sifields._sigsys._call_addr
106+
#define si_syscall _sifields._sigsys._syscall
107+
#define si_arch _sifields._sigsys._arch
108+
28109
#endif // __LLVM_LIBC_TYPES_SIGINFO_T_H__

libcxx/benchmarks/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ add_library( cxx-benchmarks-flags INTERFACE)
8383
# version that MSVC flags support is C++20.
8484
if (MSVC)
8585
add_compile_options(/std:c++latest)
86+
# ibm-clang does not recognize the cxx_std_32 flag, so use this as a temporary
87+
# workaround on AIX as well.
88+
elseif (${CMAKE_SYSTEM_NAME} MATCHES "AIX")
89+
add_compile_options(-std=c++23)
8690
else()
8791
target_compile_features( cxx-benchmarks-flags INTERFACE cxx_std_23)
8892
endif()

libcxx/utils/ci/run-buildbot

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,6 @@ function generate-cmake-libcxx-win() {
162162
}
163163

164164
function check-runtimes() {
165-
echo "--- Installing libc++, libc++abi and libunwind to a fake location"
166-
${NINJA} -vC "${BUILD_DIR}" install-cxx install-cxxabi install-unwind
167-
168165
echo "+++ Running the libc++ tests"
169166
${NINJA} -vC "${BUILD_DIR}" check-cxx
170167

@@ -173,6 +170,19 @@ function check-runtimes() {
173170

174171
echo "+++ Running the libunwind tests"
175172
${NINJA} -vC "${BUILD_DIR}" check-unwind
173+
174+
# TODO: On macOS 13.5, the linker seems to have an issue where it will pick up
175+
# a library if it exists inside a -L search path, even if we don't link
176+
# against that library. This happens with libunwind.dylib if it is built
177+
# at the point when we run the libc++ tests, which causes issues cause we
178+
# are also linking against the system unwinder.
179+
#
180+
# I believe this is a linker regression and I reported it as rdar://115842730.
181+
# It should be possible to move this installation step back to the top once
182+
# that issue has been resolved, but in the meantime it doesn't really hurt to
183+
# have it here.
184+
echo "--- Installing libc++, libc++abi and libunwind to a fake location"
185+
${NINJA} -vC "${BUILD_DIR}" install-cxx install-cxxabi install-unwind
176186
}
177187

178188
# TODO: The goal is to test this against all configurations. We should also move

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 475490
19+
#define LLVM_MAIN_REVISION 475502
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ class SCEVExpander : public SCEVVisitor<SCEVExpander, Value *> {
483483
PHINode *getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
484484
const Loop *L, Type *ExpandTy, Type *IntTy,
485485
Type *&TruncTy, bool &InvertStep);
486-
Value *expandIVInc(PHINode *PN, Value *StepV, const Loop *L, Type *ExpandTy,
486+
Value *expandIVInc(PHINode *PN, Value *StepV, const Loop *L,
487487
bool useSubtract);
488488

489489
void fixupInsertPoints(Instruction *I);

0 commit comments

Comments
 (0)