Skip to content

Commit ab12f85

Browse files
committed
Merged main into amd-gfx
2 parents 565b3cd + 8e8bad7 commit ab12f85

File tree

12 files changed

+167
-143
lines changed

12 files changed

+167
-143
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5452,7 +5452,7 @@ class Sema final {
54525452
bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
54535453
ObjCMethodDecl *Getter,
54545454
SourceLocation Loc);
5455-
void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
5455+
void DiagnoseSentinelCalls(const NamedDecl *D, SourceLocation Loc,
54565456
ArrayRef<Expr *> Args);
54575457

54585458
void PushExpressionEvaluationContext(

clang/lib/AST/ExprConstant.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15672,12 +15672,14 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx,
1567215672
// this doesn't escape.
1567315673
MaterializeTemporaryExpr BaseMTE(T, const_cast<Expr*>(this), true);
1567415674
APValue::LValueBase Base(&BaseMTE);
15675-
1567615675
Info.setEvaluatingDecl(Base, Result.Val);
15677-
LValue LVal;
15678-
LVal.set(Base);
1567915676

15680-
{
15677+
if (Info.EnableNewConstInterp) {
15678+
if (!Info.Ctx.getInterpContext().evaluateAsRValue(Info, this, Result.Val))
15679+
return false;
15680+
} else {
15681+
LValue LVal;
15682+
LVal.set(Base);
1568115683
// C++23 [intro.execution]/p5
1568215684
// A full-expression is [...] a constant-expression
1568315685
// So we need to make sure temporary objects are destroyed after having
@@ -15686,10 +15688,10 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx,
1568615688
if (!::EvaluateInPlace(Result.Val, Info, LVal, this) ||
1568715689
Result.HasSideEffects || !Scope.destroy())
1568815690
return false;
15689-
}
1569015691

15691-
if (!Info.discardCleanups())
15692-
llvm_unreachable("Unhandled cleanup; missing full expression marker?");
15692+
if (!Info.discardCleanups())
15693+
llvm_unreachable("Unhandled cleanup; missing full expression marker?");
15694+
}
1569315695

1569415696
if (!CheckConstantExpression(Info, getExprLoc(), getStorageType(Ctx, this),
1569515697
Result.Val, Kind))

clang/lib/AST/Interp/Interp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset,
14531453
DiagInvalidOffset();
14541454
}
14551455

1456-
if (Invalid && !Ptr.isDummy())
1456+
if (Invalid && !Ptr.isDummy() && S.getLangOpts().CPlusPlus)
14571457
return false;
14581458

14591459
// Offset is valid - compute it on unsigned.
@@ -1531,7 +1531,7 @@ inline bool SubPtr(InterpState &S, CodePtr OpPC) {
15311531
const Pointer &LHS = S.Stk.pop<Pointer>();
15321532
const Pointer &RHS = S.Stk.pop<Pointer>();
15331533

1534-
if (!Pointer::hasSameArray(LHS, RHS)) {
1534+
if (!Pointer::hasSameBase(LHS, RHS) && S.getLangOpts().CPlusPlus) {
15351535
// TODO: Diagnose.
15361536
return false;
15371537
}

clang/lib/Sema/SemaExpr.cpp

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -414,80 +414,83 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
414414
/// message-send is to a declaration with the sentinel attribute, and
415415
/// if so, it checks that the requirements of the sentinel are
416416
/// satisfied.
417-
void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
417+
void Sema::DiagnoseSentinelCalls(const NamedDecl *D, SourceLocation Loc,
418418
ArrayRef<Expr *> Args) {
419-
const SentinelAttr *attr = D->getAttr<SentinelAttr>();
420-
if (!attr)
419+
const SentinelAttr *Attr = D->getAttr<SentinelAttr>();
420+
if (!Attr)
421421
return;
422422

423423
// The number of formal parameters of the declaration.
424-
unsigned numFormalParams;
424+
unsigned NumFormalParams;
425425

426426
// The kind of declaration. This is also an index into a %select in
427427
// the diagnostic.
428-
enum CalleeType { CT_Function, CT_Method, CT_Block } calleeType;
429-
430-
if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
431-
numFormalParams = MD->param_size();
432-
calleeType = CT_Method;
433-
} else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
434-
numFormalParams = FD->param_size();
435-
calleeType = CT_Function;
436-
} else if (isa<VarDecl>(D)) {
437-
QualType type = cast<ValueDecl>(D)->getType();
438-
const FunctionType *fn = nullptr;
439-
if (const PointerType *ptr = type->getAs<PointerType>()) {
440-
fn = ptr->getPointeeType()->getAs<FunctionType>();
441-
if (!fn) return;
442-
calleeType = CT_Function;
443-
} else if (const BlockPointerType *ptr = type->getAs<BlockPointerType>()) {
444-
fn = ptr->getPointeeType()->castAs<FunctionType>();
445-
calleeType = CT_Block;
428+
enum { CK_Function, CK_Method, CK_Block } CalleeKind;
429+
430+
if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
431+
NumFormalParams = MD->param_size();
432+
CalleeKind = CK_Method;
433+
} else if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
434+
NumFormalParams = FD->param_size();
435+
CalleeKind = CK_Function;
436+
} else if (const auto *VD = dyn_cast<VarDecl>(D)) {
437+
QualType Ty = VD->getType();
438+
const FunctionType *Fn = nullptr;
439+
if (const auto *PtrTy = Ty->getAs<PointerType>()) {
440+
Fn = PtrTy->getPointeeType()->getAs<FunctionType>();
441+
if (!Fn)
442+
return;
443+
CalleeKind = CK_Function;
444+
} else if (const auto *PtrTy = Ty->getAs<BlockPointerType>()) {
445+
Fn = PtrTy->getPointeeType()->castAs<FunctionType>();
446+
CalleeKind = CK_Block;
446447
} else {
447448
return;
448449
}
449450

450-
if (const FunctionProtoType *proto = dyn_cast<FunctionProtoType>(fn)) {
451-
numFormalParams = proto->getNumParams();
452-
} else {
453-
numFormalParams = 0;
454-
}
451+
if (const auto *proto = dyn_cast<FunctionProtoType>(Fn))
452+
NumFormalParams = proto->getNumParams();
453+
else
454+
NumFormalParams = 0;
455455
} else {
456456
return;
457457
}
458458

459-
// "nullPos" is the number of formal parameters at the end which
459+
// "NullPos" is the number of formal parameters at the end which
460460
// effectively count as part of the variadic arguments. This is
461461
// useful if you would prefer to not have *any* formal parameters,
462462
// but the language forces you to have at least one.
463-
unsigned nullPos = attr->getNullPos();
464-
assert((nullPos == 0 || nullPos == 1) && "invalid null position on sentinel");
465-
numFormalParams = (nullPos > numFormalParams ? 0 : numFormalParams - nullPos);
463+
unsigned NullPos = Attr->getNullPos();
464+
assert((NullPos == 0 || NullPos == 1) && "invalid null position on sentinel");
465+
NumFormalParams = (NullPos > NumFormalParams ? 0 : NumFormalParams - NullPos);
466466

467467
// The number of arguments which should follow the sentinel.
468-
unsigned numArgsAfterSentinel = attr->getSentinel();
468+
unsigned NumArgsAfterSentinel = Attr->getSentinel();
469469

470470
// If there aren't enough arguments for all the formal parameters,
471471
// the sentinel, and the args after the sentinel, complain.
472-
if (Args.size() < numFormalParams + numArgsAfterSentinel + 1) {
472+
if (Args.size() < NumFormalParams + NumArgsAfterSentinel + 1) {
473473
Diag(Loc, diag::warn_not_enough_argument) << D->getDeclName();
474-
Diag(D->getLocation(), diag::note_sentinel_here) << int(calleeType);
474+
Diag(D->getLocation(), diag::note_sentinel_here) << int(CalleeKind);
475475
return;
476476
}
477477

478478
// Otherwise, find the sentinel expression.
479-
Expr *sentinelExpr = Args[Args.size() - numArgsAfterSentinel - 1];
480-
if (!sentinelExpr) return;
481-
if (sentinelExpr->isValueDependent()) return;
482-
if (Context.isSentinelNullExpr(sentinelExpr)) return;
479+
const Expr *SentinelExpr = Args[Args.size() - NumArgsAfterSentinel - 1];
480+
if (!SentinelExpr)
481+
return;
482+
if (SentinelExpr->isValueDependent())
483+
return;
484+
if (Context.isSentinelNullExpr(SentinelExpr))
485+
return;
483486

484487
// Pick a reasonable string to insert. Optimistically use 'nil', 'nullptr',
485488
// or 'NULL' if those are actually defined in the context. Only use
486489
// 'nil' for ObjC methods, where it's much more likely that the
487490
// variadic arguments form a list of object pointers.
488-
SourceLocation MissingNilLoc = getLocForEndOfToken(sentinelExpr->getEndLoc());
491+
SourceLocation MissingNilLoc = getLocForEndOfToken(SentinelExpr->getEndLoc());
489492
std::string NullValue;
490-
if (calleeType == CT_Method && PP.isMacroDefined("nil"))
493+
if (CalleeKind == CK_Method && PP.isMacroDefined("nil"))
491494
NullValue = "nil";
492495
else if (getLangOpts().CPlusPlus11)
493496
NullValue = "nullptr";
@@ -497,12 +500,13 @@ void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
497500
NullValue = "(void*) 0";
498501

499502
if (MissingNilLoc.isInvalid())
500-
Diag(Loc, diag::warn_missing_sentinel) << int(calleeType);
503+
Diag(Loc, diag::warn_missing_sentinel) << int(CalleeKind);
501504
else
502505
Diag(MissingNilLoc, diag::warn_missing_sentinel)
503-
<< int(calleeType)
504-
<< FixItHint::CreateInsertion(MissingNilLoc, ", " + NullValue);
505-
Diag(D->getLocation(), diag::note_sentinel_here) << int(calleeType);
506+
<< int(CalleeKind)
507+
<< FixItHint::CreateInsertion(MissingNilLoc, ", " + NullValue);
508+
Diag(D->getLocation(), diag::note_sentinel_here)
509+
<< int(CalleeKind) << Attr->getRange();
506510
}
507511

508512
SourceRange Sema::getExprRange(Expr *E) const {

clang/test/AST/Interp/c.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// RUN: %clang_cc1 -pedantic -verify=pedantic-ref -std=c11 %s
55

66
typedef __INTPTR_TYPE__ intptr_t;
7+
typedef __PTRDIFF_TYPE__ ptrdiff_t;
78

89
_Static_assert(1, "");
910
_Static_assert(0 != 1, "");
@@ -81,3 +82,6 @@ const intptr_t L = (intptr_t)(&(yy->y)); // expected-error {{not a compile-time
8182
// pedantic-expected-error {{not a compile-time constant}} \
8283
// ref-error {{not a compile-time constant}} \
8384
// pedantic-ref-error {{not a compile-time constant}}
85+
const ptrdiff_t m = &m + 137 - &m;
86+
_Static_assert(m == 137, ""); // pedantic-ref-warning {{GNU extension}} \
87+
// pedantic-expected-warning {{GNU extension}}

clang/test/AST/Interp/literals.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define INT_MAX __INT_MAX__
88

99
typedef __INTPTR_TYPE__ intptr_t;
10+
typedef __PTRDIFF_TYPE__ ptrdiff_t;
1011

1112

1213
static_assert(true, "");
@@ -198,6 +199,20 @@ namespace PointerComparison {
198199
// ref-note {{comparison between '&s.b' and 'nullptr' has unspecified value}}
199200

200201
constexpr bool v7 = qv <= (void*)&s.b; // ok
202+
203+
constexpr ptrdiff_t m = &m - &m;
204+
static_assert(m == 0, "");
205+
206+
constexpr ptrdiff_t m2 = (&m2 + 1) - (&m2 + 1);
207+
static_assert(m2 == 0, "");
208+
209+
constexpr long m3 = (&m3 + 1) - (&m3);
210+
static_assert(m3 == 1, "");
211+
212+
constexpr long m4 = &m4 + 2 - &m4; // ref-error {{must be initialized by a constant expression}} \
213+
// ref-note {{cannot refer to element 2 of non-array object}} \
214+
// expected-error {{must be initialized by a constant expression}} \
215+
// expected-note {{cannot refer to element 2 of non-array object}}
201216
}
202217

203218
namespace SizeOf {
@@ -261,15 +276,13 @@ namespace SizeOf {
261276
#if __cplusplus >= 202002L
262277
/// FIXME: The following code should be accepted.
263278
consteval int foo(int n) { // ref-error {{consteval function never produces a constant expression}}
264-
return sizeof(int[n]); // ref-note 3{{not valid in a constant expression}} \
265-
// expected-note {{not valid in a constant expression}}
279+
return sizeof(int[n]); // ref-note 3{{not valid in a constant expression}}
266280
}
267281
constinit int var = foo(5); // ref-error {{not a constant expression}} \
268282
// ref-note 2{{in call to}} \
269283
// ref-error {{does not have a constant initializer}} \
270284
// ref-note {{required by 'constinit' specifier}} \
271285
// expected-error {{is not a constant expression}} \
272-
// expected-note {{in call to}} \
273286
// expected-error {{does not have a constant initializer}} \
274287
// expected-note {{required by 'constinit' specifier}} \
275288

compiler-rt/lib/hwasan/hwasan_linux.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -294,25 +294,6 @@ void InstallAtExitHandler() { atexit(HwasanAtExit); }
294294

295295
// ---------------------- TSD ---------------- {{{1
296296

297-
extern "C" void __hwasan_thread_enter() {
298-
hwasanThreadList().CreateCurrentThread()->EnsureRandomStateInited();
299-
}
300-
301-
extern "C" void __hwasan_thread_exit() {
302-
Thread *t = GetCurrentThread();
303-
// Make sure that signal handler can not see a stale current thread pointer.
304-
atomic_signal_fence(memory_order_seq_cst);
305-
if (t) {
306-
// Block async signals on the thread as the handler can be instrumented.
307-
// After this point instrumented code can't access essential data from TLS
308-
// and will crash.
309-
// Bionic already calls __hwasan_thread_exit with blocked signals.
310-
if (SANITIZER_GLIBC)
311-
BlockSignals();
312-
hwasanThreadList().ReleaseThread(t);
313-
}
314-
}
315-
316297
# if HWASAN_WITH_INTERCEPTORS
317298
static pthread_key_t tsd_key;
318299
static bool tsd_key_inited = false;
@@ -561,4 +542,25 @@ void InstallAtExitCheckLeaks() {
561542

562543
} // namespace __hwasan
563544

545+
using namespace __hwasan;
546+
547+
extern "C" void __hwasan_thread_enter() {
548+
hwasanThreadList().CreateCurrentThread()->EnsureRandomStateInited();
549+
}
550+
551+
extern "C" void __hwasan_thread_exit() {
552+
Thread *t = GetCurrentThread();
553+
// Make sure that signal handler can not see a stale current thread pointer.
554+
atomic_signal_fence(memory_order_seq_cst);
555+
if (t) {
556+
// Block async signals on the thread as the handler can be instrumented.
557+
// After this point instrumented code can't access essential data from TLS
558+
// and will crash.
559+
// Bionic already calls __hwasan_thread_exit with blocked signals.
560+
if (SANITIZER_GLIBC)
561+
BlockSignals();
562+
hwasanThreadList().ReleaseThread(t);
563+
}
564+
}
565+
564566
#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD

llvm/include/llvm/FileCheck/FileCheck.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,24 +187,14 @@ class FileCheck {
187187
explicit FileCheck(FileCheckRequest Req);
188188
~FileCheck();
189189

190-
// Combines the check prefixes into a single regex so that we can efficiently
191-
// scan for any of the set.
192-
//
193-
// The semantics are that the longest-match wins which matches our regex
194-
// library.
195-
Regex buildCheckPrefixRegex();
196-
197190
/// Reads the check file from \p Buffer and records the expected strings it
198191
/// contains. Errors are reported against \p SM.
199192
///
200-
/// Only expected strings whose prefix is one of those listed in \p PrefixRE
201-
/// are recorded. \returns true in case of an error, false otherwise.
202-
///
203193
/// If \p ImpPatBufferIDRange, then the range (inclusive start, exclusive end)
204194
/// of IDs for source buffers added to \p SM for implicit patterns are
205195
/// recorded in it. The range is empty if there are none.
206196
bool
207-
readCheckFile(SourceMgr &SM, StringRef Buffer, Regex &PrefixRE,
197+
readCheckFile(SourceMgr &SM, StringRef Buffer,
208198
std::pair<unsigned, unsigned> *ImpPatBufferIDRange = nullptr);
209199

210200
bool ValidateCheckPrefixes();

0 commit comments

Comments
 (0)