11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "llvm/ADT/StringMap.h" 14 #include "llvm/ADT/Triple.h" 15 #include "llvm/Support/Regex.h" 21 namespace portability {
29 bool IsVector = Node.getReturnType()->isVectorType();
30 for (
const ParmVarDecl *Parm : Node.parameters()) {
31 QualType Type = Parm->getType();
32 if (Type->isPointerType())
33 Type = Type->getPointeeType();
34 if (Type->isVectorType())
43 if (!Name.consume_front(
"vec_"))
46 static const llvm::StringMap<StringRef> Mapping{
52 {
"add",
"operator+ on $simd objects"},
53 {
"sub",
"operator- on $simd objects"},
54 {
"mul",
"operator* on $simd objects"},
57 auto It = Mapping.find(Name);
58 if (It != Mapping.end())
64 if (!(Name.consume_front(
"_mm_") || Name.consume_front(
"_mm256_") ||
65 Name.consume_front(
"_mm512_")))
69 if (Name.startswith(
"max_"))
71 if (Name.startswith(
"min_"))
75 if (Name.startswith(
"add_"))
76 return "operator+ on $simd objects";
77 if (Name.startswith(
"sub_"))
78 return "operator- on $simd objects";
79 if (Name.startswith(
"mul_"))
80 return "operator* on $simd objects";
85 SIMDIntrinsicsCheck::SIMDIntrinsicsCheck(StringRef
Name,
88 Suggest(Options.get(
"Suggest", 0) != 0) {}
101 Std =
getLangOpts().CPlusPlus2a ?
"std" :
"std::experimental";
103 Finder->addMatcher(callExpr(callee(functionDecl(
104 matchesName(
"^::(_mm_|_mm256_|_mm512_|vec_)"),
105 isVectorFunction())),
106 unless(isExpansionInSystemHeader()))
112 const auto *Call = Result.Nodes.getNodeAs<CallExpr>(
"call");
113 assert(Call !=
nullptr);
114 const FunctionDecl *Callee = Call->getDirectCallee();
118 StringRef Old = Callee->getName();
120 llvm::Triple::ArchType Arch =
121 Result.Context->getTargetInfo().getTriple().getArch();
128 case llvm::Triple::ppc:
129 case llvm::Triple::ppc64:
130 case llvm::Triple::ppc64le:
133 case llvm::Triple::x86:
134 case llvm::Triple::x86_64:
145 Message = (Twine(
"'") + Old +
"' can be replaced by " + New).str();
146 Message = llvm::Regex(
"\\$std").sub(Std, Message);
148 llvm::Regex(
"\\$simd").sub((Std.str() +
"::simd").str(),
Message);
150 Message = (Twine(
"'") + Old +
"' is a non-portable " +
151 llvm::Triple::getArchTypeName(Arch) +
" intrinsic function")
AST_MATCHER(BinaryOperator, isAssignmentOperator)
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
LangOptions getLangOpts() const
Returns the language options from the context.
static const StringRef Message
Base class for all clang-tidy checks.
static StringRef TrySuggestX86(StringRef Name)
static constexpr llvm::StringLiteral Name
std::map< std::string, std::string > OptionMap
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
static StringRef TrySuggestPPC(StringRef Name)
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.