================ @@ -222,4 +223,210 @@ bool isPtrConversion(const FunctionDecl *F) { return false; } +bool isSingleton(const FunctionDecl *F) { + assert(F); + // FIXME: check # of params == 1 + if (auto *MethodDecl = dyn_cast<CXXMethodDecl>(F)) { + if (!MethodDecl->isStatic()) + return false; + } + const auto &Name = safeGetName(F); + std::string SingletonStr = "singleton"; + auto index = Name.find(SingletonStr); + return index != std::string::npos && + index == Name.size() - SingletonStr.size(); +} + +// We only care about statements so let's use the simple +// (non-recursive) visitor. +class TrivialFunctionAnalysisVisitor + : public ConstStmtVisitor<TrivialFunctionAnalysisVisitor, bool> { + + // Returns false if at least one child is non-trivial. + bool VisitChildren(const Stmt *S) { + for (const Stmt *Child : S->children()) { + if (Child && !Visit(Child)) + return false; + } + + return true; + } + +public: + using CacheTy = TrivialFunctionAnalysis::CacheTy; + + TrivialFunctionAnalysisVisitor(CacheTy &Cache) : Cache(Cache) {} + + bool VisitStmt(const Stmt *S) { + // All statements are non-trivial unless overriden later. + // Don't even recurse into children by default. + return false; + } + + bool VisitCompoundStmt(const CompoundStmt *CS) { + // A compound statement is allowed as long each individual sub-statement + // is trivial. + return VisitChildren(CS); + } + + bool VisitReturnStmt(const ReturnStmt *RS) { + // A return statement is allowed as long as the return value is trivial. + return Visit(RS->getRetValue()); ---------------- rniwa wrote:
Fixed! This as indeed the cause of the crash. https://github.com/llvm/llvm-project/pull/81808 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits