Skip to content

Commit 78f3e97

Browse files
author
iclsrc
committed
Merge from 'main' to 'sycl-web' (36 commits)
2 parents 8085e49 + da90fd7 commit 78f3e97

File tree

105 files changed

+2310
-1085
lines changed

Some content is hidden

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

105 files changed

+2310
-1085
lines changed

clang/docs/tools/clang-formatted-files.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,7 @@ compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp
18371837
compiler-rt/lib/sanitizer_common/sanitizer_stack_store.h
18381838
compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_fuchsia.h
18391839
compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_win.cpp
1840-
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_fuchsia.h
1840+
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup_constants.h
18411841
compiler-rt/lib/sanitizer_common/sanitizer_thread_safety.h
18421842
compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.h
18431843
compiler-rt/lib/sanitizer_common/sanitizer_type_traits.cpp

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5724,7 +5724,7 @@ class Sema final {
57245724
bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
57255725
ObjCMethodDecl *Getter,
57265726
SourceLocation Loc);
5727-
void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
5727+
void DiagnoseSentinelCalls(const NamedDecl *D, SourceLocation Loc,
57285728
ArrayRef<Expr *> Args);
57295729

57305730
void PushExpressionEvaluationContext(

clang/lib/AST/ExprConstant.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15702,12 +15702,14 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx,
1570215702
// this doesn't escape.
1570315703
MaterializeTemporaryExpr BaseMTE(T, const_cast<Expr*>(this), true);
1570415704
APValue::LValueBase Base(&BaseMTE);
15705-
1570615705
Info.setEvaluatingDecl(Base, Result.Val);
15707-
LValue LVal;
15708-
LVal.set(Base);
1570915706

15710-
{
15707+
if (Info.EnableNewConstInterp) {
15708+
if (!Info.Ctx.getInterpContext().evaluateAsRValue(Info, this, Result.Val))
15709+
return false;
15710+
} else {
15711+
LValue LVal;
15712+
LVal.set(Base);
1571115713
// C++23 [intro.execution]/p5
1571215714
// A full-expression is [...] a constant-expression
1571315715
// So we need to make sure temporary objects are destroyed after having
@@ -15716,10 +15718,10 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx,
1571615718
if (!::EvaluateInPlace(Result.Val, Info, LVal, this) ||
1571715719
Result.HasSideEffects || !Scope.destroy())
1571815720
return false;
15719-
}
1572015721

15721-
if (!Info.discardCleanups())
15722-
llvm_unreachable("Unhandled cleanup; missing full expression marker?");
15722+
if (!Info.discardCleanups())
15723+
llvm_unreachable("Unhandled cleanup; missing full expression marker?");
15724+
}
1572315725

1572415726
if (!CheckConstantExpression(Info, getExprLoc(), getStorageType(Ctx, this),
1572515727
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/CodeGen/CGDebugInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1734,7 +1734,8 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, llvm::DIType *RecordTy,
17341734
llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
17351735
auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
17361736
llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
1737-
RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr, Align);
1737+
RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr,
1738+
llvm::dwarf::DW_TAG_member, Align);
17381739
StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
17391740
StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
17401741
return GV;

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2765,10 +2765,8 @@ llvm::Value *CodeGenFunction::EmitAnnotationCall(llvm::Function *AnnotationFn,
27652765
const AnnotateAttr *Attr) {
27662766
SmallVector<llvm::Value *, 5> Args = {
27672767
AnnotatedVal,
2768-
Builder.CreateBitCast(CGM.EmitAnnotationString(AnnotationStr),
2769-
ConstGlobalsPtrTy),
2770-
Builder.CreateBitCast(CGM.EmitAnnotationUnit(Location),
2771-
ConstGlobalsPtrTy),
2768+
CGM.EmitAnnotationString(AnnotationStr),
2769+
CGM.EmitAnnotationUnit(Location),
27722770
CGM.EmitAnnotationLineNo(Location),
27732771
};
27742772
if (Attr)
@@ -2786,15 +2784,10 @@ llvm::Value *CodeGenFunction::EmitAnnotationCall(llvm::Function *AnnotationFn,
27862784

27872785
void CodeGenFunction::EmitVarAnnotations(const VarDecl *D, llvm::Value *V) {
27882786
assert(D->hasAttr<AnnotateAttr>() && "no annotate attribute");
2789-
// FIXME We create a new bitcast for every annotation because that's what
2790-
// llvm-gcc was doing.
2791-
unsigned AS = V->getType()->getPointerAddressSpace();
2792-
llvm::Type *I8PtrTy = Builder.getPtrTy(AS);
27932787
for (const auto *I : D->specific_attrs<AnnotateAttr>())
27942788
EmitAnnotationCall(CGM.getIntrinsic(llvm::Intrinsic::var_annotation,
2795-
{I8PtrTy, CGM.ConstGlobalsPtrTy}),
2796-
Builder.CreateBitCast(V, I8PtrTy, V->getName()),
2797-
I->getAnnotation(), D->getLocation(), I);
2789+
{V->getType(), CGM.ConstGlobalsPtrTy}),
2790+
V, I->getAnnotation(), D->getLocation(), I);
27982791
}
27992792
Address CodeGenFunction::EmitFieldAnnotations(const FieldDecl *D,
28002793
Address Addr) {

clang/lib/Sema/SemaExpr.cpp

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -482,80 +482,83 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
482482
/// message-send is to a declaration with the sentinel attribute, and
483483
/// if so, it checks that the requirements of the sentinel are
484484
/// satisfied.
485-
void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
485+
void Sema::DiagnoseSentinelCalls(const NamedDecl *D, SourceLocation Loc,
486486
ArrayRef<Expr *> Args) {
487-
const SentinelAttr *attr = D->getAttr<SentinelAttr>();
488-
if (!attr)
487+
const SentinelAttr *Attr = D->getAttr<SentinelAttr>();
488+
if (!Attr)
489489
return;
490490

491491
// The number of formal parameters of the declaration.
492-
unsigned numFormalParams;
492+
unsigned NumFormalParams;
493493

494494
// The kind of declaration. This is also an index into a %select in
495495
// the diagnostic.
496-
enum CalleeType { CT_Function, CT_Method, CT_Block } calleeType;
497-
498-
if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
499-
numFormalParams = MD->param_size();
500-
calleeType = CT_Method;
501-
} else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
502-
numFormalParams = FD->param_size();
503-
calleeType = CT_Function;
504-
} else if (isa<VarDecl>(D)) {
505-
QualType type = cast<ValueDecl>(D)->getType();
506-
const FunctionType *fn = nullptr;
507-
if (const PointerType *ptr = type->getAs<PointerType>()) {
508-
fn = ptr->getPointeeType()->getAs<FunctionType>();
509-
if (!fn) return;
510-
calleeType = CT_Function;
511-
} else if (const BlockPointerType *ptr = type->getAs<BlockPointerType>()) {
512-
fn = ptr->getPointeeType()->castAs<FunctionType>();
513-
calleeType = CT_Block;
496+
enum { CK_Function, CK_Method, CK_Block } CalleeKind;
497+
498+
if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
499+
NumFormalParams = MD->param_size();
500+
CalleeKind = CK_Method;
501+
} else if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
502+
NumFormalParams = FD->param_size();
503+
CalleeKind = CK_Function;
504+
} else if (const auto *VD = dyn_cast<VarDecl>(D)) {
505+
QualType Ty = VD->getType();
506+
const FunctionType *Fn = nullptr;
507+
if (const auto *PtrTy = Ty->getAs<PointerType>()) {
508+
Fn = PtrTy->getPointeeType()->getAs<FunctionType>();
509+
if (!Fn)
510+
return;
511+
CalleeKind = CK_Function;
512+
} else if (const auto *PtrTy = Ty->getAs<BlockPointerType>()) {
513+
Fn = PtrTy->getPointeeType()->castAs<FunctionType>();
514+
CalleeKind = CK_Block;
514515
} else {
515516
return;
516517
}
517518

518-
if (const FunctionProtoType *proto = dyn_cast<FunctionProtoType>(fn)) {
519-
numFormalParams = proto->getNumParams();
520-
} else {
521-
numFormalParams = 0;
522-
}
519+
if (const auto *proto = dyn_cast<FunctionProtoType>(Fn))
520+
NumFormalParams = proto->getNumParams();
521+
else
522+
NumFormalParams = 0;
523523
} else {
524524
return;
525525
}
526526

527-
// "nullPos" is the number of formal parameters at the end which
527+
// "NullPos" is the number of formal parameters at the end which
528528
// effectively count as part of the variadic arguments. This is
529529
// useful if you would prefer to not have *any* formal parameters,
530530
// but the language forces you to have at least one.
531-
unsigned nullPos = attr->getNullPos();
532-
assert((nullPos == 0 || nullPos == 1) && "invalid null position on sentinel");
533-
numFormalParams = (nullPos > numFormalParams ? 0 : numFormalParams - nullPos);
531+
unsigned NullPos = Attr->getNullPos();
532+
assert((NullPos == 0 || NullPos == 1) && "invalid null position on sentinel");
533+
NumFormalParams = (NullPos > NumFormalParams ? 0 : NumFormalParams - NullPos);
534534

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

538538
// If there aren't enough arguments for all the formal parameters,
539539
// the sentinel, and the args after the sentinel, complain.
540-
if (Args.size() < numFormalParams + numArgsAfterSentinel + 1) {
540+
if (Args.size() < NumFormalParams + NumArgsAfterSentinel + 1) {
541541
Diag(Loc, diag::warn_not_enough_argument) << D->getDeclName();
542-
Diag(D->getLocation(), diag::note_sentinel_here) << int(calleeType);
542+
Diag(D->getLocation(), diag::note_sentinel_here) << int(CalleeKind);
543543
return;
544544
}
545545

546546
// Otherwise, find the sentinel expression.
547-
Expr *sentinelExpr = Args[Args.size() - numArgsAfterSentinel - 1];
548-
if (!sentinelExpr) return;
549-
if (sentinelExpr->isValueDependent()) return;
550-
if (Context.isSentinelNullExpr(sentinelExpr)) return;
547+
const Expr *SentinelExpr = Args[Args.size() - NumArgsAfterSentinel - 1];
548+
if (!SentinelExpr)
549+
return;
550+
if (SentinelExpr->isValueDependent())
551+
return;
552+
if (Context.isSentinelNullExpr(SentinelExpr))
553+
return;
551554

552555
// Pick a reasonable string to insert. Optimistically use 'nil', 'nullptr',
553556
// or 'NULL' if those are actually defined in the context. Only use
554557
// 'nil' for ObjC methods, where it's much more likely that the
555558
// variadic arguments form a list of object pointers.
556-
SourceLocation MissingNilLoc = getLocForEndOfToken(sentinelExpr->getEndLoc());
559+
SourceLocation MissingNilLoc = getLocForEndOfToken(SentinelExpr->getEndLoc());
557560
std::string NullValue;
558-
if (calleeType == CT_Method && PP.isMacroDefined("nil"))
561+
if (CalleeKind == CK_Method && PP.isMacroDefined("nil"))
559562
NullValue = "nil";
560563
else if (getLangOpts().CPlusPlus11)
561564
NullValue = "nullptr";
@@ -565,12 +568,13 @@ void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
565568
NullValue = "(void*) 0";
566569

567570
if (MissingNilLoc.isInvalid())
568-
Diag(Loc, diag::warn_missing_sentinel) << int(calleeType);
571+
Diag(Loc, diag::warn_missing_sentinel) << int(CalleeKind);
569572
else
570573
Diag(MissingNilLoc, diag::warn_missing_sentinel)
571-
<< int(calleeType)
572-
<< FixItHint::CreateInsertion(MissingNilLoc, ", " + NullValue);
573-
Diag(D->getLocation(), diag::note_sentinel_here) << int(calleeType);
574+
<< int(CalleeKind)
575+
<< FixItHint::CreateInsertion(MissingNilLoc, ", " + NullValue);
576+
Diag(D->getLocation(), diag::note_sentinel_here)
577+
<< int(CalleeKind) << Attr->getRange();
574578
}
575579

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

clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class SimpleStreamChecker : public Checker<check::PostCall,
9090
REGISTER_MAP_WITH_PROGRAMSTATE(StreamMap, SymbolRef, StreamState)
9191

9292
SimpleStreamChecker::SimpleStreamChecker()
93-
: OpenFn({"fopen"}), CloseFn({"fclose"}, 1) {
93+
: OpenFn({"fopen"}, 2), CloseFn({"fclose"}, 1) {
9494
// Initialize the bug types.
9595
DoubleCloseBugType.reset(
9696
new BugType(this, "Double fclose", "Unix Stream API Error"));

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

clang/test/Analysis/stream-non-posix-function.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// RUN: %clang_analyze_cc1 -fno-builtin -analyzer-checker=core,alpha.unix.Stream -verify %s
2+
// RUN: %clang_analyze_cc1 -fno-builtin -analyzer-checker=core,alpha.unix.SimpleStream -verify %s
3+
24
// expected-no-diagnostics
35

46
typedef struct _FILE FILE;

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

0 commit comments

Comments
 (0)