[cfe-dev] match OffsetOfExpr

Aaron Ballman via cfe-dev cfe-dev at lists.llvm.org
Fri Aug 14 07:01:19 PDT 2020


On Fri, Aug 14, 2020 at 9:48 AM Billy Araujo <billyaraujo at gmail.com> wrote:
>
> Just an update on this:
> This matcher works fine in Linux.
> When I said it didn't work, that was on Windows.

An OffsetOfExpr is only generated when parsing __builtin_offsetof, so
my guess is that the macro for offsetof is expanding to address
arithmetic for you rather than a call to __builtin_offsetof.

~Aaron

>
>
> On Fri, Aug 14, 2020 at 10:35 AM Billy Araujo <billyaraujo at gmail.com> wrote:
>>
>> Hi,
>>
>> I don't know how it should be matched, using classOf, dyn_cast, or isa.
>>
>> I tried:
>>
>> namespace
>> {
>>     AST_MATCHER(clang::Stmt, isOffsetOf) { return clang::isa<clang::OffsetOfExpr>(&Node); }
>> }
>>
>> and still doesn't match.
>>
>>
>> On Wed, Aug 12, 2020 at 7:37 PM Aaron Ballman <aaron at aaronballman.com> wrote:
>>>
>>> On Wed, Aug 12, 2020 at 1:52 PM Billy Araujo via cfe-dev
>>> <cfe-dev at lists.llvm.org> wrote:
>>> >
>>> > Anyone know how to match OffsetOfExpr?
>>> >
>>> > |-FunctionDecl 0x2484fff0298 <line:9:1, line:12:1> line:9:13 used f1 'void ()' static
>>> > | `-CompoundStmt 0x2484fff03c8 <line:10:1, line:12:1>
>>> > |   `-OffsetOfExpr 0x2484fff0390 <C:\Program Files\LLVM\lib\clang\10.0.0\include\stddef.h:104:24, col:47> 'unsigned long long'
>>> >
>>> > In clang-query if I type: m offsetOfExpr() is says: matcher not found.
>>>
>>> We don't currently expose a matcher for it, so that's why it's not
>>> found. It wouldn't be difficult to add a matcher for it, however (feel
>>> free to add me as a review if you decide to author a patch for this).
>>>
>>> ~Aaron
>>>
>>> >
>>> >
>>> > _______________________________________________
>>> > cfe-dev mailing list
>>> > cfe-dev at lists.llvm.org
>>> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


More information about the cfe-dev mailing list