Skip to content

Location for ParmVarDecl with macros is incorrect. #65

@kaushikcfd

Description

@kaushikcfd

I have two files:

  1. bar.h (single-liner):
#define DEFINE_MY_FUNC(x) void bar##x(int y);
  1. foo.h (two-liner):
#include "bar.h"

DEFINE_MY_FUNC(FOO)

With clang-rs, the entity corresponding to parameters of function "barFoo" is:

Entity {
    kind: ParmDecl,
    display_name: Some(
        "y",
    ),
    location: Some(
        SourceLocation {
            file: Some(
                File {
                    path: "foo.h",
                },
            ),
            line: 2,
            column: 1,
            offset: 17,
        },
    ),
}

With clang -Xclang -ast-dump=json foo.h, we get:

        {
          "id": "0x564483c5b7a0",
          "kind": "ParmVarDecl",
          "loc": {
            "spellingLoc": {
              "offset": 42,
              "file": "./bar.h",
              "line": 1,
              "col": 43,
              "tokLen": 1,
              "includedFrom": {
                "file": "foo.h"
              }
            },
            "expansionLoc": {
              "offset": 17,
              "file": "foo.h",
              "line": 2,
              "col": 1,
              "tokLen": 14
            }
          },
          "range": {
            "begin": {
              "spellingLoc": {
                "offset": 38,
                "file": "./bar.h",
                "line": 1,
                "col": 39,
                "tokLen": 3,
                "includedFrom": {
                  "file": "foo.h"
                }
              },
              "expansionLoc": {
                "offset": 17,
                "file": "foo.h",
                "line": 2,
                "col": 1,
                "tokLen": 14
              }
            },
            "end": {
              "spellingLoc": {
                "offset": 42,
                "file": "./bar.h",
                "line": 1,
                "col": 43,
                "tokLen": 1,
                "includedFrom": {
                  "file": "foo.h"
                }
              },
              "expansionLoc": {
                "offset": 17,
                "file": "foo.h",
                "line": 2,
                "col": 1,
                "tokLen": 14
              }
            }
          },
          "name": "y",
          "type": {
            "qualType": "int"
          }
        }

Is it a bug in clang-rs or am I missing something with my invocations. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions