Skip to content

Commit 373ec78

Browse files
authored
merge main into amd-staging (llvm#993)
2 parents f05a17a + 46ffce8 commit 373ec78

File tree

216 files changed

+6926
-3982
lines changed

Some content is hidden

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

216 files changed

+6926
-3982
lines changed

clang-tools-extra/clangd/TidyProvider.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ TidyProvider disableUnusableChecks(llvm::ArrayRef<std::string> ExtraBadChecks) {
210210
// Check relies on seeing ifndef/define/endif directives,
211211
// clangd doesn't replay those when using a preamble.
212212
"-llvm-header-guard", "-modernize-macro-to-enum",
213+
"-cppcoreguidelines-macro-to-enum",
213214

214215
// ----- Crashing Checks -----
215216

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,21 @@ TEST(DiagnosticTest, ClangTidyNoLiteralDataInMacroToken) {
823823
EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre()); // no-crash
824824
}
825825

826+
TEST(DiagnosticTest, ClangTidyMacroToEnumCheck) {
827+
Annotations Main(R"cpp(
828+
#if 1
829+
auto foo();
830+
#endif
831+
)cpp");
832+
TestTU TU = TestTU::withCode(Main.code());
833+
std::vector<TidyProvider> Providers;
834+
Providers.push_back(
835+
addTidyChecks("cppcoreguidelines-macro-to-enum,modernize-macro-to-enum"));
836+
Providers.push_back(disableUnusableChecks());
837+
TU.ClangTidyProvider = combine(std::move(Providers));
838+
EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre()); // no-crash
839+
}
840+
826841
TEST(DiagnosticTest, ElseAfterReturnRange) {
827842
Annotations Main(R"cpp(
828843
int foo(int cond) {

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ Android Support
308308
Windows Support
309309
^^^^^^^^^^^^^^^
310310

311+
- Clang now supports MSVC vector deleting destructors (GH19772).
312+
311313
LoongArch Support
312314
^^^^^^^^^^^^^^^^^
313315

clang/include/clang/AST/VTableBuilder.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class VTableComponent {
150150

151151
bool isRTTIKind() const { return isRTTIKind(getKind()); }
152152

153-
GlobalDecl getGlobalDecl() const {
153+
GlobalDecl getGlobalDecl(bool HasVectorDeletingDtors) const {
154154
assert(isUsedFunctionPointerKind() &&
155155
"GlobalDecl can be created only from virtual function");
156156

@@ -161,7 +161,9 @@ class VTableComponent {
161161
case CK_CompleteDtorPointer:
162162
return GlobalDecl(DtorDecl, CXXDtorType::Dtor_Complete);
163163
case CK_DeletingDtorPointer:
164-
return GlobalDecl(DtorDecl, CXXDtorType::Dtor_Deleting);
164+
return GlobalDecl(DtorDecl, (HasVectorDeletingDtors)
165+
? CXXDtorType::Dtor_VectorDeleting
166+
: CXXDtorType::Dtor_Deleting);
165167
case CK_VCallOffset:
166168
case CK_VBaseOffset:
167169
case CK_OffsetToTop:

clang/include/clang/Basic/ABI.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ enum CXXCtorType {
3131

3232
/// C++ destructor types.
3333
enum CXXDtorType {
34-
Dtor_Deleting, ///< Deleting dtor
35-
Dtor_Complete, ///< Complete object dtor
36-
Dtor_Base, ///< Base object dtor
37-
Dtor_Comdat ///< The COMDAT used for dtors
34+
Dtor_Deleting, ///< Deleting dtor
35+
Dtor_Complete, ///< Complete object dtor
36+
Dtor_Base, ///< Base object dtor
37+
Dtor_Comdat, ///< The COMDAT used for dtors
38+
Dtor_VectorDeleting ///< Vector deleting dtor
3839
};
3940

4041
} // end namespace clang

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,6 +2843,8 @@ bool Compiler<Emitter>::VisitLambdaExpr(const LambdaExpr *E) {
28432843

28442844
assert(Initializing);
28452845
const Record *R = P.getOrCreateRecord(E->getLambdaClass());
2846+
if (!R)
2847+
return false;
28462848

28472849
auto *CaptureInitIt = E->capture_init_begin();
28482850
// Initialize all fields (which represent lambda captures) of the
@@ -4087,9 +4089,8 @@ bool Compiler<Emitter>::visitZeroRecordInitializer(const Record *R,
40874089
} else if (D->isRecord()) {
40884090
if (!this->visitZeroRecordInitializer(D->ElemRecord, E))
40894091
return false;
4090-
} else {
4091-
assert(false);
4092-
}
4092+
} else
4093+
return false;
40934094

40944095
if (!this->emitFinishInitPop(E))
40954096
return false;

clang/lib/AST/ByteCode/Descriptor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,10 @@ Descriptor::Descriptor(const DeclTy &D, const Record *R, MetadataSize MD,
404404
}
405405

406406
/// Dummy.
407-
Descriptor::Descriptor(const DeclTy &D)
408-
: Source(D), ElemSize(1), Size(1), MDSize(0), AllocSize(MDSize),
409-
ElemRecord(nullptr), IsConst(true), IsMutable(false), IsTemporary(false),
410-
IsDummy(true) {
407+
Descriptor::Descriptor(const DeclTy &D, MetadataSize MD)
408+
: Source(D), ElemSize(1), Size(1), MDSize(MD.value_or(0)),
409+
AllocSize(MDSize), ElemRecord(nullptr), IsConst(true), IsMutable(false),
410+
IsTemporary(false), IsDummy(true) {
411411
assert(Source && "Missing source");
412412
}
413413

clang/lib/AST/ByteCode/Descriptor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ struct Descriptor final {
200200
bool IsTemporary, bool IsMutable);
201201

202202
/// Allocates a dummy descriptor.
203-
Descriptor(const DeclTy &D);
203+
Descriptor(const DeclTy &D, MetadataSize MD = std::nullopt);
204204

205205
/// Make this descriptor a dummy descriptor.
206206
void makeDummy() { IsDummy = true; }
@@ -263,7 +263,7 @@ struct Descriptor final {
263263
bool isUnknownSizeArray() const { return Size == UnknownSizeMark; }
264264

265265
/// Checks if the descriptor is of a primitive.
266-
bool isPrimitive() const { return !IsArray && !ElemRecord; }
266+
bool isPrimitive() const { return !IsArray && !ElemRecord && !IsDummy; }
267267

268268
/// Checks if the descriptor is of an array.
269269
bool isArray() const { return IsArray; }

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,8 @@ bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
551551

552552
if (const auto *VD = Ptr.getDeclDesc()->asVarDecl();
553553
VD && (VD->isConstexpr() || VD->hasGlobalStorage())) {
554-
const SourceInfo &Loc = S.Current->getSource(OpPC);
555554
if (VD->getAnyInitializer()) {
555+
const SourceInfo &Loc = S.Current->getSource(OpPC);
556556
S.FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD;
557557
S.Note(VD->getLocation(), diag::note_declared_at);
558558
} else {
@@ -722,7 +722,6 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
722722
if (F->isLambdaStaticInvoker())
723723
return true;
724724

725-
const SourceLocation &Loc = S.Current->getLocation(OpPC);
726725
if (S.getLangOpts().CPlusPlus11) {
727726
const FunctionDecl *DiagDecl = F->getDecl();
728727

@@ -748,7 +747,8 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
748747
// or an inheriting constructor, we should be much more explicit about why
749748
// it's not constexpr.
750749
if (CD && CD->isInheritingConstructor()) {
751-
S.FFDiag(Loc, diag::note_constexpr_invalid_inhctor, 1)
750+
S.FFDiag(S.Current->getLocation(OpPC),
751+
diag::note_constexpr_invalid_inhctor, 1)
752752
<< CD->getInheritedConstructor().getConstructor()->getParent();
753753
S.Note(DiagDecl->getLocation(), diag::note_declared_at);
754754
} else {
@@ -766,7 +766,8 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
766766
DiagDecl->hasBody())
767767
return false;
768768

769-
S.FFDiag(Loc, diag::note_constexpr_invalid_function, 1)
769+
S.FFDiag(S.Current->getLocation(OpPC),
770+
diag::note_constexpr_invalid_function, 1)
770771
<< DiagDecl->isConstexpr() << (bool)CD << DiagDecl;
771772

772773
if (DiagDecl->getDefinition())
@@ -776,7 +777,8 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
776777
S.Note(DiagDecl->getLocation(), diag::note_declared_at);
777778
}
778779
} else {
779-
S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
780+
S.FFDiag(S.Current->getLocation(OpPC),
781+
diag::note_invalid_subexpr_in_const_expr);
780782
}
781783

782784
return false;
@@ -980,11 +982,6 @@ bool CheckNonNullArgs(InterpState &S, CodePtr OpPC, const Function *F,
980982
return true;
981983
}
982984

983-
// FIXME: This is similar to code we already have in Compiler.cpp.
984-
// I think it makes sense to instead add the field and base destruction stuff
985-
// to the destructor Function itself. Then destroying a record would really
986-
// _just_ be calling its destructor. That would also help with the diagnostic
987-
// difference when the destructor or a field/base fails.
988985
static bool runRecordDestructor(InterpState &S, CodePtr OpPC,
989986
const Pointer &BasePtr,
990987
const Descriptor *Desc) {
@@ -1095,8 +1092,8 @@ bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm,
10951092

10961093
// For a class type with a virtual destructor, the selected operator delete
10971094
// is the one looked up when building the destructor.
1098-
QualType AllocType = Ptr.getType();
10991095
if (!DeleteIsArrayForm && !IsGlobalDelete) {
1096+
QualType AllocType = Ptr.getType();
11001097
auto getVirtualOperatorDelete = [](QualType T) -> const FunctionDecl * {
11011098
if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl())
11021099
if (const CXXDestructorDecl *DD = RD->getDestructor())

clang/lib/AST/ByteCode/Interp.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,14 @@ inline bool CmpHelper<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
10061006
}
10071007
}
10081008

1009+
static inline bool IsOpaqueConstantCall(const CallExpr *E) {
1010+
unsigned Builtin = E->getBuiltinCallee();
1011+
return (Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
1012+
Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
1013+
Builtin == Builtin::BI__builtin_ptrauth_sign_constant ||
1014+
Builtin == Builtin::BI__builtin_function_start);
1015+
}
1016+
10091017
template <>
10101018
inline bool CmpHelperEQ<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
10111019
using BoolT = PrimConv<PT_Bool>::T;
@@ -1066,9 +1074,18 @@ inline bool CmpHelperEQ<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
10661074
if (P.isZero())
10671075
continue;
10681076
if (BothNonNull && P.pointsToLiteral()) {
1069-
const SourceInfo &Loc = S.Current->getSource(OpPC);
1070-
S.FFDiag(Loc, diag::note_constexpr_literal_comparison);
1071-
return false;
1077+
const Expr *E = P.getDeclDesc()->asExpr();
1078+
if (isa<StringLiteral>(E)) {
1079+
const SourceInfo &Loc = S.Current->getSource(OpPC);
1080+
S.FFDiag(Loc, diag::note_constexpr_literal_comparison);
1081+
return false;
1082+
} else if (const auto *CE = dyn_cast<CallExpr>(E);
1083+
CE && IsOpaqueConstantCall(CE)) {
1084+
const SourceInfo &Loc = S.Current->getSource(OpPC);
1085+
S.FFDiag(Loc, diag::note_constexpr_opaque_call_comparison)
1086+
<< P.toDiagnosticString(S.getASTContext());
1087+
return false;
1088+
}
10721089
}
10731090
}
10741091

0 commit comments

Comments
 (0)