10 #include "clang/AST/ASTContext.h" 11 #include "clang/ASTMatchers/ASTMatchFinder.h" 12 #include "llvm/ADT/StringMap.h" 13 #include "llvm/ADT/Triple.h" 14 #include "llvm/Support/Regex.h" 20 namespace portability {
28 bool IsVector = Node.getReturnType()->isVectorType();
29 for (
const ParmVarDecl *Parm : Node.parameters()) {
30 QualType
Type = Parm->getType();
31 if (Type->isPointerType())
32 Type = Type->getPointeeType();
33 if (Type->isVectorType())
42 if (!Name.consume_front(
"vec_"))
45 static const llvm::StringMap<StringRef> Mapping{
51 {
"add",
"operator+ on $simd objects"},
52 {
"sub",
"operator- on $simd objects"},
53 {
"mul",
"operator* on $simd objects"},
56 auto It = Mapping.find(Name);
57 if (It != Mapping.end())
63 if (!(Name.consume_front(
"_mm_") || Name.consume_front(
"_mm256_") ||
64 Name.consume_front(
"_mm512_")))
68 if (Name.startswith(
"max_"))
70 if (Name.startswith(
"min_"))
74 if (Name.startswith(
"add_"))
75 return "operator+ on $simd objects";
76 if (Name.startswith(
"sub_"))
77 return "operator- on $simd objects";
78 if (Name.startswith(
"mul_"))
79 return "operator* on $simd objects";
84 SIMDIntrinsicsCheck::SIMDIntrinsicsCheck(StringRef
Name,
87 Suggest(Options.get(
"Suggest", 0) != 0) {}
100 Std =
getLangOpts().CPlusPlus2a ?
"std" :
"std::experimental";
102 Finder->addMatcher(callExpr(callee(functionDecl(
103 matchesName(
"^::(_mm_|_mm256_|_mm512_|vec_)"),
104 isVectorFunction())),
105 unless(isExpansionInSystemHeader()))
111 const auto *Call = Result.Nodes.getNodeAs<CallExpr>(
"call");
112 assert(Call !=
nullptr);
113 const FunctionDecl *Callee = Call->getDirectCallee();
117 StringRef Old = Callee->getName();
119 llvm::Triple::ArchType Arch =
120 Result.Context->getTargetInfo().getTriple().getArch();
127 case llvm::Triple::ppc:
128 case llvm::Triple::ppc64:
129 case llvm::Triple::ppc64le:
132 case llvm::Triple::x86:
133 case llvm::Triple::x86_64:
144 Message = (Twine(
"'") + Old +
"' can be replaced by " + New).str();
145 Message = llvm::Regex(
"\\$std").sub(Std, Message);
147 llvm::Regex(
"\\$simd").sub((Std.str() +
"::simd").str(),
Message);
149 Message = (Twine(
"'") + Old +
"' is a non-portable " +
150 llvm::Triple::getArchTypeName(Arch) +
" intrinsic function")
AST_MATCHER(Expr, isMacroID)
constexpr llvm::StringLiteral Message
Base class for all clang-tidy checks.
const LangOptions & getLangOpts() const
Returns the language options from the context.
static StringRef TrySuggestX86(StringRef Name)
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.
static constexpr llvm::StringLiteral Name
std::map< std::string, std::string > OptionMap
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.
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
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.