Skip to content

Commit 825e73f

Browse files
authored
Merge branch 'main' into dependent-new-fix
2 parents 2753330 + 3733b0c commit 825e73f

File tree

17 files changed

+462
-399
lines changed

17 files changed

+462
-399
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,12 @@ Bug Fixes to C++ Support
509509
a class template. (#GH102320)
510510
- Fix a crash when parsing a pseudo destructor involving an invalid type. (#GH111460)
511511
- Fixed an assertion failure when invoking recovery call expressions with explicit attributes
512-
and undeclared templates. (#GH107047, #GH49093)
512+
and undeclared templates. (#GH107047), (#GH49093)
513513
- Clang no longer crashes when a lambda contains an invalid block declaration that contains an unexpanded
514514
parameter pack. (#GH109148)
515515
- Fixed overload handling for object parameters with top-level cv-qualifiers in explicit member functions (#GH100394)
516+
- Fixed a bug in lambda captures where ``constexpr`` class-type objects were not properly considered ODR-used in
517+
certain situations. (#GH47400), (#GH90896)
516518
- Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441)
517519

518520
Bug Fixes to AST Handling

clang/lib/Sema/SemaExpr.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18865,7 +18865,17 @@ bool Sema::tryCaptureVariable(
1886518865
// We need to sync up the Declaration Context with the
1886618866
// FunctionScopeIndexToStopAt
1886718867
if (FunctionScopeIndexToStopAt) {
18868+
assert(!FunctionScopes.empty() && "No function scopes to stop at?");
1886818869
unsigned FSIndex = FunctionScopes.size() - 1;
18870+
// When we're parsing the lambda parameter list, the current DeclContext is
18871+
// NOT the lambda but its parent. So move away the current LSI before
18872+
// aligning DC and FunctionScopeIndexToStopAt.
18873+
if (auto *LSI = dyn_cast<LambdaScopeInfo>(FunctionScopes[FSIndex]);
18874+
FSIndex && LSI && !LSI->AfterParameterList)
18875+
--FSIndex;
18876+
assert(MaxFunctionScopesIndex <= FSIndex &&
18877+
"FunctionScopeIndexToStopAt should be no greater than FSIndex into "
18878+
"FunctionScopes.");
1886918879
while (FSIndex != MaxFunctionScopesIndex) {
1887018880
DC = getLambdaAwareParentOfDeclContext(DC);
1887118881
--FSIndex;

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8687,7 +8687,7 @@ static void CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures(
86878687
while (isa_and_nonnull<CapturedDecl>(DC))
86888688
DC = DC->getParent();
86898689
assert(
8690-
CurrentLSI->CallOperator == DC &&
8690+
(CurrentLSI->CallOperator == DC || !CurrentLSI->AfterParameterList) &&
86918691
"The current call operator must be synchronized with Sema's CurContext");
86928692
#endif // NDEBUG
86938693

clang/test/SemaCXX/lambda-capture-type-deduction.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,25 @@ void __trans_tmp_1() {
297297
}
298298

299299
}
300+
301+
namespace GH47400 {
302+
303+
struct Foo {};
304+
305+
template <int, Foo> struct Arr {};
306+
307+
template <int> struct S {};
308+
309+
constexpr void foo() {
310+
constexpr Foo f;
311+
[&]<int is>() {
312+
[&](Arr<is, f>) {}({}); // f constitutes an ODR-use
313+
}.template operator()<42>();
314+
315+
constexpr int C = 1;
316+
[] {
317+
[](S<C>) { }({}); // ... while C doesn't
318+
}();
319+
}
320+
321+
} // namespace GH47400

compiler-rt/lib/hwasan/hwasan_platform_interceptors.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@
200200
#undef SANITIZER_INTERCEPT_CLOCK_GETCPUCLOCKID
201201
#define SANITIZER_INTERCEPT_CLOCK_GETCPUCLOCKID 0
202202

203+
#undef SANITIZER_INTERCEPT_TIMER_CREATE
204+
#define SANITIZER_INTERCEPT_TIMER_CREATE 0
205+
203206
#undef SANITIZER_INTERCEPT_GETITIMER
204207
#define SANITIZER_INTERCEPT_GETITIMER 0
205208

compiler-rt/lib/msan/tests/msan_test.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4881,4 +4881,27 @@ TEST(MemorySanitizer, throw_catch) {
48814881
// pass
48824882
}
48834883
}
4884+
4885+
#if defined(__linux__)
4886+
TEST(MemorySanitizer, timer_create) {
4887+
timer_t timer;
4888+
EXPECT_POISONED(timer);
4889+
int res = timer_create(CLOCK_REALTIME, nullptr, &timer);
4890+
ASSERT_EQ(0, res);
4891+
EXPECT_NOT_POISONED(timer);
4892+
4893+
// Make sure the timer is usable.
4894+
struct itimerspec cur_value {};
4895+
cur_value.it_value.tv_sec = 1;
4896+
EXPECT_EQ(0, timer_settime(timer, 0, &cur_value, nullptr));
4897+
4898+
timer_t timer2;
4899+
EXPECT_POISONED(timer2);
4900+
// Use an invalid clock_id to make timer_create fail.
4901+
res = timer_create(INT_MAX, nullptr, &timer2);
4902+
ASSERT_EQ(-1, res);
4903+
EXPECT_POISONED(timer2);
4904+
timer_delete(timer);
4905+
}
4906+
#endif
48844907
} // namespace

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,6 +2289,24 @@ INTERCEPTOR(int, pthread_getcpuclockid, uptr thread,
22892289
#define INIT_CLOCK_GETCPUCLOCKID
22902290
#endif
22912291

2292+
#if SANITIZER_INTERCEPT_TIMER_CREATE
2293+
INTERCEPTOR(int, timer_create, __sanitizer_clockid_t clockid, void *sevp,
2294+
__sanitizer_timer_t *timer) {
2295+
void *ctx;
2296+
COMMON_INTERCEPTOR_ENTER(ctx, timer_create, clockid, sevp, timer);
2297+
int res = REAL(timer_create)(clockid, sevp, timer);
2298+
if (!res && timer) {
2299+
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, timer, sizeof *timer);
2300+
}
2301+
return res;
2302+
}
2303+
2304+
# define INIT_TIMER_CREATE \
2305+
COMMON_INTERCEPT_FUNCTION_GLIBC_VER_MIN(timer_create, "GLIBC_2.3.3");
2306+
#else
2307+
# define INIT_TIMER_CREATE
2308+
#endif
2309+
22922310
#if SANITIZER_INTERCEPT_GETITIMER
22932311
INTERCEPTOR(int, getitimer, int which, void *curr_value) {
22942312
void *ctx;
@@ -10266,6 +10284,7 @@ static void InitializeCommonInterceptors() {
1026610284
INIT_SETPWENT;
1026710285
INIT_CLOCK_GETTIME;
1026810286
INIT_CLOCK_GETCPUCLOCKID;
10287+
INIT_TIMER_CREATE;
1026910288
INIT_GETITIMER;
1027010289
INIT_TIME;
1027110290
INIT_GLOB;

compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@
237237
(SI_FREEBSD || SI_NETBSD || SI_LINUX || SI_SOLARIS)
238238
#define SANITIZER_INTERCEPT_CLOCK_GETCPUCLOCKID \
239239
(SI_LINUX || SI_FREEBSD || SI_NETBSD)
240+
// TODO: This should be SI_POSIX, adding Linux first until I have time
241+
// to verify all timer_t typedefs on other platforms.
242+
#define SANITIZER_INTERCEPT_TIMER_CREATE SI_LINUX
240243
#define SANITIZER_INTERCEPT_GETITIMER SI_POSIX
241244
#define SANITIZER_INTERCEPT_TIME SI_POSIX
242245
#define SANITIZER_INTERCEPT_GLOB (SI_GLIBC || SI_SOLARIS)

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,10 @@ extern const int si_SEGV_ACCERR;
15171517

15181518
#define SIGACTION_SYMNAME sigaction
15191519

1520+
# if SANITIZER_LINUX
1521+
typedef void *__sanitizer_timer_t;
1522+
# endif
1523+
15201524
#endif // SANITIZER_LINUX || SANITIZER_APPLE
15211525

15221526
#endif

compiler-rt/lib/sanitizer_common/sanitizer_win.cpp

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,39 +1070,11 @@ void SignalContext::DumpAllRegisters(void *context) {
10701070
Printf("\n");
10711071
# elif defined(_M_ARM64)
10721072
Report("Register values:\n");
1073-
Printf("x0 = %llx ", ctx->X0);
1074-
Printf("x1 = %llx ", ctx->X1);
1075-
Printf("x2 = %llx ", ctx->X2);
1076-
Printf("x3 = %llx ", ctx->X3);
1077-
Printf("x4 = %llx ", ctx->X4);
1078-
Printf("x5 = %llx ", ctx->X5);
1079-
Printf("x6 = %llx ", ctx->X6);
1080-
Printf("x7 = %llx ", ctx->X7);
1081-
Printf("x8 = %llx ", ctx->X8);
1082-
Printf("x9 = %llx ", ctx->X9);
1083-
Printf("x10 = %llx ", ctx->X10);
1084-
Printf("x11 = %llx ", ctx->X11);
1085-
Printf("x12 = %llx ", ctx->X12);
1086-
Printf("x13 = %llx ", ctx->X13);
1087-
Printf("x14 = %llx ", ctx->X14);
1088-
Printf("x15 = %llx ", ctx->X15);
1089-
Printf("x16 = %llx ", ctx->X16);
1090-
Printf("x17 = %llx ", ctx->X17);
1091-
Printf("x18 = %llx ", ctx->X18);
1092-
Printf("x19 = %llx ", ctx->X19);
1093-
Printf("x20 = %llx ", ctx->X20);
1094-
Printf("x21 = %llx ", ctx->X21);
1095-
Printf("x22 = %llx ", ctx->X22);
1096-
Printf("x23 = %llx ", ctx->X23);
1097-
Printf("x24 = %llx ", ctx->X24);
1098-
Printf("x25 = %llx ", ctx->X25);
1099-
Printf("x26 = %llx ", ctx->X26);
1100-
Printf("x27 = %llx ", ctx->X27);
1101-
Printf("x28 = %llx ", ctx->X28);
1102-
Printf("x29 = %llx ", ctx->X29);
1103-
Printf("x30 = %llx ", ctx->X30);
1104-
Printf("x31 = %llx ", ctx->X31);
1105-
Printf("\n");
1073+
for (int i = 0; i <= 30; i++) {
1074+
Printf("x%d%s = %llx", i < 10 ? " " : "", ctx->X[i]);
1075+
if (i % 4 == 3)
1076+
Printf("\n");
1077+
}
11061078
# else
11071079
// TODO
11081080
(void)ctx;

0 commit comments

Comments
 (0)