Skip to content

Port A bunch of checkers useful in some RAJA / CHAI/ CARE codes from clang-query to clang-tidy #7

Open
@robinson96

Description

@robinson96
let comment "### Disable default name for errors"
set bind-root false

let comment "### Identify device lambda contexts"
let b1 callExpr(hasArgument(0,hasType(asString("struct care::gpu"))))
let b2 callExpr(hasArgument(0,hasType(asString("struct care::parallel"))))
let b3 cxxMemberCallExpr(on(hasType(pointsTo(cxxRecordDecl(hasName("LoopFuser"))))))
let careHostDevicePtrCallee callee(cxxMethodDecl(ofClass(classTemplateSpecializationDecl(matchesName("care::host_device_ptr")))))
let rajaDeviceContext callExpr(anyOf(b1,b2,b3))
let inDeviceLambda hasAncestor(lambdaExpr(hasAncestor(rajaDeviceContext)))
let comment "### Identify code outside lambda contexts"
let notInsideLambda unless(hasAncestor(lambdaExpr()))
let comment "### Ignore implicit casts (to prevent duplicate matches)"
let notInImplicitCast unless(hasAncestor(implicitCastExpr()))
let hasCareHostDevPtrType hasType(qualType(hasCanonicalType(hasDeclaration(namedDecl(matchesName("care::host_device_ptr"))))))

######## USEFUL FOR RAJA USERS ###################

let comment "### Set up detection of assignment of pointer to 0 or NULL (instead of nullptr), except for with explicit casts"
match stmt(isExpansionInMainFile(), castExpr(hasCastKind("NullToPointer"), unless(hasAncestor(explicitCastExpr())), unless(hasSourceExpression(cxxNullPtrLiteralExpr())))).bind("assignment_of_pointer_to_0")

let comment "### Set up detection of implicit this within device RAJA context"
match cxxThisExpr(inDeviceLambda, notInImplicitCast).bind("implicit_use_of_this_inside_lambda_function")


#### USEFUL FOR CARE USERS (https://github.com/LLNL/CARE) ##################

let comment "### Set up detection of host_device_ptr operator[] outside RAJA context"
match cxxOperatorCallExpr(careHostDevicePtrCallee, notInsideLambda, hasOverloadedOperatorName("[]")).bind("use_of_host_device_ptr_operator[]_outside_lambda_function")

let comment "### Set up detection of host_device_ptr operator[] from pointer within inside lambda context (as a stand-in for RAJA contexts)"
let careHostDevPtrArrow stmt(allOf(memberExpr(isArrow()), expr(hasCareHostDevPtrType)))
match cxxOperatorCallExpr(careHostDevicePtrCallee, hasAncestor(lambdaExpr()), hasOverloadedOperatorName("[]"), hasDescendant(careHostDevPtrArrow)).bind("use_of_host_device_ptr_operator[]_from_pointer_inside_lambda_function")

let comment "### Set up detection of dereference of host_device_ptr, ignoring system headers (from vector<host_device_ptr>) and explicit casts"
match stmt(unaryOperator(unless(hasDescendant(explicitCastExpr())), unless(isExpansionInSystemHeader()), allOf(hasOperatorName("*"), hasUnaryOperand(hasDescendant(expr(hasCareHostDevPtrType)))))).bind("dereference_host_device_ptr")

let comment "### Set up detection of KeyValueSorter functions outside RAJA context"
let k1 cxxMethodDecl(hasName("key"))
let k2 cxxMethodDecl(hasName("setKey"))
let k3 cxxMethodDecl(hasName("value"))
let k4 cxxMethodDecl(hasName("setValue"))
let KeyValueSorterRAJACalls cxxMethodDecl(anyOf(k1,k2,k3,k4))
match cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("KeyValueSorter")))), callee(KeyValueSorterRAJACalls), notInsideLambda).bind("use_of_KeyValueSort_RAJA_function_outside_lambda_function")

let comment "### Set up detection of assignment of raw pointer to host_device_ptr"
let comment "### This is searching for the constructor with bool as the third argument"
let comment "### Ignore when the raw pointer is explicitly cast"
match cxxConstructExpr(hasCareHostDevPtrType, hasArgument(2, hasType(asString("_Bool"))), unless(hasArgument(0, explicitCastExpr()))).bind("construction_of_host_device_ptr_from_raw_pointer")

############# USEFUL FOR CHAI USERS ########################

let comment "### Set up detection of reference of raw pointer in device lambda"
let comment "### ignoringImplicit and no implicitCastExpr ancestor is required to prevent duplicate matches"
match expr(inDeviceLambda, notInImplicitCast, ignoringImplicit(declRefExpr(to(varDecl(hasType(isAnyPointer()), unless(inDeviceLambda)))))).bind("capture_of_raw_pointer_in_lambda")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions