24 const MatchFinder::MatchResult &MatchResult,
25 IdentifierTable &IdentTable) {
27 if (Lexer::getRawToken(Loc, Tok, *MatchResult.SourceManager,
28 MatchResult.Context->getLangOpts(),
false))
31 if (Tok.is(tok::raw_identifier)) {
32 IdentifierInfo &Info = IdentTable.get(Tok.getRawIdentifier());
33 Tok.setIdentifierInfo(&Info);
34 Tok.setKind(Info.getTokenID());
94 typeLoc(loc(isInteger()), isValidAndNotInMacro(), isBuiltinType(),
96 callExpr(callee(functionDecl(hasAttr(attr::Format)))))),
97 unless(hasParent(parmVarDecl(
98 hasAncestor(functionDecl(isUserDefineLiteral()))))))
101 IdentTable = std::make_unique<IdentifierTable>(getLangOpts());
105 auto TL = *Result.Nodes.getNodeAs<TypeLoc>(
"tl");
106 SourceLocation Loc = TL.getBeginLoc();
109 if (
auto QualLoc = TL.getAs<QualifiedTypeLoc>())
110 TL = QualLoc.getUnqualifiedLoc();
112 auto BuiltinLoc = TL.getAs<BuiltinTypeLoc>();
121 if (!Tok.isOneOf(tok::kw_short, tok::kw_long, tok::kw_unsigned,
125 bool IsSigned =
false;
127 const TargetInfo &TargetInfo = Result.Context->getTargetInfo();
130 switch (BuiltinLoc.getTypePtr()->getKind()) {
131 case BuiltinType::Short:
132 Width = TargetInfo.getShortWidth();
135 case BuiltinType::Long:
136 Width = TargetInfo.getLongWidth();
139 case BuiltinType::LongLong:
140 Width = TargetInfo.getLongLongWidth();
143 case BuiltinType::UShort:
144 Width = TargetInfo.getShortWidth();
147 case BuiltinType::ULong:
148 Width = TargetInfo.getLongWidth();
151 case BuiltinType::ULongLong:
152 Width = TargetInfo.getLongLongWidth();
161 const StringRef Port =
"unsigned short port";
162 const char *Data = Result.SourceManager->getCharacterData(Loc);
163 if (!std::strncmp(Data, Port.data(), Port.size()) &&
164 !isAsciiIdentifierContinue(Data[Port.size()]))
167 std::string Replacement =
168 ((IsSigned ? SignedTypePrefix : UnsignedTypePrefix) + Twine(Width) +
175 diag(Loc,
"consider replacing %0 with '%1'")
176 << BuiltinLoc.getType() << Replacement;
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.