Skip to content

Commit 4594d7c

Browse files
authored
Merge branch 'llvm:main' into OpenXiangShan/flang-new-generalizes-complex-division
2 parents ef7b572 + 045b827 commit 4594d7c

File tree

123 files changed

+2536
-792
lines changed

Some content is hidden

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

123 files changed

+2536
-792
lines changed

clang-tools-extra/clang-doc/BitcodeReader.cpp

Lines changed: 56 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -800,11 +800,39 @@ llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, T I) {
800800
}
801801
}
802802

803-
// TODO: Create a helper that can receive a function to reduce repetition for
804-
// most blocks.
803+
// TODO: fix inconsistentent returning of errors in add callbacks.
804+
// Once that's fixed, we only need one handleSubBlock.
805+
template <typename InfoType, typename T, typename Callback>
806+
llvm::Error ClangDocBitcodeReader::handleSubBlock(unsigned ID, T Parent,
807+
Callback Function) {
808+
InfoType Info;
809+
if (auto Err = readBlock(ID, &Info))
810+
return Err;
811+
Function(Parent, std::move(Info));
812+
return llvm::Error::success();
813+
}
814+
815+
template <typename InfoType, typename T, typename Callback>
816+
llvm::Error ClangDocBitcodeReader::handleTypeSubBlock(unsigned ID, T Parent,
817+
Callback Function) {
818+
InfoType Info;
819+
if (auto Err = readBlock(ID, &Info))
820+
return Err;
821+
if (auto Err = Function(Parent, std::move(Info)))
822+
return Err;
823+
return llvm::Error::success();
824+
}
825+
805826
template <typename T>
806827
llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) {
807828
llvm::TimeTraceScope("Reducing infos", "readSubBlock");
829+
830+
static auto CreateAddFunc = [](auto AddFunc) {
831+
return [AddFunc](auto Parent, auto Child) {
832+
return AddFunc(Parent, std::move(Child));
833+
};
834+
};
835+
808836
switch (ID) {
809837
// Blocks can only have certain types of sub blocks.
810838
case BI_COMMENT_BLOCK_ID: {
@@ -816,28 +844,16 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) {
816844
return llvm::Error::success();
817845
}
818846
case BI_TYPE_BLOCK_ID: {
819-
TypeInfo TI;
820-
if (auto Err = readBlock(ID, &TI))
821-
return Err;
822-
if (auto Err = addTypeInfo(I, std::move(TI)))
823-
return Err;
824-
return llvm::Error::success();
847+
return handleTypeSubBlock<TypeInfo>(
848+
ID, I, CreateAddFunc(addTypeInfo<T, TypeInfo>));
825849
}
826850
case BI_FIELD_TYPE_BLOCK_ID: {
827-
FieldTypeInfo TI;
828-
if (auto Err = readBlock(ID, &TI))
829-
return Err;
830-
if (auto Err = addTypeInfo(I, std::move(TI)))
831-
return Err;
832-
return llvm::Error::success();
851+
return handleTypeSubBlock<FieldTypeInfo>(
852+
ID, I, CreateAddFunc(addTypeInfo<T, FieldTypeInfo>));
833853
}
834854
case BI_MEMBER_TYPE_BLOCK_ID: {
835-
MemberTypeInfo TI;
836-
if (auto Err = readBlock(ID, &TI))
837-
return Err;
838-
if (auto Err = addTypeInfo(I, std::move(TI)))
839-
return Err;
840-
return llvm::Error::success();
855+
return handleTypeSubBlock<MemberTypeInfo>(
856+
ID, I, CreateAddFunc(addTypeInfo<T, MemberTypeInfo>));
841857
}
842858
case BI_REFERENCE_BLOCK_ID: {
843859
Reference R;
@@ -848,81 +864,46 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) {
848864
return llvm::Error::success();
849865
}
850866
case BI_FUNCTION_BLOCK_ID: {
851-
FunctionInfo F;
852-
if (auto Err = readBlock(ID, &F))
853-
return Err;
854-
addChild(I, std::move(F));
855-
return llvm::Error::success();
867+
return handleSubBlock<FunctionInfo>(
868+
ID, I, CreateAddFunc(addChild<T, FunctionInfo>));
856869
}
857870
case BI_BASE_RECORD_BLOCK_ID: {
858-
BaseRecordInfo BR;
859-
if (auto Err = readBlock(ID, &BR))
860-
return Err;
861-
addChild(I, std::move(BR));
862-
return llvm::Error::success();
871+
return handleSubBlock<BaseRecordInfo>(
872+
ID, I, CreateAddFunc(addChild<T, BaseRecordInfo>));
863873
}
864874
case BI_ENUM_BLOCK_ID: {
865-
EnumInfo E;
866-
if (auto Err = readBlock(ID, &E))
867-
return Err;
868-
addChild(I, std::move(E));
869-
return llvm::Error::success();
875+
return handleSubBlock<EnumInfo>(ID, I,
876+
CreateAddFunc(addChild<T, EnumInfo>));
870877
}
871878
case BI_ENUM_VALUE_BLOCK_ID: {
872-
EnumValueInfo EV;
873-
if (auto Err = readBlock(ID, &EV))
874-
return Err;
875-
addChild(I, std::move(EV));
876-
return llvm::Error::success();
879+
return handleSubBlock<EnumValueInfo>(
880+
ID, I, CreateAddFunc(addChild<T, EnumValueInfo>));
877881
}
878882
case BI_TEMPLATE_BLOCK_ID: {
879-
TemplateInfo TI;
880-
if (auto Err = readBlock(ID, &TI))
881-
return Err;
882-
addTemplate(I, std::move(TI));
883-
return llvm::Error::success();
883+
return handleSubBlock<TemplateInfo>(ID, I, CreateAddFunc(addTemplate<T>));
884884
}
885885
case BI_TEMPLATE_SPECIALIZATION_BLOCK_ID: {
886-
TemplateSpecializationInfo TSI;
887-
if (auto Err = readBlock(ID, &TSI))
888-
return Err;
889-
addTemplateSpecialization(I, std::move(TSI));
890-
return llvm::Error::success();
886+
return handleSubBlock<TemplateSpecializationInfo>(
887+
ID, I, CreateAddFunc(addTemplateSpecialization<T>));
891888
}
892889
case BI_TEMPLATE_PARAM_BLOCK_ID: {
893-
TemplateParamInfo TPI;
894-
if (auto Err = readBlock(ID, &TPI))
895-
return Err;
896-
addTemplateParam(I, std::move(TPI));
897-
return llvm::Error::success();
890+
return handleSubBlock<TemplateParamInfo>(
891+
ID, I, CreateAddFunc(addTemplateParam<T>));
898892
}
899893
case BI_TYPEDEF_BLOCK_ID: {
900-
TypedefInfo TI;
901-
if (auto Err = readBlock(ID, &TI))
902-
return Err;
903-
addChild(I, std::move(TI));
904-
return llvm::Error::success();
894+
return handleSubBlock<TypedefInfo>(ID, I,
895+
CreateAddFunc(addChild<T, TypedefInfo>));
905896
}
906897
case BI_CONSTRAINT_BLOCK_ID: {
907-
ConstraintInfo CI;
908-
if (auto Err = readBlock(ID, &CI))
909-
return Err;
910-
addConstraint(I, std::move(CI));
911-
return llvm::Error::success();
898+
return handleSubBlock<ConstraintInfo>(ID, I,
899+
CreateAddFunc(addConstraint<T>));
912900
}
913901
case BI_CONCEPT_BLOCK_ID: {
914-
ConceptInfo CI;
915-
if (auto Err = readBlock(ID, &CI))
916-
return Err;
917-
addChild(I, std::move(CI));
918-
return llvm::Error::success();
902+
return handleSubBlock<ConceptInfo>(ID, I,
903+
CreateAddFunc(addChild<T, ConceptInfo>));
919904
}
920905
case BI_VAR_BLOCK_ID: {
921-
VarInfo VI;
922-
if (auto Err = readBlock(ID, &VI))
923-
return Err;
924-
addChild(I, std::move(VI));
925-
return llvm::Error::success();
906+
return handleSubBlock<VarInfo>(ID, I, CreateAddFunc(addChild<T, VarInfo>));
926907
}
927908
default:
928909
return llvm::createStringError(llvm::inconvertibleErrorCode(),

clang-tools-extra/clang-doc/BitcodeReader.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ class ClangDocBitcodeReader {
6464
// Helper function to set up the appropriate type of Info.
6565
llvm::Expected<std::unique_ptr<Info>> readBlockToInfo(unsigned ID);
6666

67+
template <typename InfoType, typename T, typename CallbackFunction>
68+
llvm::Error handleSubBlock(unsigned ID, T Parent, CallbackFunction Function);
69+
70+
template <typename InfoType, typename T, typename CallbackFunction>
71+
llvm::Error handleTypeSubBlock(unsigned ID, T Parent,
72+
CallbackFunction Function);
73+
6774
llvm::BitstreamCursor &Stream;
6875
std::optional<llvm::BitstreamBlockInfo> BlockInfo;
6976
FieldId CurrentReferenceField;

clang/lib/APINotes/APINotesWriter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,10 +1118,9 @@ void emitFunctionInfo(raw_ostream &OS, const FunctionInfo &FI) {
11181118
emitParamInfo(OS, PI);
11191119

11201120
writer.write<uint16_t>(FI.ResultType.size());
1121-
writer.write(ArrayRef<char>{FI.ResultType.data(), FI.ResultType.size()});
1121+
writer.write(ArrayRef<char>{FI.ResultType});
11221122
writer.write<uint16_t>(FI.SwiftReturnOwnership.size());
1123-
writer.write(ArrayRef<char>{FI.SwiftReturnOwnership.data(),
1124-
FI.SwiftReturnOwnership.size()});
1123+
writer.write(ArrayRef<char>{FI.SwiftReturnOwnership});
11251124
}
11261125

11271126
/// Used to serialize the on-disk global function table.

clang/lib/AST/ASTImporter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ ASTNodeImporter::VisitCountAttributedType(const CountAttributedType *T) {
16051605

16061606
return Importer.getToContext().getCountAttributedType(
16071607
*ToWrappedTypeOrErr, CountExpr, T->isCountInBytes(), T->isOrNull(),
1608-
ArrayRef(CoupledDecls.data(), CoupledDecls.size()));
1608+
ArrayRef(CoupledDecls));
16091609
}
16101610

16111611
ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
@@ -6337,8 +6337,8 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl(
63376337

63386338
if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
63396339
D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6340-
*IdLocOrErr, ToTPList, ClassTemplate,
6341-
ArrayRef(TemplateArgs.data(), TemplateArgs.size()), CanonInjType,
6340+
*IdLocOrErr, ToTPList, ClassTemplate, ArrayRef(TemplateArgs),
6341+
CanonInjType,
63426342
cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
63436343
return D2;
63446344

clang/lib/AST/DeclBase.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,8 @@ bool Decl::isInExportDeclContext() const {
11331133
}
11341134

11351135
bool Decl::isModuleLocal() const {
1136+
if (isa<NamespaceDecl, TranslationUnitDecl>(this))
1137+
return false;
11361138
auto *M = getOwningModule();
11371139
return M && M->isNamedModule() &&
11381140
getModuleOwnershipKind() == ModuleOwnershipKind::ReachableWhenImported;

clang/lib/Driver/OffloadBundler.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,7 @@ class ObjectFileHandler final : public FileHandler {
744744
// Input is the same as the content of the original input file, therefore
745745
// temporary file is not needed.
746746
if (StringRef(BundlerConfig.FilesType).starts_with("a")) {
747-
auto InputFileOrErr =
748-
TempFiles.Create(ArrayRef<char>(Input.data(), Input.size()));
747+
auto InputFileOrErr = TempFiles.Create(ArrayRef<char>(Input));
749748
if (!InputFileOrErr)
750749
return InputFileOrErr.takeError();
751750
ObjcopyInputFileName = *InputFileOrErr;
@@ -1289,8 +1288,7 @@ CompressedOffloadBundle::decompress(const llvm::MemoryBuffer &Input,
12891288
HashRecalcTimer.startTimer();
12901289
llvm::MD5 Hash;
12911290
llvm::MD5::MD5Result Result;
1292-
Hash.update(llvm::ArrayRef<uint8_t>(DecompressedData.data(),
1293-
DecompressedData.size()));
1291+
Hash.update(llvm::ArrayRef<uint8_t>(DecompressedData));
12941292
Hash.final(Result);
12951293
uint64_t RecalculatedHash = Result.low();
12961294
HashRecalcTimer.stopTimer();

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16427,9 +16427,8 @@ bool Sema::CompleteConstructorCall(CXXConstructorDecl *Constructor,
1642716427

1642816428
DiagnoseSentinelCalls(Constructor, Loc, AllArgs);
1642916429

16430-
CheckConstructorCall(Constructor, DeclInitType,
16431-
llvm::ArrayRef(AllArgs.data(), AllArgs.size()), Proto,
16432-
Loc);
16430+
CheckConstructorCall(Constructor, DeclInitType, llvm::ArrayRef(AllArgs),
16431+
Proto, Loc);
1643316432

1643416433
return Invalid;
1643516434
}

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,9 +1773,9 @@ Sema::ActOnTemplateParameterList(unsigned Depth,
17731773
for (NamedDecl *P : Params)
17741774
warnOnReservedIdentifier(P);
17751775

1776-
return TemplateParameterList::Create(
1777-
Context, TemplateLoc, LAngleLoc,
1778-
llvm::ArrayRef(Params.data(), Params.size()), RAngleLoc, RequiresClause);
1776+
return TemplateParameterList::Create(Context, TemplateLoc, LAngleLoc,
1777+
llvm::ArrayRef(Params), RAngleLoc,
1778+
RequiresClause);
17791779
}
17801780

17811781
static void SetNestedNameSpecifier(Sema &S, TagDecl *T,

clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
// Depends on NewDeleteChecker.
3535
//
3636
// * MismatchedDeallocatorChecker
37-
// Enables checking whether memory is deallocated with the correspending
37+
// Enables checking whether memory is deallocated with the corresponding
3838
// allocation function in MallocChecker, such as malloc() allocated
3939
// regions are only freed by free(), new by delete, new[] by delete[].
4040
//
@@ -1372,8 +1372,8 @@ void MallocChecker::checkIfFreeNameIndex(ProgramStateRef State,
13721372
C.addTransition(State);
13731373
}
13741374

1375-
const Expr *getPlacementNewBufferArg(const CallExpr *CE,
1376-
const FunctionDecl *FD) {
1375+
static const Expr *getPlacementNewBufferArg(const CallExpr *CE,
1376+
const FunctionDecl *FD) {
13771377
// Checking for signature:
13781378
// void* operator new ( std::size_t count, void* ptr );
13791379
// void* operator new[]( std::size_t count, void* ptr );
@@ -1682,17 +1682,15 @@ ProgramStateRef MallocChecker::ProcessZeroAllocCheck(
16821682
const RefState *RS = State->get<RegionState>(Sym);
16831683
if (RS) {
16841684
if (RS->isAllocated())
1685-
return TrueState->set<RegionState>(Sym,
1686-
RefState::getAllocatedOfSizeZero(RS));
1687-
else
1688-
return State;
1689-
} else {
1690-
// Case of zero-size realloc. Historically 'realloc(ptr, 0)' is treated as
1691-
// 'free(ptr)' and the returned value from 'realloc(ptr, 0)' is not
1692-
// tracked. Add zero-reallocated Sym to the state to catch references
1693-
// to zero-allocated memory.
1694-
return TrueState->add<ReallocSizeZeroSymbols>(Sym);
1685+
return TrueState->set<RegionState>(
1686+
Sym, RefState::getAllocatedOfSizeZero(RS));
1687+
return State;
16951688
}
1689+
// Case of zero-size realloc. Historically 'realloc(ptr, 0)' is treated as
1690+
// 'free(ptr)' and the returned value from 'realloc(ptr, 0)' is not
1691+
// tracked. Add zero-reallocated Sym to the state to catch references
1692+
// to zero-allocated memory.
1693+
return TrueState->add<ReallocSizeZeroSymbols>(Sym);
16961694
}
16971695

16981696
// Assume the value is non-zero going forward.
@@ -1890,7 +1888,7 @@ void MallocChecker::reportTaintBug(StringRef Msg, ProgramStateRef State,
18901888
"Tainted Memory Allocation",
18911889
categories::TaintedData));
18921890
auto R = std::make_unique<PathSensitiveBugReport>(*BT_TaintedAlloc, Msg, N);
1893-
for (auto TaintedSym : TaintedSyms) {
1891+
for (const auto *TaintedSym : TaintedSyms) {
18941892
R->markInteresting(TaintedSym);
18951893
}
18961894
C.emitReport(std::move(R));
@@ -2277,11 +2275,12 @@ MallocChecker::FreeMemAux(CheckerContext &C, const Expr *ArgExpr,
22772275
HandleDoubleFree(C, ParentExpr->getSourceRange(), RsBase->isReleased(),
22782276
SymBase, PreviousRetStatusSymbol);
22792277
return nullptr;
2278+
}
22802279

22812280
// If the pointer is allocated or escaped, but we are now trying to free it,
22822281
// check that the call to free is proper.
2283-
} else if (RsBase->isAllocated() || RsBase->isAllocatedOfSizeZero() ||
2284-
RsBase->isEscaped()) {
2282+
if (RsBase->isAllocated() || RsBase->isAllocatedOfSizeZero() ||
2283+
RsBase->isEscaped()) {
22852284

22862285
// Check if an expected deallocation function matches the real one.
22872286
bool DeallocMatchesAlloc = RsBase->getAllocationFamily() == Family;
@@ -2857,9 +2856,7 @@ MallocChecker::ReallocMemAux(CheckerContext &C, const CallEvent &Call,
28572856

28582857
const CallExpr *CE = cast<CallExpr>(Call.getOriginExpr());
28592858

2860-
if (SuffixWithN && CE->getNumArgs() < 3)
2861-
return nullptr;
2862-
else if (CE->getNumArgs() < 2)
2859+
if ((SuffixWithN && CE->getNumArgs() < 3) || CE->getNumArgs() < 2)
28632860
return nullptr;
28642861

28652862
const Expr *arg0Expr = CE->getArg(0);

0 commit comments

Comments
 (0)