void DurationConversionCastCheck::check( const MatchFinder::MatchResult &Result) { const auto *MatchedCast = Result.Nodes.getNodeAs<ExplicitCastExpr>("cast_expr"); if (isInMacro(Result, MatchedCast)) return; const auto *FuncDecl = Result.Nodes.getNodeAs<FunctionDecl>("func_decl"); const auto *Arg = Result.Nodes.getNodeAs<Expr>("arg"); StringRef ConversionFuncName = FuncDecl->getName(); llvm::Optional<DurationScale> Scale = getScaleForDurationInverse(ConversionFuncName); if (!Scale) return; // Casting a double to an integer. if (MatchedCast->getTypeAsWritten()->isIntegerType() && ConversionFuncName.contains("Double")) { llvm::StringRef NewFuncName = getDurationInverseForScale(*Scale).second; diag(MatchedCast->getBeginLoc(), "duration should be converted directly to an integer rather than " "through a type cast") << FixItHint::CreateReplacement( MatchedCast->getSourceRange(), (llvm::Twine(NewFuncName.substr(2)) + "(" + tooling::fixit::getText(*Arg, *Result.Context) + ")") .str()); } // Casting an integer to a double. if (MatchedCast->getTypeAsWritten()->isRealFloatingType() && ConversionFuncName.contains("Int64")) { llvm::StringRef NewFuncName = getDurationInverseForScale(*Scale).first; diag(MatchedCast->getBeginLoc(), "duration should be converted directly to " "a floating-piont number rather than " "through a type cast") << FixItHint::CreateReplacement( MatchedCast->getSourceRange(), (llvm::Twine(NewFuncName.substr(2)) + "(" + tooling::fixit::getText(*Arg, *Result.Context) + ")") .str()); } }
// Using .symver foo,foo@@VER unfortunately creates two symbols: foo and // foo@@VER. We want to effectively ignore foo, so give precedence to // foo@@VER. // FIXME: If users can transition to using // .symver foo,foo@@@VER // we can delete this hack. static int compareVersion(Symbol *S, StringRef Name) { bool A = Name.contains("@@"); bool B = S->getName().contains("@@"); if (A && !B) return 1; if (!A && B) return -1; return 0; }
static bool useStringTable(bool Thin, StringRef Name) { return Thin || Name.size() >= 16 || Name.contains('/'); }
// Quote a given string if it contains a space character. std::string lld::quote(StringRef S) { if (S.contains(' ')) return ("\"" + S + "\"").str(); return S; }