Skip to content

Commit f618a1c

Browse files
committed
Merge remote-tracking branch 'origin/main' into vplan-multiple-fmaxnum-rdxs
2 parents 65031f4 + ff108f7 commit f618a1c

File tree

104 files changed

+2371
-789
lines changed

Some content is hidden

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

104 files changed

+2371
-789
lines changed

bolt/test/runtime/AArch64/inline-memcpy.s

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@
8181
# CHECK-ASM: bl{{.*}}<memcpy
8282

8383
# Register move should NOT be inlined (size unknown at compile time)
84-
# CHECK-ASM-LABEL: <test_register_move_negative>:
84+
# CHECK-ASM-LABEL: <test_register_move_unknown>:
8585
# CHECK-ASM: bl{{.*}}<memcpy
8686

87-
# CHECK-ASM-LABEL: <test_x2_rewrite_negative>:
87+
# CHECK-ASM-LABEL: <test_x2_rewrite_unknown>:
8888
# CHECK-ASM: bl{{.*}}<memcpy
8989

9090
# Live-in parameter should NOT be inlined (size unknown at compile time)
91-
# CHECK-ASM-LABEL: <test_live_in_negative>:
91+
# CHECK-ASM-LABEL: <test_live_in_unknown>:
9292
# CHECK-ASM: bl{{.*}}<memcpy
9393

9494
# _memcpy8 should be inlined with end-pointer return (dest+size)
@@ -262,9 +262,9 @@ test_4_byte_add_immediate:
262262
ret
263263
.size test_4_byte_add_immediate, .-test_4_byte_add_immediate
264264

265-
.globl test_register_move_negative
266-
.type test_register_move_negative,@function
267-
test_register_move_negative:
265+
.globl test_register_move_unknown
266+
.type test_register_move_unknown,@function
267+
test_register_move_unknown:
268268
stp x29, x30, [sp, #-32]!
269269
mov x29, sp
270270
add x1, sp, #16
@@ -274,20 +274,20 @@ test_register_move_negative:
274274
bl memcpy
275275
ldp x29, x30, [sp], #32
276276
ret
277-
.size test_register_move_negative, .-test_register_move_negative
277+
.size test_register_move_unknown, .-test_register_move_unknown
278278

279-
.globl test_x2_rewrite_negative
280-
.type test_x2_rewrite_negative,@function
281-
test_x2_rewrite_negative:
279+
.globl test_x2_rewrite_unknown
280+
.type test_x2_rewrite_unknown,@function
281+
test_x2_rewrite_unknown:
282282
mov x2, #8
283283
ldr x2, [sp, #24]
284284
bl memcpy
285285
ret
286-
.size test_x2_rewrite_negative, .-test_x2_rewrite_negative
286+
.size test_x2_rewrite_unknown, .-test_x2_rewrite_unknown
287287

288-
.globl test_live_in_negative
289-
.type test_live_in_negative,@function
290-
test_live_in_negative:
288+
.globl test_live_in_unknown
289+
.type test_live_in_unknown,@function
290+
test_live_in_unknown:
291291
# x2 comes in as parameter, no instruction sets it (should NOT inline)
292292
stp x29, x30, [sp, #-32]!
293293
mov x29, sp
@@ -297,7 +297,7 @@ test_live_in_negative:
297297
bl memcpy
298298
ldp x29, x30, [sp], #32
299299
ret
300-
.size test_live_in_negative, .-test_live_in_negative
300+
.size test_live_in_unknown, .-test_live_in_unknown
301301

302302
.globl test_memcpy8_4_byte
303303
.type test_memcpy8_4_byte,@function

clang-tools-extra/docs/clang-tidy/checks/cert/mem57-cpp.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cert-mem57-cpp
44
==============
55

66
The `cert-mem57-cpp` is an aliaes, please see
7-
`bugprone-default-operator-new-on-overaligned-type <../bugprone/default-operator-new-on-overaligned-type>`_
7+
`bugprone-default-operator-new-on-overaligned-type <../bugprone/default-operator-new-on-overaligned-type.html>`_
88
for more information.
99

1010
This check corresponds to the CERT C++ Coding Standard rule

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11668,7 +11668,7 @@ class Sema final : public SemaBase {
1166811668
ASTTemplateArgsPtr TemplateArgsIn, SourceLocation RAngleLoc);
1166911669

1167011670
DeclResult ActOnVarTemplateSpecialization(
11671-
Scope *S, Declarator &D, TypeSourceInfo *DI, LookupResult &Previous,
11671+
Scope *S, Declarator &D, TypeSourceInfo *TSI, LookupResult &Previous,
1167211672
SourceLocation TemplateKWLoc, TemplateParameterList *TemplateParams,
1167311673
StorageClass SC, bool IsPartialSpecialization);
1167411674

clang/lib/AST/ASTContext.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3108,9 +3108,9 @@ TypeSourceInfo *ASTContext::CreateTypeSourceInfo(QualType T,
31083108

31093109
TypeSourceInfo *ASTContext::getTrivialTypeSourceInfo(QualType T,
31103110
SourceLocation L) const {
3111-
TypeSourceInfo *DI = CreateTypeSourceInfo(T);
3112-
DI->getTypeLoc().initialize(const_cast<ASTContext &>(*this), L);
3113-
return DI;
3111+
TypeSourceInfo *TSI = CreateTypeSourceInfo(T);
3112+
TSI->getTypeLoc().initialize(const_cast<ASTContext &>(*this), L);
3113+
return TSI;
31143114
}
31153115

31163116
const ASTRecordLayout &
@@ -5891,11 +5891,11 @@ TypeSourceInfo *ASTContext::getTemplateSpecializationTypeInfo(
58915891
QualType TST = getTemplateSpecializationType(
58925892
Keyword, Name, SpecifiedArgs.arguments(), CanonicalArgs, Underlying);
58935893

5894-
TypeSourceInfo *DI = CreateTypeSourceInfo(TST);
5895-
DI->getTypeLoc().castAs<TemplateSpecializationTypeLoc>().set(
5894+
TypeSourceInfo *TSI = CreateTypeSourceInfo(TST);
5895+
TSI->getTypeLoc().castAs<TemplateSpecializationTypeLoc>().set(
58965896
ElaboratedKeywordLoc, QualifierLoc, TemplateKeywordLoc, NameLoc,
58975897
SpecifiedArgs);
5898-
return DI;
5898+
return TSI;
58995899
}
59005900

59015901
QualType ASTContext::getTemplateSpecializationType(

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,19 @@ template <class Emitter> class LocOverrideScope final {
208208
} // namespace interp
209209
} // namespace clang
210210

211+
template <class Emitter>
212+
bool Compiler<Emitter>::isValidBitCast(const CastExpr *E) {
213+
QualType FromTy = E->getSubExpr()->getType()->getPointeeType();
214+
QualType ToTy = E->getType()->getPointeeType();
215+
216+
if (classify(FromTy) == classify(ToTy))
217+
return true;
218+
219+
if (FromTy->isVoidType() || ToTy->isVoidType())
220+
return true;
221+
return false;
222+
}
223+
211224
template <class Emitter>
212225
bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
213226
const Expr *SubExpr = CE->getSubExpr();
@@ -476,8 +489,9 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
476489
return this->delegate(SubExpr);
477490

478491
case CK_BitCast: {
492+
QualType CETy = CE->getType();
479493
// Reject bitcasts to atomic types.
480-
if (CE->getType()->isAtomicType()) {
494+
if (CETy->isAtomicType()) {
481495
if (!this->discard(SubExpr))
482496
return false;
483497
return this->emitInvalidCast(CastKind::Reinterpret, /*Fatal=*/true, CE);
@@ -492,6 +506,10 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
492506
if (!FromT || !ToT)
493507
return false;
494508

509+
if (!this->isValidBitCast(CE) &&
510+
!this->emitInvalidCast(CastKind::ReinterpretLike, /*Fatal=*/false, CE))
511+
return false;
512+
495513
assert(isPtrType(*FromT));
496514
assert(isPtrType(*ToT));
497515
if (FromT == ToT) {

clang/lib/AST/ByteCode/Compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,
425425

426426
bool refersToUnion(const Expr *E);
427427

428+
bool isValidBitCast(const CastExpr *E);
429+
428430
protected:
429431
/// Variable to storage mapping.
430432
llvm::DenseMap<const ValueDecl *, Scope::Local> Locals;

clang/lib/AST/ByteCode/Interp.h

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,9 @@ bool Load(InterpState &S, CodePtr OpPC) {
19151915
return false;
19161916
if (!Ptr.isBlockPointer())
19171917
return false;
1918+
if (const Descriptor *D = Ptr.getFieldDesc();
1919+
!(D->isPrimitive() || D->isPrimitiveArray()) || D->getPrimType() != Name)
1920+
return false;
19181921
S.Stk.push<T>(Ptr.deref<T>());
19191922
return true;
19201923
}
@@ -1926,6 +1929,9 @@ bool LoadPop(InterpState &S, CodePtr OpPC) {
19261929
return false;
19271930
if (!Ptr.isBlockPointer())
19281931
return false;
1932+
if (const Descriptor *D = Ptr.getFieldDesc();
1933+
!(D->isPrimitive() || D->isPrimitiveArray()) || D->getPrimType() != Name)
1934+
return false;
19291935
S.Stk.push<T>(Ptr.deref<T>());
19301936
return true;
19311937
}
@@ -3288,12 +3294,18 @@ inline bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind,
32883294
bool Fatal) {
32893295
const SourceLocation &Loc = S.Current->getLocation(OpPC);
32903296

3291-
if (Kind == CastKind::Reinterpret) {
3297+
switch (Kind) {
3298+
case CastKind::Reinterpret:
32923299
S.CCEDiag(Loc, diag::note_constexpr_invalid_cast)
3293-
<< static_cast<unsigned>(Kind) << S.Current->getRange(OpPC);
3300+
<< diag::ConstexprInvalidCastKind::Reinterpret
3301+
<< S.Current->getRange(OpPC);
32943302
return !Fatal;
3295-
}
3296-
if (Kind == CastKind::Volatile) {
3303+
case CastKind::ReinterpretLike:
3304+
S.CCEDiag(Loc, diag::note_constexpr_invalid_cast)
3305+
<< diag::ConstexprInvalidCastKind::ThisConversionOrReinterpret
3306+
<< S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
3307+
return !Fatal;
3308+
case CastKind::Volatile:
32973309
if (!S.checkingPotentialConstantExpression()) {
32983310
const auto *E = cast<CastExpr>(S.Current->getExpr(OpPC));
32993311
if (S.getLangOpts().CPlusPlus)
@@ -3304,14 +3316,13 @@ inline bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind,
33043316
}
33053317

33063318
return false;
3307-
}
3308-
if (Kind == CastKind::Dynamic) {
3319+
case CastKind::Dynamic:
33093320
assert(!S.getLangOpts().CPlusPlus20);
3310-
S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_invalid_cast)
3321+
S.CCEDiag(Loc, diag::note_constexpr_invalid_cast)
33113322
<< diag::ConstexprInvalidCastKind::Dynamic;
33123323
return true;
33133324
}
3314-
3325+
llvm_unreachable("Unhandled CastKind");
33153326
return false;
33163327
}
33173328

clang/lib/AST/ByteCode/PrimType.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ inline constexpr bool isSignedType(PrimType T) {
101101

102102
enum class CastKind : uint8_t {
103103
Reinterpret,
104+
ReinterpretLike,
104105
Volatile,
105106
Dynamic,
106107
};
@@ -111,6 +112,9 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
111112
case interp::CastKind::Reinterpret:
112113
OS << "reinterpret_cast";
113114
break;
115+
case interp::CastKind::ReinterpretLike:
116+
OS << "reinterpret_like";
117+
break;
114118
case interp::CastKind::Volatile:
115119
OS << "volatile";
116120
break;

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,19 @@ unsigned Program::createGlobalString(const StringLiteral *S, const Expr *Base) {
3636
const size_t BitWidth = CharWidth * Ctx.getCharBit();
3737
unsigned StringLength = S->getLength();
3838

39-
PrimType CharType;
40-
switch (CharWidth) {
41-
case 1:
42-
CharType = PT_Sint8;
43-
break;
44-
case 2:
45-
CharType = PT_Uint16;
46-
break;
47-
case 4:
48-
CharType = PT_Uint32;
49-
break;
50-
default:
51-
llvm_unreachable("unsupported character width");
52-
}
39+
OptPrimType CharType =
40+
Ctx.classify(S->getType()->castAsArrayTypeUnsafe()->getElementType());
41+
assert(CharType);
5342

5443
if (!Base)
5544
Base = S;
5645

5746
// Create a descriptor for the string.
58-
Descriptor *Desc =
59-
allocateDescriptor(Base, CharType, Descriptor::GlobalMD, StringLength + 1,
60-
/*isConst=*/true,
61-
/*isTemporary=*/false,
62-
/*isMutable=*/false);
47+
Descriptor *Desc = allocateDescriptor(Base, *CharType, Descriptor::GlobalMD,
48+
StringLength + 1,
49+
/*isConst=*/true,
50+
/*isTemporary=*/false,
51+
/*isMutable=*/false);
6352

6453
// Allocate storage for the string.
6554
// The byte length does not include the null terminator.
@@ -79,26 +68,9 @@ unsigned Program::createGlobalString(const StringLiteral *S, const Expr *Base) {
7968
} else {
8069
// Construct the string in storage.
8170
for (unsigned I = 0; I <= StringLength; ++I) {
82-
const uint32_t CodePoint = I == StringLength ? 0 : S->getCodeUnit(I);
83-
switch (CharType) {
84-
case PT_Sint8: {
85-
using T = PrimConv<PT_Sint8>::T;
86-
Ptr.elem<T>(I) = T::from(CodePoint, BitWidth);
87-
break;
88-
}
89-
case PT_Uint16: {
90-
using T = PrimConv<PT_Uint16>::T;
91-
Ptr.elem<T>(I) = T::from(CodePoint, BitWidth);
92-
break;
93-
}
94-
case PT_Uint32: {
95-
using T = PrimConv<PT_Uint32>::T;
96-
Ptr.elem<T>(I) = T::from(CodePoint, BitWidth);
97-
break;
98-
}
99-
default:
100-
llvm_unreachable("unsupported character type");
101-
}
71+
uint32_t CodePoint = I == StringLength ? 0 : S->getCodeUnit(I);
72+
INT_TYPE_SWITCH_NO_BOOL(*CharType,
73+
Ptr.elem<T>(I) = T::from(CodePoint, BitWidth););
10274
}
10375
}
10476
Ptr.initializeAllElements();

clang/lib/Sema/SemaDeclObjC.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4730,13 +4730,13 @@ ParmVarDecl *SemaObjC::ActOnMethodParmDeclaration(Scope *S,
47304730
bool MethodDefinition) {
47314731
ASTContext &Context = getASTContext();
47324732
QualType ArgType;
4733-
TypeSourceInfo *DI;
4733+
TypeSourceInfo *TSI;
47344734

47354735
if (!ArgInfo.Type) {
47364736
ArgType = Context.getObjCIdType();
4737-
DI = nullptr;
4737+
TSI = nullptr;
47384738
} else {
4739-
ArgType = SemaRef.GetTypeFromParser(ArgInfo.Type, &DI);
4739+
ArgType = SemaRef.GetTypeFromParser(ArgInfo.Type, &TSI);
47404740
}
47414741
LookupResult R(SemaRef, ArgInfo.Name, ArgInfo.NameLoc,
47424742
Sema::LookupOrdinaryName,
@@ -4753,14 +4753,14 @@ ParmVarDecl *SemaObjC::ActOnMethodParmDeclaration(Scope *S,
47534753
}
47544754
}
47554755
SourceLocation StartLoc =
4756-
DI ? DI->getTypeLoc().getBeginLoc() : ArgInfo.NameLoc;
4756+
TSI ? TSI->getTypeLoc().getBeginLoc() : ArgInfo.NameLoc;
47574757

47584758
// Temporarily put parameter variables in the translation unit. This is what
47594759
// ActOnParamDeclarator does in the case of C arguments to the Objective-C
47604760
// method too.
47614761
ParmVarDecl *Param = SemaRef.CheckParameter(
47624762
Context.getTranslationUnitDecl(), StartLoc, ArgInfo.NameLoc, ArgInfo.Name,
4763-
ArgType, DI, SC_None);
4763+
ArgType, TSI, SC_None);
47644764
Param->setObjCMethodScopeInfo(ParamIndex);
47654765
Param->setObjCDeclQualifier(
47664766
CvtQTToAstBitMask(ArgInfo.DeclSpec.getObjCDeclQualifier()));

0 commit comments

Comments
 (0)