Skip to content

Commit 92c227b

Browse files
committed
Merge branch 'main' into pr/riscv-reg-errors-3
2 parents dedeb44 + 55015e1 commit 92c227b

File tree

402 files changed

+12455
-5073
lines changed

Some content is hidden

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

402 files changed

+12455
-5073
lines changed

clang/docs/BoundsSafety.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,13 +777,13 @@ the transformed pseudo code of function ``alloc_buf()`` in the example below.
777777
size_t count;
778778
} sized_buf_t;
779779
780-
void alloc_buf(sized_buf_t *sbuf, sized_t nelems) {
780+
void alloc_buf(sized_buf_t *sbuf, size_t nelems) {
781781
sbuf->buf = (int *)malloc(sizeof(int) * nelems);
782782
sbuf->count = nelems;
783783
}
784784
785785
// Transformed pseudo code:
786-
void alloc_buf(sized_buf_t *sbuf, sized_t nelems) {
786+
void alloc_buf(sized_buf_t *sbuf, size_t nelems) {
787787
// Materialize RHS values:
788788
int *tmp_ptr = (int *)malloc(sizeof(int) * nelems);
789789
int tmp_count = nelems;

clang/docs/BoundsSafetyImplPlans.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ same basic block and without side effect in between.
134134
int *__counted_by(count) buf; size_t count;
135135
} sized_buf_t;
136136
137-
void alloc_buf(sized_buf_t *sbuf, sized_t nelems) {
137+
void alloc_buf(sized_buf_t *sbuf, size_t nelems) {
138138
sbuf->buf = (int *)malloc(sizeof(int) * nelems);
139139
sbuf->count = nelems;
140140
}

clang/include/clang/Basic/TargetInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,7 @@ class TargetInfo : public TransferrableTargetInfo,
16621662
// access target-specific GPU grid values that must be consistent between
16631663
// host RTL (plugin), deviceRTL and clang.
16641664
virtual const llvm::omp::GV &getGridValue() const {
1665-
llvm_unreachable("getGridValue not implemented on this target");
1665+
return llvm::omp::SPIRVGridValues;
16661666
}
16671667

16681668
/// Retrieve the name of the platform as it is used in the

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3421,8 +3421,6 @@ def fno_strict_aliasing : Flag<["-"], "fno-strict-aliasing">, Group<f_Group>,
34213421
def fstruct_path_tbaa : Flag<["-"], "fstruct-path-tbaa">, Group<f_Group>;
34223422
def fno_struct_path_tbaa : Flag<["-"], "fno-struct-path-tbaa">, Group<f_Group>;
34233423
def fno_strict_enums : Flag<["-"], "fno-strict-enums">, Group<f_Group>;
3424-
def fno_strict_overflow : Flag<["-"], "fno-strict-overflow">, Group<f_Group>,
3425-
Visibility<[ClangOption, FlangOption]>;
34263424
defm init_global_zero : BoolOptionWithoutMarshalling<"f", "init-global-zero",
34273425
PosFlag<SetTrue, [], [FlangOption, FC1Option],
34283426
"Zero initialize globals without default initialization (default)">,
@@ -3934,7 +3932,9 @@ defm strict_vtable_pointers : BoolFOption<"strict-vtable-pointers",
39343932
" overwriting polymorphic C++ objects">,
39353933
NegFlag<SetFalse>>;
39363934
def fstrict_overflow : Flag<["-"], "fstrict-overflow">, Group<f_Group>,
3937-
Visibility<[ClangOption, FlangOption]>;
3935+
Visibility<[ClangOption, CLOption, FlangOption]>;
3936+
def fno_strict_overflow : Flag<["-"], "fno-strict-overflow">, Group<f_Group>,
3937+
Visibility<[ClangOption, CLOption, FlangOption]>;
39383938
def fpointer_tbaa : Flag<["-"], "fpointer-tbaa">, Group<f_Group>;
39393939
def fdriver_only : Flag<["-"], "fdriver-only">, Flags<[NoXarchOption]>,
39403940
Visibility<[ClangOption, CLOption, DXCOption]>,

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 120 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ template <class Emitter> class StmtExprScope final {
194194
template <class Emitter>
195195
bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
196196
const Expr *SubExpr = CE->getSubExpr();
197-
switch (CE->getCastKind()) {
198197

199-
case CK_LValueToRValue: {
200-
if (DiscardResult)
201-
return this->discard(SubExpr);
198+
if (DiscardResult)
199+
return this->delegate(SubExpr);
202200

201+
switch (CE->getCastKind()) {
202+
case CK_LValueToRValue: {
203203
std::optional<PrimType> SubExprT = classify(SubExpr->getType());
204204
// Prepare storage for the result.
205205
if (!Initializing && !SubExprT) {
@@ -253,9 +253,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
253253

254254
case CK_UncheckedDerivedToBase:
255255
case CK_DerivedToBase: {
256-
if (DiscardResult)
257-
return this->discard(SubExpr);
258-
259256
if (!this->delegate(SubExpr))
260257
return false;
261258

@@ -285,9 +282,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
285282
}
286283

287284
case CK_BaseToDerived: {
288-
if (DiscardResult)
289-
return this->discard(SubExpr);
290-
291285
if (!this->delegate(SubExpr))
292286
return false;
293287

@@ -302,17 +296,13 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
302296
if (!SubExpr->getType()->isFloatingType() ||
303297
!CE->getType()->isFloatingType())
304298
return false;
305-
if (DiscardResult)
306-
return this->discard(SubExpr);
307299
if (!this->visit(SubExpr))
308300
return false;
309301
const auto *TargetSemantics = &Ctx.getFloatSemantics(CE->getType());
310302
return this->emitCastFP(TargetSemantics, getRoundingMode(CE), CE);
311303
}
312304

313305
case CK_IntegralToFloating: {
314-
if (DiscardResult)
315-
return this->discard(SubExpr);
316306
std::optional<PrimType> FromT = classify(SubExpr->getType());
317307
if (!FromT)
318308
return false;
@@ -327,8 +317,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
327317

328318
case CK_FloatingToBoolean:
329319
case CK_FloatingToIntegral: {
330-
if (DiscardResult)
331-
return this->discard(SubExpr);
332320

333321
std::optional<PrimType> ToT = classify(CE->getType());
334322

@@ -352,9 +340,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
352340
case CK_NullToMemberPointer: {
353341
if (!this->discard(SubExpr))
354342
return false;
355-
if (DiscardResult)
356-
return true;
357-
358343
const Descriptor *Desc = nullptr;
359344
const QualType PointeeType = CE->getType()->getPointeeType();
360345
if (!PointeeType.isNull()) {
@@ -371,9 +356,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
371356
}
372357

373358
case CK_PointerToIntegral: {
374-
if (DiscardResult)
375-
return this->discard(SubExpr);
376-
377359
if (!this->visit(SubExpr))
378360
return false;
379361

@@ -399,8 +381,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
399381
return false;
400382
if (!this->emitArrayDecay(CE))
401383
return false;
402-
if (DiscardResult)
403-
return this->emitPopPtr(CE);
404384
return true;
405385
}
406386

@@ -412,9 +392,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
412392
// FIXME: I think the discard is wrong since the int->ptr cast might cause a
413393
// diagnostic.
414394
PrimType T = classifyPrim(IntType);
415-
if (DiscardResult)
416-
return this->emitPop(T, CE);
417-
418395
QualType PtrType = CE->getType();
419396
const Descriptor *Desc;
420397
if (std::optional<PrimType> T = classify(PtrType->getPointeeType()))
@@ -454,10 +431,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
454431
return false;
455432
return this->emitInvalidCast(CastKind::Reinterpret, /*Fatal=*/true, CE);
456433
}
457-
458-
if (DiscardResult)
459-
return this->discard(SubExpr);
460-
461434
QualType SubExprTy = SubExpr->getType();
462435
std::optional<PrimType> FromT = classify(SubExprTy);
463436
// Casts from integer/vector to vector.
@@ -493,8 +466,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
493466
case CK_FixedPointToBoolean:
494467
case CK_BooleanToSignedIntegral:
495468
case CK_IntegralCast: {
496-
if (DiscardResult)
497-
return this->discard(SubExpr);
498469
std::optional<PrimType> FromT = classify(SubExpr->getType());
499470
std::optional<PrimType> ToT = classify(CE->getType());
500471

@@ -546,8 +517,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
546517

547518
case CK_IntegralComplexToBoolean:
548519
case CK_FloatingComplexToBoolean: {
549-
if (DiscardResult)
550-
return this->discard(SubExpr);
551520
if (!this->visit(SubExpr))
552521
return false;
553522
return this->emitComplexBoolCast(SubExpr);
@@ -585,9 +554,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
585554
case CK_FloatingComplexToIntegralComplex: {
586555
assert(CE->getType()->isAnyComplexType());
587556
assert(SubExpr->getType()->isAnyComplexType());
588-
if (DiscardResult)
589-
return this->discard(SubExpr);
590-
591557
if (!Initializing) {
592558
std::optional<unsigned> LocalIndex = allocateLocal(CE);
593559
if (!LocalIndex)
@@ -633,9 +599,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
633599
assert(classify(SubExpr->getType()));
634600
assert(CE->getType()->isVectorType());
635601

636-
if (DiscardResult)
637-
return this->discard(SubExpr);
638-
639602
if (!Initializing) {
640603
std::optional<unsigned> LocalIndex = allocateLocal(CE);
641604
if (!LocalIndex)
@@ -3370,15 +3333,23 @@ bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) {
33703333

33713334
PrimType SizeT = classifyPrim(Stripped->getType());
33723335

3336+
// Save evaluated array size to a variable.
3337+
unsigned ArrayLen = allocateLocalPrimitive(
3338+
Stripped, SizeT, /*IsConst=*/false, /*IsExtended=*/false);
3339+
if (!this->visit(Stripped))
3340+
return false;
3341+
if (!this->emitSetLocal(SizeT, ArrayLen, E))
3342+
return false;
3343+
33733344
if (PlacementDest) {
33743345
if (!this->visit(PlacementDest))
33753346
return false;
3376-
if (!this->visit(Stripped))
3347+
if (!this->emitGetLocal(SizeT, ArrayLen, E))
33773348
return false;
33783349
if (!this->emitCheckNewTypeMismatchArray(SizeT, E, E))
33793350
return false;
33803351
} else {
3381-
if (!this->visit(Stripped))
3352+
if (!this->emitGetLocal(SizeT, ArrayLen, E))
33823353
return false;
33833354

33843355
if (ElemT) {
@@ -3392,10 +3363,113 @@ bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) {
33923363
}
33933364
}
33943365

3395-
if (Init && !this->visitInitializer(Init))
3396-
return false;
3366+
if (Init) {
3367+
QualType InitType = Init->getType();
3368+
size_t StaticInitElems = 0;
3369+
const Expr *DynamicInit = nullptr;
3370+
if (const ConstantArrayType *CAT =
3371+
Ctx.getASTContext().getAsConstantArrayType(InitType)) {
3372+
StaticInitElems = CAT->getZExtSize();
3373+
if (!this->visitInitializer(Init))
3374+
return false;
33973375

3398-
} else {
3376+
if (const auto *ILE = dyn_cast<InitListExpr>(Init);
3377+
ILE && ILE->hasArrayFiller())
3378+
DynamicInit = ILE->getArrayFiller();
3379+
}
3380+
3381+
// The initializer initializes a certain number of elements, S.
3382+
// However, the complete number of elements, N, might be larger than that.
3383+
// In this case, we need to get an initializer for the remaining elements.
3384+
// There are to cases:
3385+
// 1) For the form 'new Struct[n];', the initializer is a
3386+
// CXXConstructExpr and its type is an IncompleteArrayType.
3387+
// 2) For the form 'new Struct[n]{1,2,3}', the initializer is an
3388+
// InitListExpr and the initializer for the remaining elements
3389+
// is the array filler.
3390+
3391+
if (DynamicInit || InitType->isIncompleteArrayType()) {
3392+
const Function *CtorFunc = nullptr;
3393+
if (const auto *CE = dyn_cast<CXXConstructExpr>(Init)) {
3394+
CtorFunc = getFunction(CE->getConstructor());
3395+
if (!CtorFunc)
3396+
return false;
3397+
}
3398+
3399+
LabelTy EndLabel = this->getLabel();
3400+
LabelTy StartLabel = this->getLabel();
3401+
3402+
// In the nothrow case, the alloc above might have returned nullptr.
3403+
// Don't call any constructors that case.
3404+
if (IsNoThrow) {
3405+
if (!this->emitDupPtr(E))
3406+
return false;
3407+
if (!this->emitNullPtr(0, nullptr, E))
3408+
return false;
3409+
if (!this->emitEQPtr(E))
3410+
return false;
3411+
if (!this->jumpTrue(EndLabel))
3412+
return false;
3413+
}
3414+
3415+
// Create loop variables.
3416+
unsigned Iter = allocateLocalPrimitive(
3417+
Stripped, SizeT, /*IsConst=*/false, /*IsExtended=*/false);
3418+
if (!this->emitConst(StaticInitElems, SizeT, E))
3419+
return false;
3420+
if (!this->emitSetLocal(SizeT, Iter, E))
3421+
return false;
3422+
3423+
this->fallthrough(StartLabel);
3424+
this->emitLabel(StartLabel);
3425+
// Condition. Iter < ArrayLen?
3426+
if (!this->emitGetLocal(SizeT, Iter, E))
3427+
return false;
3428+
if (!this->emitGetLocal(SizeT, ArrayLen, E))
3429+
return false;
3430+
if (!this->emitLT(SizeT, E))
3431+
return false;
3432+
if (!this->jumpFalse(EndLabel))
3433+
return false;
3434+
3435+
// Pointer to the allocated array is already on the stack.
3436+
if (!this->emitGetLocal(SizeT, Iter, E))
3437+
return false;
3438+
if (!this->emitArrayElemPtr(SizeT, E))
3439+
return false;
3440+
3441+
if (DynamicInit) {
3442+
if (std::optional<PrimType> InitT = classify(DynamicInit)) {
3443+
if (!this->visit(DynamicInit))
3444+
return false;
3445+
if (!this->emitStorePop(*InitT, E))
3446+
return false;
3447+
} else {
3448+
if (!this->visitInitializer(DynamicInit))
3449+
return false;
3450+
if (!this->emitPopPtr(E))
3451+
return false;
3452+
}
3453+
} else {
3454+
assert(CtorFunc);
3455+
if (!this->emitCall(CtorFunc, 0, E))
3456+
return false;
3457+
}
3458+
3459+
// ++Iter;
3460+
if (!this->emitGetPtrLocal(Iter, E))
3461+
return false;
3462+
if (!this->emitIncPop(SizeT, E))
3463+
return false;
3464+
3465+
if (!this->jump(StartLabel))
3466+
return false;
3467+
3468+
this->fallthrough(EndLabel);
3469+
this->emitLabel(EndLabel);
3470+
}
3471+
}
3472+
} else { // Non-array.
33993473
if (PlacementDest) {
34003474
if (!this->visit(PlacementDest))
34013475
return false;

clang/lib/AST/ByteCode/Interp.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,10 @@ bool InitThisBitField(InterpState &S, CodePtr OpPC, const Record::Field *F,
14841484
template <PrimType Name, class T = typename PrimConv<Name>::T>
14851485
bool InitField(InterpState &S, CodePtr OpPC, uint32_t I) {
14861486
const T &Value = S.Stk.pop<T>();
1487-
const Pointer &Field = S.Stk.peek<Pointer>().atField(I);
1487+
const Pointer &Ptr = S.Stk.peek<Pointer>();
1488+
if (!CheckRange(S, OpPC, Ptr, CSK_Field))
1489+
return false;
1490+
const Pointer &Field = Ptr.atField(I);
14881491
Field.deref<T>() = Value;
14891492
Field.activate();
14901493
Field.initialize();

clang/lib/AST/RawCommentList.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,13 @@ void RawCommentList::addComment(const RawComment &RC,
287287

288288
// If this is the first Doxygen comment, save it (because there isn't
289289
// anything to merge it with).
290-
if (OrderedComments[CommentFile].empty()) {
291-
OrderedComments[CommentFile][CommentOffset] =
292-
new (Allocator) RawComment(RC);
290+
auto &OC = OrderedComments[CommentFile];
291+
if (OC.empty()) {
292+
OC[CommentOffset] = new (Allocator) RawComment(RC);
293293
return;
294294
}
295295

296-
const RawComment &C1 = *OrderedComments[CommentFile].rbegin()->second;
296+
const RawComment &C1 = *OC.rbegin()->second;
297297
const RawComment &C2 = RC;
298298

299299
// Merge comments only if there is only whitespace between them.

0 commit comments

Comments
 (0)