diff options
Diffstat (limited to 'clang-tools-extra')
33 files changed, 166 insertions, 129 deletions
diff --git a/clang-tools-extra/clang-doc/Generators.cpp b/clang-tools-extra/clang-doc/Generators.cpp index 3fb5b63..a5f6f1c 100644 --- a/clang-tools-extra/clang-doc/Generators.cpp +++ b/clang-tools-extra/clang-doc/Generators.cpp @@ -97,15 +97,11 @@ void Generator::addInfoToIndex(Index &Idx, const doc::Info *Info) { // This anchor is used to force the linker to link in the generated object file // and thus register the generators. -static int LLVM_ATTRIBUTE_UNUSED YAMLGeneratorAnchorDest = - YAMLGeneratorAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED MDGeneratorAnchorDest = - MDGeneratorAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED HTMLGeneratorAnchorDest = - HTMLGeneratorAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED MHTMLGeneratorAnchorDest = +[[maybe_unused]] static int YAMLGeneratorAnchorDest = YAMLGeneratorAnchorSource; +[[maybe_unused]] static int MDGeneratorAnchorDest = MDGeneratorAnchorSource; +[[maybe_unused]] static int HTMLGeneratorAnchorDest = HTMLGeneratorAnchorSource; +[[maybe_unused]] static int MHTMLGeneratorAnchorDest = MHTMLGeneratorAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED JSONGeneratorAnchorDest = - JSONGeneratorAnchorSource; +[[maybe_unused]] static int JSONGeneratorAnchorDest = JSONGeneratorAnchorSource; } // namespace doc } // namespace clang diff --git a/clang-tools-extra/clang-tidy/.clang-format b/clang-tools-extra/clang-tidy/.clang-format index d18cf7c..5b50661 100644 --- a/clang-tools-extra/clang-tidy/.clang-format +++ b/clang-tools-extra/clang-tidy/.clang-format @@ -1,2 +1,3 @@ BasedOnStyle: LLVM QualifierAlignment: Left +LineEnding: LF diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h index cdf6ce2..afc358a 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h +++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h @@ -16,132 +16,131 @@ namespace clang::tidy { // This anchor is used to force the linker to link the AbseilModule. extern volatile int AbseilModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED AbseilModuleAnchorDestination = +[[maybe_unused]] static int AbseilModuleAnchorDestination = AbseilModuleAnchorSource; // This anchor is used to force the linker to link the AlteraModule. extern volatile int AlteraModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED AlteraModuleAnchorDestination = +[[maybe_unused]] static int AlteraModuleAnchorDestination = AlteraModuleAnchorSource; // This anchor is used to force the linker to link the AndroidModule. extern volatile int AndroidModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED AndroidModuleAnchorDestination = +[[maybe_unused]] static int AndroidModuleAnchorDestination = AndroidModuleAnchorSource; // This anchor is used to force the linker to link the BoostModule. extern volatile int BoostModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination = +[[maybe_unused]] static int BoostModuleAnchorDestination = BoostModuleAnchorSource; // This anchor is used to force the linker to link the BugproneModule. extern volatile int BugproneModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED BugproneModuleAnchorDestination = +[[maybe_unused]] static int BugproneModuleAnchorDestination = BugproneModuleAnchorSource; // This anchor is used to force the linker to link the CERTModule. extern volatile int CERTModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination = +[[maybe_unused]] static int CERTModuleAnchorDestination = CERTModuleAnchorSource; // This anchor is used to force the linker to link the ConcurrencyModule. extern volatile int ConcurrencyModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED ConcurrencyModuleAnchorDestination = +[[maybe_unused]] static int ConcurrencyModuleAnchorDestination = ConcurrencyModuleAnchorSource; // This anchor is used to force the linker to link the CppCoreGuidelinesModule. extern volatile int CppCoreGuidelinesModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination = +[[maybe_unused]] static int CppCoreGuidelinesModuleAnchorDestination = CppCoreGuidelinesModuleAnchorSource; #if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS // This anchor is used to force the linker to link the CustomModule. extern volatile int CustomModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED CustomModuleAnchorDestination = +[[maybe_unused]] static int CustomModuleAnchorDestination = CustomModuleAnchorSource; #endif // This anchor is used to force the linker to link the DarwinModule. extern volatile int DarwinModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED DarwinModuleAnchorDestination = +[[maybe_unused]] static int DarwinModuleAnchorDestination = DarwinModuleAnchorSource; // This anchor is used to force the linker to link the FuchsiaModule. extern volatile int FuchsiaModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED FuchsiaModuleAnchorDestination = +[[maybe_unused]] static int FuchsiaModuleAnchorDestination = FuchsiaModuleAnchorSource; // This anchor is used to force the linker to link the GoogleModule. extern volatile int GoogleModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED GoogleModuleAnchorDestination = +[[maybe_unused]] static int GoogleModuleAnchorDestination = GoogleModuleAnchorSource; // This anchor is used to force the linker to link the HICPPModule. extern volatile int HICPPModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED HICPPModuleAnchorDestination = +[[maybe_unused]] static int HICPPModuleAnchorDestination = HICPPModuleAnchorSource; // This anchor is used to force the linker to link the LinuxKernelModule. extern volatile int LinuxKernelModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED LinuxKernelModuleAnchorDestination = +[[maybe_unused]] static int LinuxKernelModuleAnchorDestination = LinuxKernelModuleAnchorSource; // This anchor is used to force the linker to link the LLVMModule. extern volatile int LLVMModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination = +[[maybe_unused]] static int LLVMModuleAnchorDestination = LLVMModuleAnchorSource; // This anchor is used to force the linker to link the LLVMLibcModule. extern volatile int LLVMLibcModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED LLVMLibcModuleAnchorDestination = +[[maybe_unused]] static int LLVMLibcModuleAnchorDestination = LLVMLibcModuleAnchorSource; // This anchor is used to force the linker to link the MiscModule. extern volatile int MiscModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination = +[[maybe_unused]] static int MiscModuleAnchorDestination = MiscModuleAnchorSource; // This anchor is used to force the linker to link the ModernizeModule. extern volatile int ModernizeModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination = +[[maybe_unused]] static int ModernizeModuleAnchorDestination = ModernizeModuleAnchorSource; #if CLANG_TIDY_ENABLE_STATIC_ANALYZER && \ !defined(CLANG_TIDY_DISABLE_STATIC_ANALYZER_CHECKS) // This anchor is used to force the linker to link the MPIModule. extern volatile int MPIModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination = - MPIModuleAnchorSource; +[[maybe_unused]] static int MPIModuleAnchorDestination = MPIModuleAnchorSource; #endif // This anchor is used to force the linker to link the ObjCModule. extern volatile int ObjCModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED ObjCModuleAnchorDestination = +[[maybe_unused]] static int ObjCModuleAnchorDestination = ObjCModuleAnchorSource; // This anchor is used to force the linker to link the OpenMPModule. extern volatile int OpenMPModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED OpenMPModuleAnchorDestination = +[[maybe_unused]] static int OpenMPModuleAnchorDestination = OpenMPModuleAnchorSource; // This anchor is used to force the linker to link the PerformanceModule. extern volatile int PerformanceModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination = +[[maybe_unused]] static int PerformanceModuleAnchorDestination = PerformanceModuleAnchorSource; // This anchor is used to force the linker to link the PortabilityModule. extern volatile int PortabilityModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED PortabilityModuleAnchorDestination = +[[maybe_unused]] static int PortabilityModuleAnchorDestination = PortabilityModuleAnchorSource; // This anchor is used to force the linker to link the ReadabilityModule. extern volatile int ReadabilityModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination = +[[maybe_unused]] static int ReadabilityModuleAnchorDestination = ReadabilityModuleAnchorSource; // This anchor is used to force the linker to link the ZirconModule. extern volatile int ZirconModuleAnchorSource; -static int LLVM_ATTRIBUTE_UNUSED ZirconModuleAnchorDestination = +[[maybe_unused]] static int ZirconModuleAnchorDestination = ZirconModuleAnchorSource; } // namespace clang::tidy diff --git a/clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp b/clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp index d7cc0ca..a58c041 100644 --- a/clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp @@ -45,7 +45,10 @@ struct StrCatCheckResult { std::vector<FixItHint> Hints; }; -void removeCallLeaveArgs(const CallExpr *Call, StrCatCheckResult *CheckResult) { +} // namespace + +static void removeCallLeaveArgs(const CallExpr *Call, + StrCatCheckResult *CheckResult) { if (Call->getNumArgs() == 0) return; // Remove 'Foo(' @@ -58,9 +61,9 @@ void removeCallLeaveArgs(const CallExpr *Call, StrCatCheckResult *CheckResult) { Call->getRParenLoc(), Call->getEndLoc().getLocWithOffset(1)))); } -const clang::CallExpr *processArgument(const Expr *Arg, - const MatchFinder::MatchResult &Result, - StrCatCheckResult *CheckResult) { +static const clang::CallExpr * +processArgument(const Expr *Arg, const MatchFinder::MatchResult &Result, + StrCatCheckResult *CheckResult) { const auto IsAlphanum = hasDeclaration(cxxMethodDecl(hasName("AlphaNum"))); static const auto *const Strcat = new auto(hasName("::absl::StrCat")); const auto IsStrcat = cxxBindTemporaryExpr( @@ -78,8 +81,8 @@ const clang::CallExpr *processArgument(const Expr *Arg, return nullptr; } -StrCatCheckResult processCall(const CallExpr *RootCall, bool IsAppend, - const MatchFinder::MatchResult &Result) { +static StrCatCheckResult processCall(const CallExpr *RootCall, bool IsAppend, + const MatchFinder::MatchResult &Result) { StrCatCheckResult CheckResult; std::deque<const CallExpr *> CallsToProcess = {RootCall}; @@ -101,7 +104,6 @@ StrCatCheckResult processCall(const CallExpr *RootCall, bool IsAppend, } return CheckResult; } -} // namespace void RedundantStrcatCallsCheck::check(const MatchFinder::MatchResult &Result) { bool IsAppend = false; diff --git a/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp index 4fc1b3b..76df992 100644 --- a/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp @@ -69,14 +69,14 @@ public: return Visit(T->getElementType().getTypePtr()); } bool VisitEnumType(const EnumType *T) { - if (isCompleteAndHasNoZeroValue(T->getOriginalDecl())) { + if (isCompleteAndHasNoZeroValue(T->getDecl())) { FoundEnum = T; return true; } return false; } bool VisitRecordType(const RecordType *T) { - const RecordDecl *RD = T->getOriginalDecl()->getDefinition(); + const RecordDecl *RD = T->getDecl()->getDefinition(); if (!RD || RD->isUnion()) return false; auto VisitField = [this](const FieldDecl *F) { @@ -139,7 +139,7 @@ void InvalidEnumDefaultInitializationCheck::check( if (!Finder.Visit(InitList->getArrayFiller()->getType().getTypePtr())) return; InitExpr = InitList; - Enum = Finder.FoundEnum->getOriginalDecl(); + Enum = Finder.FoundEnum->getDecl(); } if (!InitExpr || !Enum) diff --git a/clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.cpp index 390f3dd..54ed899 100644 --- a/clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.cpp @@ -18,8 +18,11 @@ namespace { AST_MATCHER(Expr, isInMacro) { return Node.getBeginLoc().isMacroID(); } +} // namespace + /// Find the next statement after `S`. -const Stmt *nextStmt(const MatchFinder::MatchResult &Result, const Stmt *S) { +static const Stmt *nextStmt(const MatchFinder::MatchResult &Result, + const Stmt *S) { auto Parents = Result.Context->getParents(*S); if (Parents.empty()) return nullptr; @@ -40,8 +43,8 @@ using ExpansionRanges = std::vector<SourceRange>; /// \brief Get all the macro expansion ranges related to `Loc`. /// /// The result is ordered from most inner to most outer. -ExpansionRanges getExpansionRanges(SourceLocation Loc, - const MatchFinder::MatchResult &Result) { +static ExpansionRanges +getExpansionRanges(SourceLocation Loc, const MatchFinder::MatchResult &Result) { ExpansionRanges Locs; while (Loc.isMacroID()) { Locs.push_back( @@ -51,8 +54,6 @@ ExpansionRanges getExpansionRanges(SourceLocation Loc, return Locs; } -} // namespace - void MultipleStatementMacroCheck::registerMatchers(MatchFinder *Finder) { const auto Inner = expr(isInMacro(), unless(compoundStmt())).bind("inner"); Finder->addMatcher( diff --git a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp index d467684..3dd0a50 100644 --- a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp @@ -64,15 +64,17 @@ static unsigned getLength(const Expr *E, if (!E) return 0; - Expr::EvalResult Length; E = E->IgnoreImpCasts(); if (const auto *LengthDRE = dyn_cast<DeclRefExpr>(E)) if (const auto *LengthVD = dyn_cast<VarDecl>(LengthDRE->getDecl())) if (!isa<ParmVarDecl>(LengthVD)) - if (const Expr *LengthInit = LengthVD->getInit()) + if (const Expr *LengthInit = LengthVD->getInit(); + LengthInit && !LengthInit->isValueDependent()) { + Expr::EvalResult Length; if (LengthInit->EvaluateAsInt(Length, *Result.Context)) return Length.Val.getInt().getZExtValue(); + } if (const auto *LengthIL = dyn_cast<IntegerLiteral>(E)) return LengthIL->getValue().getZExtValue(); diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp index 5de4e33..1ac9b8b 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp @@ -28,10 +28,13 @@ AST_MATCHER(CXXRecordDecl, hasDefaultConstructor) { return Node.hasDefaultConstructor(); } +} // namespace + // Iterate over all the fields in a record type, both direct and indirect (e.g. // if the record contains an anonymous struct). template <typename T, typename Func> -void forEachField(const RecordDecl &Record, const T &Fields, const Func &Fn) { +static void forEachField(const RecordDecl &Record, const T &Fields, + const Func &Fn) { for (const FieldDecl *F : Fields) { if (F->isAnonymousStructOrUnion()) { if (const CXXRecordDecl *R = F->getType()->getAsCXXRecordDecl()) @@ -43,8 +46,9 @@ void forEachField(const RecordDecl &Record, const T &Fields, const Func &Fn) { } template <typename T, typename Func> -void forEachFieldWithFilter(const RecordDecl &Record, const T &Fields, - bool &AnyMemberHasInitPerUnion, const Func &Fn) { +static void forEachFieldWithFilter(const RecordDecl &Record, const T &Fields, + bool &AnyMemberHasInitPerUnion, + const Func &Fn) { for (const FieldDecl *F : Fields) { if (F->isAnonymousStructOrUnion()) { if (const CXXRecordDecl *R = F->getType()->getAsCXXRecordDecl()) { @@ -59,8 +63,9 @@ void forEachFieldWithFilter(const RecordDecl &Record, const T &Fields, } } -void removeFieldInitialized(const FieldDecl *M, - SmallPtrSetImpl<const FieldDecl *> &FieldDecls) { +static void +removeFieldInitialized(const FieldDecl *M, + SmallPtrSetImpl<const FieldDecl *> &FieldDecls) { const RecordDecl *R = M->getParent(); if (R && R->isUnion()) { // Erase all members in a union if any member of it is initialized. @@ -70,9 +75,9 @@ void removeFieldInitialized(const FieldDecl *M, FieldDecls.erase(M); } -void removeFieldsInitializedInBody( - const Stmt &Stmt, ASTContext &Context, - SmallPtrSetImpl<const FieldDecl *> &FieldDecls) { +static void +removeFieldsInitializedInBody(const Stmt &Stmt, ASTContext &Context, + SmallPtrSetImpl<const FieldDecl *> &FieldDecls) { auto Matches = match(findAll(binaryOperator( hasOperatorName("="), @@ -82,9 +87,9 @@ void removeFieldsInitializedInBody( removeFieldInitialized(Match.getNodeAs<FieldDecl>("fieldDecl"), FieldDecls); } -StringRef getName(const FieldDecl *Field) { return Field->getName(); } +static StringRef getName(const FieldDecl *Field) { return Field->getName(); } -StringRef getName(const RecordDecl *Record) { +static StringRef getName(const RecordDecl *Record) { // Get the typedef name if this is a C-style anonymous struct and typedef. if (const TypedefNameDecl *Typedef = Record->getTypedefNameForAnonDecl()) return Typedef->getName(); @@ -94,7 +99,7 @@ StringRef getName(const RecordDecl *Record) { // Creates comma separated list of decls requiring initialization in order of // declaration. template <typename R, typename T> -std::string +static std::string toCommaSeparatedString(const R &OrderedDecls, const SmallPtrSetImpl<const T *> &DeclsToInit) { SmallVector<StringRef, 16> Names; @@ -105,12 +110,14 @@ toCommaSeparatedString(const R &OrderedDecls, return llvm::join(Names.begin(), Names.end(), ", "); } -SourceLocation getLocationForEndOfToken(const ASTContext &Context, - SourceLocation Location) { +static SourceLocation getLocationForEndOfToken(const ASTContext &Context, + SourceLocation Location) { return Lexer::getLocForEndOfToken(Location, 0, Context.getSourceManager(), Context.getLangOpts()); } +namespace { + // There are 3 kinds of insertion placements: enum class InitializerPlacement { // 1. The fields are inserted after an existing CXXCtorInitializer stored in @@ -187,15 +194,17 @@ struct InitializerInsertion { SmallVector<std::string, 4> Initializers; }; +} // namespace + // Convenience utility to get a RecordDecl from a QualType. -const RecordDecl *getCanonicalRecordDecl(const QualType &Type) { +static const RecordDecl *getCanonicalRecordDecl(const QualType &Type) { if (const auto *RT = Type->getAsCanonical<RecordType>()) - return RT->getOriginalDecl(); + return RT->getDecl(); return nullptr; } template <typename R, typename T> -SmallVector<InitializerInsertion, 16> +static SmallVector<InitializerInsertion, 16> computeInsertions(const CXXConstructorDecl::init_const_range &Inits, const R &OrderedDecls, const SmallPtrSetImpl<const T *> &DeclsToInit) { @@ -239,8 +248,9 @@ computeInsertions(const CXXConstructorDecl::init_const_range &Inits, // Gets the list of bases and members that could possibly be initialized, in // order as they appear in the class declaration. -void getInitializationsInOrder(const CXXRecordDecl &ClassDecl, - SmallVectorImpl<const NamedDecl *> &Decls) { +static void +getInitializationsInOrder(const CXXRecordDecl &ClassDecl, + SmallVectorImpl<const NamedDecl *> &Decls) { Decls.clear(); for (const auto &Base : ClassDecl.bases()) { // Decl may be null if the base class is a template parameter. @@ -253,9 +263,10 @@ void getInitializationsInOrder(const CXXRecordDecl &ClassDecl, } template <typename T> -void fixInitializerList(const ASTContext &Context, DiagnosticBuilder &Diag, - const CXXConstructorDecl *Ctor, - const SmallPtrSetImpl<const T *> &DeclsToInit) { +static void fixInitializerList(const ASTContext &Context, + DiagnosticBuilder &Diag, + const CXXConstructorDecl *Ctor, + const SmallPtrSetImpl<const T *> &DeclsToInit) { // Do not propose fixes in macros since we cannot place them correctly. if (Ctor->getBeginLoc().isMacroID()) return; @@ -271,8 +282,6 @@ void fixInitializerList(const ASTContext &Context, DiagnosticBuilder &Diag, } } -} // anonymous namespace - ProTypeMemberInitCheck::ProTypeMemberInitCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), diff --git a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp index a038af4..6d5182d 100644 --- a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp @@ -72,7 +72,7 @@ static bool isStdInitializerList(QualType Type) { } if (const auto *RT = Type->getAs<RecordType>()) { if (const auto *Specialization = - dyn_cast<ClassTemplateSpecializationDecl>(RT->getOriginalDecl())) + dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl())) return declIsStdInitializerList(Specialization->getSpecializedTemplate()); } return false; diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp index 8ec7695..3b9b8e0 100644 --- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp @@ -60,12 +60,12 @@ AST_MATCHER_P(CoawaitExpr, awaitable, ast_matchers::internal::Matcher<Expr>, return InnerMatcher.matches(*E, Finder, Builder); return false; } +} // namespace -auto typeWithNameIn(const std::vector<StringRef> &Names) { +static auto typeWithNameIn(const std::vector<StringRef> &Names) { return hasType( hasCanonicalType(hasDeclaration(namedDecl(hasAnyName(Names))))); } -} // namespace CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name, ClangTidyContext *Context) diff --git a/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp b/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp index 0d7667c..035598d 100644 --- a/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp @@ -151,10 +151,12 @@ constexpr unsigned SmallSCCSize = 32; using CallStackTy = llvm::SmallVector<CallGraphNode::CallRecord, SmallCallStackSize>; +} // namespace + // In given SCC, find *some* call stack that will be cyclic. // This will only find *one* such stack, it might not be the smallest one, // and there may be other loops. -CallStackTy pathfindSomeCycle(ArrayRef<CallGraphNode *> SCC) { +static CallStackTy pathfindSomeCycle(ArrayRef<CallGraphNode *> SCC) { // We'll need to be able to performantly look up whether some CallGraphNode // is in SCC or not, so cache all the SCC elements in a set. const ImmutableSmallSet<CallGraphNode *, SmallSCCSize> SCCElts(SCC); @@ -190,8 +192,6 @@ CallStackTy pathfindSomeCycle(ArrayRef<CallGraphNode *> SCC) { return CallStack; } -} // namespace - void NoRecursionCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher(translationUnitDecl().bind("TUDecl"), this); } diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp index 31524e4..81840cc9 100644 --- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp @@ -132,7 +132,7 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) { } if (const auto *ECD = dyn_cast<EnumConstantDecl>(Used)) { if (const auto *ET = ECD->getType()->getAsCanonical<EnumType>()) - removeFromFoundDecls(ET->getOriginalDecl()); + removeFromFoundDecls(ET->getDecl()); } }; // We rely on the fact that the clang AST is walked in order, usages are only diff --git a/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp index aa1ee6d..a004480 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp @@ -29,7 +29,7 @@ static bool isLockGuardDecl(const NamedDecl *Decl) { static bool isLockGuard(const QualType &Type) { if (const auto *Record = Type->getAsCanonical<RecordType>()) - if (const RecordDecl *Decl = Record->getOriginalDecl()) + if (const RecordDecl *Decl = Record->getDecl()) return isLockGuardDecl(Decl); if (const auto *TemplateSpecType = Type->getAs<TemplateSpecializationType>()) diff --git a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp index 3e27d8f..d623ec4 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp @@ -77,7 +77,7 @@ public: if (T->getKeyword() != ElaboratedTypeKeyword::None || TTL.getQualifierLoc()) break; - if (visitUnqualName(T->getOriginalDecl()->getName())) + if (visitUnqualName(T->getDecl()->getName())) return false; break; } diff --git a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp index 29084f4..d1738f1 100644 --- a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp @@ -413,11 +413,10 @@ static bool areTypesCompatible(QualType ArgType, QualType ParamType, // Arithmetic types are interconvertible, except scoped enums. if (ParamType->isArithmeticType() && ArgType->isArithmeticType()) { - if ((ParamType->isEnumeralType() && ParamType->castAsCanonical<EnumType>() - ->getOriginalDecl() - ->isScoped()) || + if ((ParamType->isEnumeralType() && + ParamType->castAsCanonical<EnumType>()->getDecl()->isScoped()) || (ArgType->isEnumeralType() && - ArgType->castAsCanonical<EnumType>()->getOriginalDecl()->isScoped())) + ArgType->castAsCanonical<EnumType>()->getDecl()->isScoped())) return false; return true; diff --git a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp index c1dc209..740a68d 100644 --- a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp @@ -55,8 +55,10 @@ struct NewSuffix { std::optional<FixItHint> FixIt; }; -std::optional<SourceLocation> getMacroAwareLocation(SourceLocation Loc, - const SourceManager &SM) { +} // namespace + +static std::optional<SourceLocation> +getMacroAwareLocation(SourceLocation Loc, const SourceManager &SM) { // Do nothing if the provided location is invalid. if (Loc.isInvalid()) return std::nullopt; @@ -67,8 +69,8 @@ std::optional<SourceLocation> getMacroAwareLocation(SourceLocation Loc, return SpellingLoc; } -std::optional<SourceRange> getMacroAwareSourceRange(SourceRange Loc, - const SourceManager &SM) { +static std::optional<SourceRange> +getMacroAwareSourceRange(SourceRange Loc, const SourceManager &SM) { std::optional<SourceLocation> Begin = getMacroAwareLocation(Loc.getBegin(), SM); std::optional<SourceLocation> End = getMacroAwareLocation(Loc.getEnd(), SM); @@ -77,7 +79,7 @@ std::optional<SourceRange> getMacroAwareSourceRange(SourceRange Loc, return SourceRange(*Begin, *End); } -std::optional<std::string> +static std::optional<std::string> getNewSuffix(llvm::StringRef OldSuffix, const std::vector<StringRef> &NewSuffixes) { // If there is no config, just uppercase the entirety of the suffix. @@ -96,7 +98,7 @@ getNewSuffix(llvm::StringRef OldSuffix, } template <typename LiteralType> -std::optional<NewSuffix> +static std::optional<NewSuffix> shouldReplaceLiteralSuffix(const Expr &Literal, const std::vector<StringRef> &NewSuffixes, const SourceManager &SM, const LangOptions &LO) { @@ -174,8 +176,6 @@ shouldReplaceLiteralSuffix(const Expr &Literal, return ReplacementDsc; } -} // namespace - UppercaseLiteralSuffixCheck::UppercaseLiteralSuffixCheck( StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), diff --git a/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp b/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp index 57453ad..a5b0883 100644 --- a/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp +++ b/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp @@ -19,9 +19,8 @@ namespace clang::tidy::utils::decl_ref_expr { using namespace ::clang::ast_matchers; using llvm::SmallPtrSet; -namespace { - -template <typename S> bool isSetDifferenceEmpty(const S &S1, const S &S2) { +template <typename S> +static bool isSetDifferenceEmpty(const S &S1, const S &S2) { for (auto E : S1) if (S2.count(E) == 0) return false; @@ -30,15 +29,15 @@ template <typename S> bool isSetDifferenceEmpty(const S &S1, const S &S2) { // Extracts all Nodes keyed by ID from Matches and inserts them into Nodes. template <typename Node> -void extractNodesByIdTo(ArrayRef<BoundNodes> Matches, StringRef ID, - SmallPtrSet<const Node *, 16> &Nodes) { +static void extractNodesByIdTo(ArrayRef<BoundNodes> Matches, StringRef ID, + SmallPtrSet<const Node *, 16> &Nodes) { for (const auto &Match : Matches) Nodes.insert(Match.getNodeAs<Node>(ID)); } // Returns true if both types refer to the same type, // ignoring the const-qualifier. -bool isSameTypeIgnoringConst(QualType A, QualType B) { +static bool isSameTypeIgnoringConst(QualType A, QualType B) { A = A.getCanonicalType(); B = B.getCanonicalType(); A.addConst(); @@ -47,7 +46,8 @@ bool isSameTypeIgnoringConst(QualType A, QualType B) { } // Returns true if `D` and `O` have the same parameter types. -bool hasSameParameterTypes(const CXXMethodDecl &D, const CXXMethodDecl &O) { +static bool hasSameParameterTypes(const CXXMethodDecl &D, + const CXXMethodDecl &O) { if (D.getNumParams() != O.getNumParams()) return false; for (int I = 0, E = D.getNumParams(); I < E; ++I) { @@ -60,7 +60,7 @@ bool hasSameParameterTypes(const CXXMethodDecl &D, const CXXMethodDecl &O) { // If `D` has a const-qualified overload with otherwise identical // ref-qualifiers and parameter types, returns that overload. -const CXXMethodDecl *findConstOverload(const CXXMethodDecl &D) { +static const CXXMethodDecl *findConstOverload(const CXXMethodDecl &D) { assert(!D.isConst()); DeclContext::lookup_result LookupResult = @@ -81,7 +81,7 @@ const CXXMethodDecl *findConstOverload(const CXXMethodDecl &D) { // Returns true if both types are pointers or reference to the same type, // ignoring the const-qualifier. -bool pointsToSameTypeIgnoringConst(QualType A, QualType B) { +static bool pointsToSameTypeIgnoringConst(QualType A, QualType B) { assert(A->isPointerType() || A->isReferenceType()); assert(B->isPointerType() || B->isReferenceType()); return isSameTypeIgnoringConst(A->getPointeeType(), B->getPointeeType()); @@ -122,7 +122,7 @@ bool pointsToSameTypeIgnoringConst(QualType A, QualType B) { // // This function checks (A) ad (B), but the caller should make sure that the // object is not mutated through the return value. -bool isLikelyShallowConst(const CXXMethodDecl &M) { +static bool isLikelyShallowConst(const CXXMethodDecl &M) { assert(!M.isConst()); // The method can mutate our variable. @@ -146,6 +146,8 @@ bool isLikelyShallowConst(const CXXMethodDecl &M) { return isSameTypeIgnoringConst(CallTy, OverloadTy); } +namespace { + // A matcher that matches DeclRefExprs that are used in ways such that the // underlying declaration is not modified. // If the declaration is of pointer type, `Indirections` specifies the level diff --git a/clang-tools-extra/clang-tidy/utils/DesignatedInitializers.cpp b/clang-tools-extra/clang-tidy/utils/DesignatedInitializers.cpp index 044f89b..b068ae2 100644 --- a/clang-tools-extra/clang-tidy/utils/DesignatedInitializers.cpp +++ b/clang-tools-extra/clang-tidy/utils/DesignatedInitializers.cpp @@ -19,8 +19,6 @@ namespace clang::tidy::utils { -namespace { - /// Returns true if Name is reserved, like _Foo or __Vector_base. static inline bool isReservedName(llvm::StringRef Name) { // This doesn't catch all cases, but the most common. @@ -28,6 +26,8 @@ static inline bool isReservedName(llvm::StringRef Name) { (isUppercase(Name[1]) || Name[1] == '_'); } +namespace { + // Helper class to iterate over the designator names of an aggregate type. // // For an array type, yields [0], [1], [2]... @@ -112,6 +112,8 @@ private: RecordDecl::field_iterator FieldsEnd; }; +} // namespace + // Collect designator labels describing the elements of an init list. // // This function contributes the designators of some (sub)object, which is @@ -127,10 +129,9 @@ private: // '.a:' is produced directly without recursing into the written sublist. // (The written sublist will have a separate collectDesignators() call later). // Recursion with Prefix='.b' and Sem = {3, ImplicitValue} produces '.b.x:'. -void collectDesignators(const InitListExpr *Sem, - llvm::DenseMap<SourceLocation, std::string> &Out, - const llvm::DenseSet<SourceLocation> &NestedBraces, - std::string &Prefix) { +static void collectDesignators( + const InitListExpr *Sem, llvm::DenseMap<SourceLocation, std::string> &Out, + const llvm::DenseSet<SourceLocation> &NestedBraces, std::string &Prefix) { if (!Sem || Sem->isTransparent()) return; assert(Sem->isSemanticForm()); @@ -170,8 +171,6 @@ void collectDesignators(const InitListExpr *Sem, } } -} // namespace - llvm::DenseMap<SourceLocation, std::string> getUnwrittenDesignators(const InitListExpr *Syn) { assert(Syn->isSyntacticForm()); diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp index 70f6092..71d252f 100644 --- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -331,7 +331,7 @@ public: } bool VisitTagTypeLoc(const TagTypeLoc &Loc) { - Check->addUsage(Loc.getOriginalDecl(), Loc.getNameLoc(), SM); + Check->addUsage(Loc.getDecl(), Loc.getNameLoc(), SM); return true; } diff --git a/clang-tools-extra/clangd/DumpAST.cpp b/clang-tools-extra/clangd/DumpAST.cpp index 9a8d41d..cd409a2 100644 --- a/clang-tools-extra/clangd/DumpAST.cpp +++ b/clang-tools-extra/clangd/DumpAST.cpp @@ -261,7 +261,7 @@ class DumpVisitor : public RecursiveASTVisitor<DumpVisitor> { return TL.getType().getLocalQualifiers().getAsString( Ctx.getPrintingPolicy()); if (const auto *TT = dyn_cast<TagType>(TL.getTypePtr())) - return getDetail(TT->getOriginalDecl()); + return getDetail(TT->getDecl()); if (const auto *DT = dyn_cast<DeducedType>(TL.getTypePtr())) if (DT->isDeduced()) return DT->getDeducedType().getAsString(Ctx.getPrintingPolicy()); diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp index 5d5388e..f80f732 100644 --- a/clang-tools-extra/clangd/FindTarget.cpp +++ b/clang-tools-extra/clangd/FindTarget.cpp @@ -50,7 +50,7 @@ namespace clang { namespace clangd { namespace { -LLVM_ATTRIBUTE_UNUSED std::string nodeToString(const DynTypedNode &N) { +[[maybe_unused]] std::string nodeToString(const DynTypedNode &N) { std::string S = std::string(N.getNodeKind().asStringRef()); { llvm::raw_string_ostream OS(S); @@ -366,7 +366,7 @@ public: Visitor(TargetFinder &Outer, RelSet Flags) : Outer(Outer), Flags(Flags) {} void VisitTagType(const TagType *TT) { - Outer.add(cast<TagType>(TT)->getOriginalDecl(), Flags); + Outer.add(cast<TagType>(TT)->getDecl(), Flags); } void VisitUsingType(const UsingType *ET) { @@ -861,7 +861,7 @@ refInTypeLoc(TypeLoc L, const HeuristicResolver *Resolver) { Refs.push_back(ReferenceLoc{L.getQualifierLoc(), L.getNameLoc(), /*IsDecl=*/false, - {L.getOriginalDecl()}}); + {L.getDecl()}}); } void VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc L) { diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp index acc8e87..34369e1 100644 --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -179,7 +179,7 @@ HoverInfo::PrintedType printType(QualType QT, ASTContext &ASTCtx, if (!QT.isNull() && !QT.hasQualifiers() && PP.SuppressTagKeyword) { if (auto *TT = llvm::dyn_cast<TagType>(QT.getTypePtr()); TT && TT->isCanonicalUnqualified()) - OS << TT->getOriginalDecl()->getKindName() << " "; + OS << TT->getDecl()->getKindName() << " "; } QT.print(OS, PP); diff --git a/clang-tools-extra/clangd/IncludeFixer.cpp b/clang-tools-extra/clangd/IncludeFixer.cpp index c27d960..3f3d7fb 100644 --- a/clang-tools-extra/clangd/IncludeFixer.cpp +++ b/clang-tools-extra/clangd/IncludeFixer.cpp @@ -173,7 +173,7 @@ std::vector<Fix> IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel, // `enum x : int;' is not formally an incomplete type. // We may need a full definition anyway. if (auto * ET = llvm::dyn_cast<EnumType>(T)) - if (!ET->getOriginalDecl()->getDefinition()) + if (!ET->getDecl()->getDefinition()) return fixIncompleteType(*T); } } diff --git a/clang-tools-extra/clangd/InlayHints.cpp b/clang-tools-extra/clangd/InlayHints.cpp index d56b93e..23bd023 100644 --- a/clang-tools-extra/clangd/InlayHints.cpp +++ b/clang-tools-extra/clangd/InlayHints.cpp @@ -60,7 +60,7 @@ const NamedDecl *getDeclForType(const Type *T) { case Type::Enum: case Type::Record: case Type::InjectedClassName: - return cast<TagType>(T)->getOriginalDecl(); + return cast<TagType>(T)->getDecl(); case Type::TemplateSpecialization: return cast<TemplateSpecializationType>(T) ->getTemplateName() diff --git a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp index f65c74f..3f43362 100644 --- a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp @@ -322,7 +322,7 @@ bool AddUsing::prepare(const Selection &Inputs) { if (!QualifierToRemove) break; SpelledNameRange = TL.getNameLoc(); - MustInsertAfterLoc = TL.getOriginalDecl()->getBeginLoc(); + MustInsertAfterLoc = TL.getDecl()->getBeginLoc(); break; } case TypeLoc::Typedef: { diff --git a/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp b/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp index 2c98417..769d73f 100644 --- a/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp @@ -116,7 +116,7 @@ bool PopulateSwitch::prepare(const Selection &Sel) { EnumT = Cond->getType()->getAsCanonical<EnumType>(); if (!EnumT) return false; - EnumD = EnumT->getOriginalDecl()->getDefinitionOrSelf(); + EnumD = EnumT->getDecl()->getDefinitionOrSelf(); if (EnumD->isDependentType()) return false; diff --git a/clang-tools-extra/clangd/unittests/FileDistanceTests.cpp b/clang-tools-extra/clangd/unittests/FileDistanceTests.cpp index 3003582..aed3400 100644 --- a/clang-tools-extra/clangd/unittests/FileDistanceTests.cpp +++ b/clang-tools-extra/clangd/unittests/FileDistanceTests.cpp @@ -58,7 +58,7 @@ TEST(FileDistanceTests, BadSource) { } // Force the unittest URI scheme to be linked, -static int LLVM_ATTRIBUTE_UNUSED UseUnittestScheme = UnittestSchemeAnchorSource; +[[maybe_unused]] static int UseUnittestScheme = UnittestSchemeAnchorSource; TEST(FileDistanceTests, URI) { FileDistanceOptions Opts; diff --git a/clang-tools-extra/clangd/unittests/QualityTests.cpp b/clang-tools-extra/clangd/unittests/QualityTests.cpp index 4954659..879a179 100644 --- a/clang-tools-extra/clangd/unittests/QualityTests.cpp +++ b/clang-tools-extra/clangd/unittests/QualityTests.cpp @@ -33,7 +33,7 @@ namespace clang { namespace clangd { // Force the unittest URI scheme to be linked, -static int LLVM_ATTRIBUTE_UNUSED UnittestSchemeAnchorDest = +[[maybe_unused]] static int UnittestSchemeAnchorDest = UnittestSchemeAnchorSource; namespace { diff --git a/clang-tools-extra/clangd/unittests/URITests.cpp b/clang-tools-extra/clangd/unittests/URITests.cpp index 99d59b6..c0ccfc5 100644 --- a/clang-tools-extra/clangd/unittests/URITests.cpp +++ b/clang-tools-extra/clangd/unittests/URITests.cpp @@ -16,7 +16,7 @@ namespace clang { namespace clangd { // Force the unittest URI scheme to be linked, -static int LLVM_ATTRIBUTE_UNUSED UnittestSchemeAnchorDest = +[[maybe_unused]] static int UnittestSchemeAnchorDest = UnittestSchemeAnchorSource; namespace { diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 33cc401..a94dd97 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -274,6 +274,10 @@ Changes in existing checks <clang-tidy/checks/bugprone/narrowing-conversions>` check by fixing false positive from analysis of a conditional expression in C. +- Improved :doc:`bugprone-not-null-terminated-result + <clang-tidy/checks/bugprone/not-null-terminated-result>` check by fixing + a crash caused by certain value-dependent expressions. + - Improved :doc:`bugprone-reserved-identifier <clang-tidy/checks/bugprone/reserved-identifier>` check by ignoring declarations and macros in system headers. diff --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp index 7bbdc8b..d444ddd 100644 --- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp +++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp @@ -342,7 +342,7 @@ public: } bool VisitTagTypeLoc(TagTypeLoc TTL) { - reportType(TTL.getNameLoc(), TTL.getOriginalDecl()); + reportType(TTL.getNameLoc(), TTL.getDecl()); return true; } diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-value-dependent-crash.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-value-dependent-crash.cpp new file mode 100644 index 0000000..5f361c3 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-value-dependent-crash.cpp @@ -0,0 +1,23 @@ +// RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \ +// RUN: -- -std=c++17 -I %S/Inputs/not-null-terminated-result + +// This test case reproduces the crash when the check tries to evaluate +// a value-dependent expression using EvaluateAsInt() in +// bugprone-not-null-terminated-result, where the src parameter of memcpy is +// value-dependent, but the length is not. + +// expected-no-diagnostics + +#include "not-null-terminated-result-cxx.h" + +template<size_t N> +class ValueDependentClass { +public: + void copyData(char* Dst) { + const char* Src = reinterpret_cast<const char*>(this); + // The length parameter is arbitrary, but the crash is not reproduced if it is N. + memcpy(Dst, Src, 32); + } +}; + +template class ValueDependentClass<42>; // The template parameter value is arbitrary. diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/misplaced-const-cxx17.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/misplaced-const-cxx17.cpp index 7816a09..5602932 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/misplaced-const-cxx17.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/misplaced-const-cxx17.cpp @@ -3,7 +3,7 @@ // This test previously would cause a failed assertion because the structured // binding declaration had no valid type associated with it. This ensures the // expected clang diagnostic is generated instead. -// CHECK-MESSAGES: :[[@LINE+1]]:6: error: decomposition declaration '[x]' requires an initializer [clang-diagnostic-error] +// CHECK-MESSAGES: :[[@LINE+1]]:6: error: structured binding declaration '[x]' requires an initializer [clang-diagnostic-error] auto [x]; struct S { int a; }; |