[cfe-users] Calling match in a clang-tidy check's check method

2020-01-15 Thread Lewis, Cannada via cfe-users
Is there a way to get a non const reference to the ASTContext inside of a clang 
tidy check?  I have two reasons I want this.  

1. To do matches on specific nodes like below. 

void MyCheck::check(const MatchFinder::MatchResult &Result) {
auto const *Lambda = Result.Nodes.getNodeAs("Lambda");

// Doesn’t work because Context is a const* and match has no const 
overloads
auto BN = match(, Lambda, *Result.Context);
}

2. To use the ExprMutationAnalyzer in my check function, which requires a non 
const ASTContext reference for its constructor. 

-Cannada Lewis 

___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] Clang-tidy lexer util issue.

2020-02-17 Thread Lewis, Cannada via cfe-users
I am trying to use the getPreviousToken function from 
clang-tools-extra/clang-tidy/utils/LexerUtils.cpp,
 but am having issues when the SourceLocation comes from a macro.  Let’s say I 
have the following functions:

#include 
#include 

// The macros are  defined such that KOKKOS_FUNCTION is empty and 
KOKKOS_INLINE_FUNCITON = “inline”

KOKKOS_FUNCTION
void useString(std::string const& s, int i){ }

KOKKOS_INLINE_FUNCTION
void useString2(std::string const& s, int i){ }

If I take the FunctionDecl for useString and use getBeginLoc, I will get a 
location that corresponds to the token void right before useString, I then use 
getPreviousToken to find the KOKKOS_FUNCTION macro and all is well.

But if I call getBeginLoc on useString2 my location starts off in the macro 
(I’m not really sure exactly what that means, my guess is that it starts on the 
inline keyword) and if I use that location for getPreviousToken, I don’t get 
the ‘}' from the line with useString, instead I get some location from other 
headers included in Kokkos_Core.hpp.  I don’t think that this is the intended 
behavior, but I don’t have a minimal working example at the moment. I did track 
it down to  where getPreviousToken calls getWithOffset(-1) on the source 
location and it is that new location which is the unexpected location.

Any help would be appreciated.

-Cannada Lewis
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang-tidy lexer util issue.

2020-02-18 Thread Lewis, Cannada via cfe-users
I was able to solve my problem by making sure to get the expansion location 
before calling getPreviousToken.

On Feb 17, 2020, at 5:42 PM, Lewis, Cannada 
mailto:canl...@sandia.gov>> wrote:

I am trying to use the getPreviousToken function from 
clang-tools-extra/clang-tidy/utils/LexerUtils.cpp,
 but am having issues when the SourceLocation comes from a macro.  Let’s say I 
have the following functions:

#include 
#include 

// The macros are  defined such that KOKKOS_FUNCTION is empty and 
KOKKOS_INLINE_FUNCITON = “inline”

KOKKOS_FUNCTION
void useString(std::string const& s, int i){ }

KOKKOS_INLINE_FUNCTION
void useString2(std::string const& s, int i){ }

If I take the FunctionDecl for useString and use getBeginLoc, I will get a 
location that corresponds to the token void right before useString, I then use 
getPreviousToken to find the KOKKOS_FUNCTION macro and all is well.

But if I call getBeginLoc on useString2 my location starts off in the macro 
(I’m not really sure exactly what that means, my guess is that it starts on the 
inline keyword) and if I use that location for getPreviousToken, I don’t get 
the ‘}' from the line with useString, instead I get some location from other 
headers included in Kokkos_Core.hpp.  I don’t think that this is the intended 
behavior, but I don’t have a minimal working example at the moment. I did track 
it down to  where getPreviousToken calls getWithOffset(-1) on the source 
location and it is that new location which is the unexpected location.

Any help would be appreciated.

-Cannada Lewis

___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] Determining if a template type came from a typedef in clang-tidy

2020-04-29 Thread Lewis, Cannada via cfe-users
I have the following example: 

In a header somewhere:
namespace Kokkos {
  using DefaultHostExecutionSpace = Serial;
}

In a different header somewhere

namespace Kokkos{
template
class RangePolicy;
}

struct GoodClass {
  int foo;

  KOKKOS_INLINE_FUNCTION GoodClass(int f) : foo(f) {}
  KOKKOS_INLINE_FUNCTION void method() {
Kokkos::parallel_for(
Kokkos::RangePolicy(0, 42),
KOKKOS_LAMBDA(int i) { do_something(foo, i); });
  }
};

Once I have the CallExpr to the parallel_for I use the following matcher on it:

auto FilterArgs = hasAnyArgument(
expr(hasType(cxxRecordDecl(isDerivedFrom(cxxRecordDecl(
   matchesName("Impl::PolicyTraits" // This 
will cause it to match the first argument
 .bind("decl")))
.bind("expr"));

I am trying to detect that the template type on the RangePolicy is 
Kokkos::DefaultHostExecutionSpace and not Serial. 

My question is can I only see the typedef at the expression that constructs the 
object or can I deduce that Serial was actually the result of the typedef from 
the CXXRecordDecl? I can’t just find the typedefdecl because I only want to 
detect when it was explicitly Kokkos::DefaultHostExecutionSpace, Serial could 
come from some other context that I don’t want to match on. 

When I dump the expr from the the above matcher I get:
`-CXXTemporaryObjectExpr 0x7007f50 
'Kokkos::RangePolicy':'class 
Kokkos::RangePolicy' 'void (const 
Kokkos::RangePolicy::member_type, const 
Kokkos::RangePolicy::member_type)’

But if I dump the decl I can only see:

ClassTemplateSpecializationDecl 0x7e6eb70 
 line:94:7 class 
RangePolicy definition
|-DefinitionData pass_in_registers standard_layout trivially_copyable 
has_user_declared_ctor can_const_default_init
| |-DefaultConstructor exists non_trivial user_provided
| |-CopyConstructor trivial user_declared has_const_param 
needs_overload_resolution implicit_has_const_param
| |-MoveConstructor exists trivial user_declared
| |-CopyAssignment trivial has_const_param implicit_has_const_param
| |-MoveAssignment
| `-Destructor simple irrelevant trivial
|-public 
'Impl::PolicyTraits':'Kokkos::Impl::PolicyTraits'
|-TemplateArgument pack
| `-TemplateArgument type 'Kokkos::Serial' 

Thanks,
Drew 
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users