Skip to content

Commit a02774c

Browse files
committed
merge main into amd-staging
2 parents fccbf21 + dec214d commit a02774c

File tree

94 files changed

+1413
-447
lines changed

Some content is hidden

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

94 files changed

+1413
-447
lines changed

clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ static void cleanInitialValue(DiagnosticBuilder &Diag,
7070
return;
7171
Diag << FixItHint::CreateRemoval(EqualLoc)
7272
<< FixItHint::CreateRemoval(InitExprRange);
73-
return;
7473
}
7574

7675
namespace {

clang-tools-extra/clangd/unittests/ProjectAwareIndexTests.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ TEST(ProjectAware, Test) {
4949
C.Index.External.Location = "test";
5050
WithContextValue With(Config::Key, std::move(C));
5151
EXPECT_THAT(match(*Idx, Req), ElementsAre("1"));
52-
return;
5352
}
5453

5554
TEST(ProjectAware, CreatedOnce) {
@@ -80,7 +79,6 @@ TEST(ProjectAware, CreatedOnce) {
8079
match(*Idx, Req);
8180
// It is cached afterwards.
8281
EXPECT_EQ(InvocationCount, 1U);
83-
return;
8482
}
8583
} // namespace clangd
8684
} // namespace clang

clang/include/clang/AST/Type.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8583,8 +8583,7 @@ bool IsEnumDeclScoped(EnumDecl *);
85838583

85848584
inline bool Type::isIntegerType() const {
85858585
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
8586-
return BT->getKind() >= BuiltinType::Bool &&
8587-
BT->getKind() <= BuiltinType::Int128;
8586+
return BT->isInteger();
85888587
if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
85898588
// Incomplete enum types are not treated as integer types.
85908589
// FIXME: In C++, enum types are never integer types.
@@ -8658,8 +8657,7 @@ inline bool Type::isScalarType() const {
86588657

86598658
inline bool Type::isIntegralOrEnumerationType() const {
86608659
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
8661-
return BT->getKind() >= BuiltinType::Bool &&
8662-
BT->getKind() <= BuiltinType::Int128;
8660+
return BT->isInteger();
86638661

86648662
// Check for a complete enum type; incomplete enum types are not properly an
86658663
// enumeration type in the sense required here.

clang/lib/AST/ByteCode/Context.cpp

Lines changed: 84 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
using namespace clang;
2222
using namespace clang::interp;
2323

24-
Context::Context(ASTContext &Ctx) : Ctx(Ctx), P(new Program(*this)) {}
24+
Context::Context(ASTContext &Ctx) : Ctx(Ctx), P(new Program(*this)) {
25+
this->IntWidth = Ctx.getTargetInfo().getIntWidth();
26+
this->LongWidth = Ctx.getTargetInfo().getLongWidth();
27+
assert(Ctx.getTargetInfo().getCharWidth() == 8 &&
28+
"We're assuming 8 bit chars");
29+
}
2530

2631
Context::~Context() {}
2732

@@ -216,65 +221,100 @@ bool Context::evaluateCharRange(State &Parent, const Expr *SizeExpr,
216221

217222
const LangOptions &Context::getLangOpts() const { return Ctx.getLangOpts(); }
218223

219-
std::optional<PrimType> Context::classify(QualType T) const {
220-
if (T->isBooleanType())
221-
return PT_Bool;
222-
223-
if (T->isSignedIntegerOrEnumerationType()) {
224-
switch (Ctx.getIntWidth(T)) {
225-
case 64:
226-
return PT_Sint64;
227-
case 32:
228-
return PT_Sint32;
229-
case 16:
230-
return PT_Sint16;
231-
case 8:
232-
return PT_Sint8;
233-
default:
234-
return PT_IntAPS;
235-
}
224+
static PrimType integralTypeToPrimTypeS(unsigned BitWidth) {
225+
switch (BitWidth) {
226+
case 64:
227+
return PT_Sint64;
228+
case 32:
229+
return PT_Sint32;
230+
case 16:
231+
return PT_Sint16;
232+
case 8:
233+
return PT_Sint8;
234+
default:
235+
return PT_IntAPS;
236236
}
237+
llvm_unreachable("Unhandled BitWidth");
238+
}
239+
240+
static PrimType integralTypeToPrimTypeU(unsigned BitWidth) {
241+
switch (BitWidth) {
242+
case 64:
243+
return PT_Uint64;
244+
case 32:
245+
return PT_Uint32;
246+
case 16:
247+
return PT_Uint16;
248+
case 8:
249+
return PT_Uint8;
250+
default:
251+
return PT_IntAP;
252+
}
253+
llvm_unreachable("Unhandled BitWidth");
254+
}
255+
256+
std::optional<PrimType> Context::classify(QualType T) const {
237257

238-
if (T->isUnsignedIntegerOrEnumerationType()) {
239-
switch (Ctx.getIntWidth(T)) {
240-
case 64:
241-
return PT_Uint64;
242-
case 32:
243-
return PT_Uint32;
244-
case 16:
245-
return PT_Uint16;
246-
case 8:
247-
return PT_Uint8;
248-
case 1:
249-
// Might happen for enum types.
258+
if (const auto *BT = dyn_cast<BuiltinType>(T.getCanonicalType())) {
259+
auto Kind = BT->getKind();
260+
if (Kind == BuiltinType::Bool)
250261
return PT_Bool;
251-
default:
252-
return PT_IntAP;
253-
}
262+
if (Kind == BuiltinType::NullPtr)
263+
return PT_Ptr;
264+
if (Kind == BuiltinType::BoundMember)
265+
return PT_MemberPtr;
266+
267+
// Just trying to avoid the ASTContext::getIntWidth call below.
268+
if (Kind == BuiltinType::Int)
269+
return integralTypeToPrimTypeS(this->IntWidth);
270+
if (Kind == BuiltinType::UInt)
271+
return integralTypeToPrimTypeU(this->IntWidth);
272+
if (Kind == BuiltinType::Long)
273+
return integralTypeToPrimTypeS(this->LongWidth);
274+
if (Kind == BuiltinType::ULong)
275+
return integralTypeToPrimTypeU(this->LongWidth);
276+
if (Kind == BuiltinType::SChar || Kind == BuiltinType::Char_S)
277+
return integralTypeToPrimTypeS(8);
278+
if (Kind == BuiltinType::UChar || Kind == BuiltinType::Char_U ||
279+
Kind == BuiltinType::Char8)
280+
return integralTypeToPrimTypeU(8);
281+
282+
if (BT->isSignedInteger())
283+
return integralTypeToPrimTypeS(Ctx.getIntWidth(T));
284+
if (BT->isUnsignedInteger())
285+
return integralTypeToPrimTypeU(Ctx.getIntWidth(T));
286+
287+
if (BT->isFloatingPoint())
288+
return PT_Float;
254289
}
255290

256-
if (T->isNullPtrType())
291+
if (T->isPointerOrReferenceType())
257292
return PT_Ptr;
258293

259-
if (T->isRealFloatingType())
260-
return PT_Float;
294+
if (T->isMemberPointerType())
295+
return PT_MemberPtr;
261296

262-
if (T->isFunctionPointerType() || T->isFunctionReferenceType() ||
263-
T->isFunctionType() || T->isBlockPointerType())
264-
return PT_Ptr;
297+
if (const auto *BT = T->getAs<BitIntType>()) {
298+
if (BT->isSigned())
299+
return integralTypeToPrimTypeS(BT->getNumBits());
300+
return integralTypeToPrimTypeU(BT->getNumBits());
301+
}
265302

266-
if (T->isPointerOrReferenceType() || T->isObjCObjectPointerType())
267-
return PT_Ptr;
303+
if (const auto *ET = T->getAs<EnumType>()) {
304+
const auto *D = ET->getDecl();
305+
if (!D->isComplete())
306+
return std::nullopt;
307+
return classify(D->getIntegerType());
308+
}
268309

269310
if (const auto *AT = T->getAs<AtomicType>())
270311
return classify(AT->getValueType());
271312

272313
if (const auto *DT = dyn_cast<DecltypeType>(T))
273314
return classify(DT->getUnderlyingType());
274315

275-
if (T->isSpecificBuiltinType(BuiltinType::BoundMember) ||
276-
T->isMemberPointerType())
277-
return PT_MemberPtr;
316+
if (T->isObjCObjectPointerType() || T->isBlockPointerType())
317+
return PT_Ptr;
278318

279319
if (T->isFixedPointType())
280320
return PT_FixedPoint;

clang/lib/AST/ByteCode/Context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ class Context final {
137137
std::unique_ptr<Program> P;
138138
/// ID identifying an evaluation.
139139
unsigned EvalID = 0;
140+
/// Cached widths (in bits) of common types, for a faster classify().
141+
unsigned IntWidth;
142+
unsigned LongWidth;
140143
};
141144

142145
} // namespace interp

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,38 @@ unsigned Program::createGlobalString(const StringLiteral *S, const Expr *Base) {
6868
/*isExtern=*/false);
6969
G->block()->invokeCtor();
7070

71-
new (G->block()->rawData()) InlineDescriptor(Desc);
71+
new (G->block()->rawData())
72+
GlobalInlineDescriptor{GlobalInitState::Initialized};
7273
Globals.push_back(G);
7374

74-
// Construct the string in storage.
7575
const Pointer Ptr(G->block());
76-
for (unsigned I = 0; I <= StringLength; ++I) {
77-
Pointer Field = Ptr.atIndex(I);
78-
const uint32_t CodePoint = I == StringLength ? 0 : S->getCodeUnit(I);
79-
switch (CharType) {
80-
case PT_Sint8: {
81-
using T = PrimConv<PT_Sint8>::T;
82-
Field.deref<T>() = T::from(CodePoint, BitWidth);
83-
break;
84-
}
85-
case PT_Uint16: {
86-
using T = PrimConv<PT_Uint16>::T;
87-
Field.deref<T>() = T::from(CodePoint, BitWidth);
88-
break;
89-
}
90-
case PT_Uint32: {
91-
using T = PrimConv<PT_Uint32>::T;
92-
Field.deref<T>() = T::from(CodePoint, BitWidth);
93-
break;
94-
}
95-
default:
96-
llvm_unreachable("unsupported character type");
76+
if (CharWidth == 1) {
77+
std::memcpy(&Ptr.atIndex(0).deref<char>(), S->getString().data(),
78+
StringLength);
79+
} else {
80+
// Construct the string in storage.
81+
for (unsigned I = 0; I <= StringLength; ++I) {
82+
Pointer Field = Ptr.atIndex(I);
83+
const uint32_t CodePoint = I == StringLength ? 0 : S->getCodeUnit(I);
84+
switch (CharType) {
85+
case PT_Sint8: {
86+
using T = PrimConv<PT_Sint8>::T;
87+
Field.deref<T>() = T::from(CodePoint, BitWidth);
88+
break;
89+
}
90+
case PT_Uint16: {
91+
using T = PrimConv<PT_Uint16>::T;
92+
Field.deref<T>() = T::from(CodePoint, BitWidth);
93+
break;
94+
}
95+
case PT_Uint32: {
96+
using T = PrimConv<PT_Uint32>::T;
97+
Field.deref<T>() = T::from(CodePoint, BitWidth);
98+
break;
99+
}
100+
default:
101+
llvm_unreachable("unsupported character type");
102+
}
97103
}
98104
}
99105
Ptr.initialize();

clang/lib/AST/Type.cpp

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,8 +2108,7 @@ bool Type::hasIntegerRepresentation() const {
21082108
/// \returns true if the type is considered an integral type, false otherwise.
21092109
bool Type::isIntegralType(const ASTContext &Ctx) const {
21102110
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2111-
return BT->getKind() >= BuiltinType::Bool &&
2112-
BT->getKind() <= BuiltinType::Int128;
2111+
return BT->isInteger();
21132112

21142113
// Complete enum types are integral in C.
21152114
if (!Ctx.getLangOpts().CPlusPlus)
@@ -2121,8 +2120,7 @@ bool Type::isIntegralType(const ASTContext &Ctx) const {
21212120

21222121
bool Type::isIntegralOrUnscopedEnumerationType() const {
21232122
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2124-
return BT->getKind() >= BuiltinType::Bool &&
2125-
BT->getKind() <= BuiltinType::Int128;
2123+
return BT->isInteger();
21262124

21272125
if (isBitIntType())
21282126
return true;
@@ -2211,10 +2209,8 @@ bool Type::isUnicodeCharacterType() const {
22112209
/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
22122210
/// an enum decl which has a signed representation
22132211
bool Type::isSignedIntegerType() const {
2214-
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2215-
return BT->getKind() >= BuiltinType::Char_S &&
2216-
BT->getKind() <= BuiltinType::Int128;
2217-
}
2212+
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2213+
return BT->isSignedInteger();
22182214

22192215
if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
22202216
// Incomplete enum types are not treated as integer types.
@@ -2232,15 +2228,12 @@ bool Type::isSignedIntegerType() const {
22322228
}
22332229

22342230
bool Type::isSignedIntegerOrEnumerationType() const {
2235-
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2236-
return BT->getKind() >= BuiltinType::Char_S &&
2237-
BT->getKind() <= BuiltinType::Int128;
2238-
}
2231+
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2232+
return BT->isSignedInteger();
22392233

2240-
if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
2241-
if (ET->getDecl()->isComplete())
2242-
return ET->getDecl()->getIntegerType()->isSignedIntegerType();
2243-
}
2234+
if (const auto *ET = dyn_cast<EnumType>(CanonicalType);
2235+
ET && ET->getDecl()->isComplete())
2236+
return ET->getDecl()->getIntegerType()->isSignedIntegerType();
22442237

22452238
if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
22462239
return IT->isSigned();
@@ -2261,10 +2254,8 @@ bool Type::hasSignedIntegerRepresentation() const {
22612254
/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
22622255
/// decl which has an unsigned representation
22632256
bool Type::isUnsignedIntegerType() const {
2264-
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2265-
return BT->getKind() >= BuiltinType::Bool &&
2266-
BT->getKind() <= BuiltinType::UInt128;
2267-
}
2257+
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2258+
return BT->isUnsignedInteger();
22682259

22692260
if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
22702261
// Incomplete enum types are not treated as integer types.
@@ -2282,15 +2273,12 @@ bool Type::isUnsignedIntegerType() const {
22822273
}
22832274

22842275
bool Type::isUnsignedIntegerOrEnumerationType() const {
2285-
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2286-
return BT->getKind() >= BuiltinType::Bool &&
2287-
BT->getKind() <= BuiltinType::UInt128;
2288-
}
2276+
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2277+
return BT->isUnsignedInteger();
22892278

2290-
if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
2291-
if (ET->getDecl()->isComplete())
2292-
return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
2293-
}
2279+
if (const auto *ET = dyn_cast<EnumType>(CanonicalType);
2280+
ET && ET->getDecl()->isComplete())
2281+
return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
22942282

22952283
if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
22962284
return IT->isUnsigned();

clang/lib/Sema/SemaExpr.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17844,15 +17844,13 @@ void Sema::PushExpressionEvaluationContextForFunction(
1784417844
Current.InImmediateEscalatingFunctionContext =
1784517845
getLangOpts().CPlusPlus20 && FD->isImmediateEscalating();
1784617846

17847-
if (isLambdaMethod(FD)) {
17848-
Current.InDiscardedStatement = Parent.isDiscardedStatementContext();
17847+
if (isLambdaMethod(FD))
1784917848
Current.InImmediateFunctionContext =
1785017849
FD->isConsteval() ||
1785117850
(isLambdaMethod(FD) && (Parent.isConstantEvaluated() ||
1785217851
Parent.isImmediateFunctionContext()));
17853-
} else {
17852+
else
1785417853
Current.InImmediateFunctionContext = FD->isConsteval();
17855-
}
1785617854
}
1785717855
}
1785817856

clang/lib/StaticAnalyzer/Core/CoreEngine.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h"
15+
#include "PrettyStackTraceLocationContext.h"
1516
#include "clang/AST/Expr.h"
1617
#include "clang/AST/ExprCXX.h"
1718
#include "clang/AST/Stmt.h"
@@ -216,6 +217,7 @@ void CoreEngine::dispatchWorkItem(ExplodedNode *Pred, ProgramPoint Loc,
216217
llvm::TimeTraceScope tcs{timeTraceScopeName(Loc), [Loc, Pred]() {
217218
return timeTraceMetadata(Pred, Loc);
218219
}};
220+
PrettyStackTraceLocationContext CrashInfo(Pred->getLocationContext());
219221
// Dispatch on the location type.
220222
switch (Loc.getKind()) {
221223
case ProgramPoint::BlockEdgeKind:

0 commit comments

Comments
 (0)