////////////////////////////////////////////////////////////////////////////// // slice computes the potential padded product of all dimensions in a given // dimension set from the Nth. ////////////////////////////////////////////////////////////////////////////// template<std::size_t N, class Seq,class Padding> inline typename boost:: lazy_enable_if_c< (boost::fusion::result_of::size<Seq>::value >= N) , nt2::meta ::enable_call < tag::slice_ ( Seq const& , Padding const& , boost::mpl::size_t<N> const& ) > >::type slice(Seq const& s, Padding const& p) { functor<tag::slice_> callee; return callee(s,p,boost::mpl::size_t<N>() ); }
void SlicingCheck::registerMatchers(MatchFinder *Finder) { // When we see: // class B : public A { ... }; // A a; // B b; // a = b; // The assignment is OK if: // - the assignment operator is defined as taking a B as second parameter, // or // - B does not define any additional members (either variables or // overrides) wrt A. // // The same holds for copy ctor calls. This also captures stuff like: // void f(A a); // f(b); // Helpers. const auto OfBaseClass = ofClass(cxxRecordDecl().bind("BaseDecl")); const auto IsDerivedFromBaseDecl = cxxRecordDecl(isDerivedFrom(equalsBoundNode("BaseDecl"))) .bind("DerivedDecl"); const auto HasTypeDerivedFromBaseDecl = anyOf(hasType(IsDerivedFromBaseDecl), hasType(references(IsDerivedFromBaseDecl))); const auto IsWithinDerivedCtor = hasParent(cxxConstructorDecl(ofClass(equalsBoundNode("DerivedDecl")))); // Assignement slicing: "a = b;" and "a = std::move(b);" variants. const auto SlicesObjectInAssignment = callExpr(callee(cxxMethodDecl(anyOf(isCopyAssignmentOperator(), isMoveAssignmentOperator()), OfBaseClass)), hasArgument(1, HasTypeDerivedFromBaseDecl)); // Construction slicing: "A a{b};" and "f(b);" variants. Note that in case of // slicing the letter will create a temporary and therefore call a ctor. const auto SlicesObjectInCtor = cxxConstructExpr( hasDeclaration(cxxConstructorDecl( anyOf(isCopyConstructor(), isMoveConstructor()), OfBaseClass)), hasArgument(0, HasTypeDerivedFromBaseDecl), // We need to disable matching on the call to the base copy/move // constructor in DerivedDecl's constructors. unless(IsWithinDerivedCtor)); Finder->addMatcher( expr(anyOf(SlicesObjectInAssignment, SlicesObjectInCtor)).bind("Call"), this); }
void IntegerTypesCheck::registerMatchers(MatchFinder *Finder) { // Find all TypeLocs. The relevant Style Guide rule only applies to C++. if (!getLangOpts().CPlusPlus) return; // Match any integer types, unless they are passed to a printf-based API: // // http://google.github.io/styleguide/cppguide.html#64-bit_Portability // "Where possible, avoid passing arguments of types specified by // bitwidth typedefs to printf-based APIs." Finder->addMatcher(typeLoc(loc(isInteger()), unless(hasAncestor(callExpr( callee(functionDecl(hasAttr(attr::Format))))))) .bind("tl"), this); IdentTable = llvm::make_unique<IdentifierTable>(getLangOpts()); }
/// If `Node` is a call to the inverse of `Scale`, return that inverse's /// argument, otherwise None. static llvm::Optional<std::string> rewriteInverseDurationCall(const MatchFinder::MatchResult &Result, DurationScale Scale, const Expr &Node) { const std::pair<llvm::StringRef, llvm::StringRef> &InverseFunctions = getDurationInverseForScale(Scale); if (const auto *MaybeCallArg = selectFirst<const Expr>( "e", match(callExpr(callee(functionDecl(hasAnyName( InverseFunctions.first, InverseFunctions.second))), hasArgument(0, expr().bind("e"))), Node, *Result.Context))) { return tooling::fixit::getText(*MaybeCallArg, *Result.Context).str(); } return llvm::None; }
int main() { int *p; int i; p = (int *) malloc( 4 ); for (i = 1; i < 10; i++) { printf( "%d ", callee( i )); fflush (stdout); } printf( " Goodbye!\n" ); fflush (stdout); /* -break2- */ return 0; }
int main() { int i = 0; char str[] = "AbCd EfGh iJkL mNoP"; printf("\nIn main(), address is: %ld\n\n", str); char *returned; returned = callee(str); printf("Returned address is: %ld\n", returned); for(i = 0; *(returned + i) != '\0'; i++) { printf("%c", *(returned + i)); } return 0; }
void ExplicitMakePairCheck::registerMatchers(ast_matchers::MatchFinder *Finder) { // Only register the matchers for C++; the functionality currently does not // provide any benefit to other languages, despite being benign. if (!getLangOpts().CPlusPlus) return; // Look for std::make_pair with explicit template args. Ignore calls in // templates. Finder->addMatcher( callExpr(unless(isInTemplateInstantiation()), callee(expr(ignoringParenImpCasts( declRefExpr(hasExplicitTemplateArgs(), to(functionDecl(hasName("::std::make_pair")))) .bind("declref"))))).bind("call"), this); }
void StringIntegerAssignmentCheck::registerMatchers(MatchFinder *Finder) { if (!getLangOpts().CPlusPlus) return; Finder->addMatcher( cxxOperatorCallExpr( anyOf(hasOverloadedOperatorName("="), hasOverloadedOperatorName("+=")), callee(cxxMethodDecl(ofClass(classTemplateSpecializationDecl( hasName("::std::basic_string"), hasTemplateArgument(0, refersToType(qualType().bind("type"))))))), hasArgument(1, ignoringImpCasts(expr(hasType(isInteger()), unless(hasType(isAnyCharacter()))) .bind("expr"))), unless(isInTemplateInstantiation())), this); }
void UniqueptrDeleteReleaseCheck::registerMatchers(MatchFinder *Finder) { auto IsSusbstituted = qualType(anyOf( substTemplateTypeParmType(), hasDescendant(substTemplateTypeParmType()))); auto UniquePtrWithDefaultDelete = classTemplateSpecializationDecl( hasName("std::unique_ptr"), hasTemplateArgument(1, refersToType(qualType(hasDeclaration(cxxRecordDecl( hasName("std::default_delete"))))))); Finder->addMatcher( cxxDeleteExpr(has(ignoringParenImpCasts(cxxMemberCallExpr( on(expr(hasType(UniquePtrWithDefaultDelete), unless(hasType(IsSusbstituted))) .bind("uptr")), callee(cxxMethodDecl(hasName("release"))))))) .bind("delete"), this); }
void pCFGIterator::filterSendRecv(const pCFGNode& pcfgn, set<unsigned int>& blockedPSets, set<unsigned int>& sendPSets, set<unsigned int>& recvPSets) { set<unsigned int>::iterator it; for(it = blockedPSets.begin(); it != blockedPSets.end(); it++) { const DataflowNode& dfnode = pcfgn.getCurNode(*it); SgNode* sgn = dfnode.getNode(); Function callee(isSgFunctionCallExp(sgn)); if(callee.get_name().getString() == "MPI_Send") { sendPSets.insert(*it); } else if(callee.get_name().getString() == "MPI_Recv") { recvPSets.insert(*it); } } }
void MoveConstArgCheck::registerMatchers(MatchFinder *Finder) { if (!getLangOpts().CPlusPlus) return; auto MoveCallMatcher = callExpr(callee(functionDecl(hasName("::std::move"))), argumentCountIs(1), unless(isInTemplateInstantiation())) .bind("call-move"); Finder->addMatcher(MoveCallMatcher, this); auto ConstParamMatcher = forEachArgumentWithParam( MoveCallMatcher, parmVarDecl(hasType(references(isConstQualified())))); Finder->addMatcher(callExpr(ConstParamMatcher).bind("receiving-expr"), this); Finder->addMatcher(cxxConstructExpr(ConstParamMatcher).bind("receiving-expr"), this); }
void ProperlySeededRandomGeneratorCheck::registerMatchers(MatchFinder *Finder) { auto RandomGeneratorEngineDecl = cxxRecordDecl(hasAnyName( "::std::linear_congruential_engine", "::std::mersenne_twister_engine", "::std::subtract_with_carry_engine", "::std::discard_block_engine", "::std::independent_bits_engine", "::std::shuffle_order_engine")); auto RandomGeneratorEngineTypeMatcher = hasType(hasUnqualifiedDesugaredType( recordType(hasDeclaration(RandomGeneratorEngineDecl)))); // std::mt19937 engine; // engine.seed(); // ^ // engine.seed(1); // ^ // const int x = 1; // engine.seed(x); // ^ Finder->addMatcher( cxxMemberCallExpr( has(memberExpr(has(declRefExpr(RandomGeneratorEngineTypeMatcher)), member(hasName("seed")), unless(hasDescendant(cxxThisExpr()))))) .bind("seed"), this); // std::mt19937 engine; // ^ // std::mt19937 engine(1); // ^ // const int x = 1; // std::mt19937 engine(x); // ^ Finder->addMatcher( cxxConstructExpr(RandomGeneratorEngineTypeMatcher).bind("ctor"), this); // srand(); // ^ // const int x = 1; // srand(x); // ^ Finder->addMatcher( callExpr(callee(functionDecl(hasAnyName("::srand", "::std::srand")))) .bind("srand"), this); }
int main(int argc, char *argv[]) { /* * We should update state on entering main(): * CHECK: new [[ID:[0-9]+]]: [[INIT:[0-9]+:0x0]] */ /* * Update state again on calling foo(): * CHECK: update [[ID]]: [[INIT]]->[[FOO:[0-9]+:0x0]] */ foo(); /* * Again on calling bar(): * CHECK: update [[ID]]: [[FOO]]->[[BAR:[0-9]+:0x0]] */ bar(); /* * The NOW event: * CHECK: update [[ID]]: [[BAR]]->[[NOW:[0-9]+:0x0]] */ TESLA_WITHIN(main, TSEQUENCE( caller(call(foo)), callee(call(bar)), TESLA_ASSERTION_SITE ) ); /* * And finally, on exit: * CHECK: update [[ID]]: [[NOW]]->[[DONE:[0-9]+]] * CHECK: pass '[[NAME:.*]]': [[ID]] * CHECK: tesla_class_reset [[NAME]] */ return 0; }
static bool constructHook(JSContext *cx, unsigned argc, jsval *vp) { JS::CallArgs args = CallArgsFromVp(argc, vp); // Check that arguments were passed properly from JS_New. JS::RootedObject obj(cx, JS_NewObject(cx, js::Jsvalify(&JSObject::class_), JS::NullPtr(), JS::NullPtr())); if (!obj) { JS_ReportError(cx, "test failed, could not construct object"); return false; } if (strcmp(JS_GetClass(obj)->name, "Object") != 0) { JS_ReportError(cx, "test failed, wrong class for 'this'"); return false; } if (args.length() != 3) { JS_ReportError(cx, "test failed, argc == %d", args.length()); return false; } if (!args[0].isInt32() || args[2].toInt32() != 2) { JS_ReportError(cx, "test failed, wrong value in args[2]"); return false; } if (!args.isConstructing()) { JS_ReportError(cx, "test failed, not constructing"); return false; } // Perform a side-effect to indicate that this hook was actually called. JS::RootedValue value(cx, args[0]); JS::RootedObject callee(cx, &args.callee()); if (!JS_SetElement(cx, callee, 0, value)) return false; args.rval().setObject(*obj); // trash the argv, perversely args[0].setUndefined(); args[1].setUndefined(); args[2].setUndefined(); return true; }
void callee(int *nums, int n){ if(n>1){ int i; for(i=0;i<n;i++){ callee(nums, n-1); if(i<n-1){ if(n%2){ nums[0]^=nums[n-1]; nums[n-1]^=nums[0]; nums[0]^=nums[n-1]; }else{ nums[i]^=nums[n-1]; nums[n-1]^=nums[i]; nums[i]^=nums[n-1]; } } } } else prt(nums); }
void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) { // Only register the matchers for C++; the functionality currently does not // provide any benefit to other languages, despite being benign. if (!getLangOpts().CPlusPlus) return; const auto ValidContainer = cxxRecordDecl(isSameOrDerivedFrom( namedDecl( has(cxxMethodDecl( isConst(), parameterCountIs(0), isPublic(), hasName("size"), returns(qualType(isInteger(), unless(booleanType())))) .bind("size")), has(cxxMethodDecl(isConst(), parameterCountIs(0), isPublic(), hasName("empty"), returns(booleanType())) .bind("empty"))) .bind("container"))); const auto WrongUse = anyOf( hasParent(binaryOperator( matchers::isComparisonOperator(), hasEitherOperand(ignoringImpCasts(anyOf( integerLiteral(equals(1)), integerLiteral(equals(0)))))) .bind("SizeBinaryOp")), hasParent(implicitCastExpr( hasImplicitDestinationType(booleanType()), anyOf( hasParent(unaryOperator(hasOperatorName("!")).bind("NegOnSize")), anything()))), hasParent(explicitCastExpr(hasDestinationType(booleanType())))); Finder->addMatcher( cxxMemberCallExpr(on(expr(anyOf(hasType(ValidContainer), hasType(pointsTo(ValidContainer)), hasType(references(ValidContainer)))) .bind("STLObject")), callee(cxxMethodDecl(hasName("size"))), WrongUse) .bind("SizeCallExpr"), this); }
void FasterStringFindCheck::registerMatchers(MatchFinder *Finder) { if (!getLangOpts().CPlusPlus) return; const auto SingleChar = expr(ignoringParenCasts(stringLiteral(hasSize(1)).bind("literal"))); const auto StringFindFunctions = hasAnyName("find", "rfind", "find_first_of", "find_first_not_of", "find_last_of", "find_last_not_of"); Finder->addMatcher( cxxMemberCallExpr( callee(functionDecl(StringFindFunctions).bind("func")), anyOf(argumentCountIs(1), argumentCountIs(2)), hasArgument(0, SingleChar), on(expr( hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration( recordDecl(hasAnyName(SmallVector<StringRef, 4>( StringLikeClasses.begin(), StringLikeClasses.end()))))))), unless(hasSubstitutedType())))), this); }
int main( int argc, char** argv ) { UTF8 bozo = "ü"; callee( bozo ); wxString s = bozo; wxString b = bozo; if( s.IsEmpty() ) { printf( "string is empty\n" ); } if( s != bozo.wx_str() ) { printf( "string miscompare\n" ); } return 0; }
cell_t * run_secd(secd_t *secd, cell_t *ctrl) { cell_t *op, *ret; TIMING_DECLARATIONS(ts_then, ts_now); share_cell(secd, ctrl); set_control(secd, &ctrl); while (true) { TIMING_START_OPERATION(ts_then); op = pop_control(secd); assert_cell(op, "run: no command"); if (cell_type(op) != CELL_OP) { errorf("run: not an opcode at [%ld]\n", cell_index(secd, op)); dbg_printc(secd, op); continue; } int opind = op->as.op; if (about_to_halt(secd, opind, &ret)) return ret; secd_opfunc_t callee = (secd_opfunc_t) opcode_table[ opind ].fun; ret = callee(secd); if (is_error(ret)) if (!handle_exception(secd, ret)) return fatal_exception(secd, ret, opind); drop_cell(secd, op); TIMING_END_OPERATION(ts_then, ts_now) run_postop(secd); ++secd->tick; } }
static JSBool constructHook(JSContext *cx, unsigned argc, jsval *vp) { // Check that arguments were passed properly from JS_New. JS::RootedObject callee(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp))); JS::RootedObject obj(cx, JS_NewObjectForConstructor(cx, js::Jsvalify(&JSObject::class_), vp)); if (!obj) { JS_ReportError(cx, "test failed, could not construct object"); return false; } if (strcmp(JS_GetClass(obj)->name, "Object") != 0) { JS_ReportError(cx, "test failed, wrong class for 'this'"); return false; } if (argc != 3) { JS_ReportError(cx, "test failed, argc == %d", argc); return false; } if (!JSVAL_IS_INT(argv[2]) || JSVAL_TO_INT(argv[2]) != 2) { JS_ReportError(cx, "test failed, wrong value in argv[2]"); return false; } if (!JS_IsConstructing(cx, vp)) { JS_ReportError(cx, "test failed, not constructing"); return false; } // Perform a side-effect to indicate that this hook was actually called. if (!JS_SetElement(cx, callee, 0, &argv[0])) return false; *vp = OBJECT_TO_JSVAL(obj); argv[0] = argv[1] = argv[2] = JSVAL_VOID; // trash the argv, perversely return true; }
int main (void) { callee (); return 0; }
#include "ASTUtility.h" //StatementMatcher callExprMatcher = callExpr().bind("callexpr"); StatementMatcher mallocMatcher = callExpr(callee(functionDecl(hasName("malloc")).bind("m"))).bind("mallocCall"); StatementMatcher freeMatcher = callExpr(callee(functionDecl(hasName("free")).bind("f"))).bind("freeCall"); StatementMatcher reallocMatcher = callExpr(callee(functionDecl(hasName("realloc")).bind("r"))).bind("reallocCall"); //memcpy arrayType non-builtin = pointer or user-defined StatementMatcher memcpyAryMatcher = callExpr( callee(functionDecl(hasName("memcpy")).bind("cpy")), hasAnyArgument(ignoringImpCasts(declRefExpr( to(declaratorDecl(hasType(arrayType( unless(hasElementType(builtinType()))).bind("cpyParm"))))))) ).bind("memcpyCall"); StatementMatcher memcpyPtrMatcher = callExpr( callee(functionDecl(hasName("memcpy")).bind("cpy")), hasAnyArgument(ignoringImpCasts(declRefExpr( to(declaratorDecl(hasType(pointerType( pointee(unless(builtinType()))).bind("cpyParmPtr"))))))) ).bind("memcpyCall"); StatementMatcher memcmpAryMatcher = callExpr( callee(functionDecl(hasName("memcmp")).bind("cmp")), hasAnyArgument(ignoringImpCasts(declRefExpr( to(declaratorDecl(hasType(arrayType( unless(hasElementType(builtinType()))).bind("cmpParm"))))))) ).bind("memcmpCall"); StatementMatcher memcmpPtrMatcher = callExpr( callee(functionDecl(hasName("memcmp")).bind("cmp")), hasAnyArgument(ignoringImpCasts(declRefExpr(
extern int caller (int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { return callee (a1 << a2 * a3 / a4 + a6 & a6 % a7 - a8) + done; }
#include "ASTUtility.h" //match function here StatementMatcher callExprMatcher = callExpr(callee(functionDecl().bind("funcDecl"))).bind("callExpr"); //match var declarations here DeclarationMatcher varMatcher = varDecl().bind("var"); class StdPrinter : public MatchFinder::MatchCallback { public: virtual void run(const MatchFinder::MatchResult &Result) { //get the node clang::ASTContext *Context = Result.Context; const clang::CallExpr *call = Result.Nodes.getNodeAs<clang::CallExpr>("callExpr"); const clang::FunctionDecl *fun = Result.Nodes.getNodeAs<clang::FunctionDecl>("funcDecl"); const clang::VarDecl *var = Result.Nodes.getNodeAs<clang::VarDecl>("var"); if(call && !ASTUtility::IsStmtInSTDFile(call, Context)) { if (ASTUtility::IsDeclInSTDFile(fun, Context)) ASTUtility::Print(fun, Context, "Rule029.stmt.std"); else ASTUtility::Print(fun, Context, "Rule029.stmt.usr"); } if (var && !ASTUtility::IsDeclInSTDFile(var, Context)) { if (var -> getType().getAsString().find("std::") != std::string::npos) ASTUtility::Print(var, Context, "Rule029.decl.std"); else ASTUtility::Print(var, Context, "Rule029.decl.usr");
int test_calling_unimportant_callee(int argc, char *argv[]) { int x; callee(); return x; // expected-warning {{Undefined or garbage value returned to caller}} }
int main() { int a = g; callee(); //@ assert a == g-1; }
int main() { int x = 1; int y = 1; _Bool z = callee((x++ == 0) || (y++ == 0)); //@ assert x == 2 && y == 2 && z == \false; }
Core::IEditor *EditorPrototype::duplicate(QWidget *parent) { return callee()->duplicate(parent); }
QWidget* EditorPrototype::toolBar() const { return callee()->toolBar(); }
Core::IFile *EditorPrototype::file() const { return callee()->file(); }