Skip to content

incorrect source location for builtin functions in the clang AST. #61839

Open
@hokein

Description

@hokein

Given the following case:

int test(unsigned __x)  { 
  return __builtin_popcount(1); // line 2
}
int test2(unsigned __x)  { 
  return __builtin_popcount(1);
}

void foo() {
  __builtin^_popcount(1ul); // calling go-to-definition in clangd will jump to line2.
}

The __builtin_popcount FunctionDecl looks like, its source location points to the first call site (line 2, col 10). The source location is suspicious (I think it should be an invalid source loc).

`-FunctionDecl 0x560139b6dd20 <col:10> col:10 implicit used __builtin_popcount 'int (unsigned int) noexcept' extern
|   |-ParmVarDecl 0x560139b6de20 <<invalid sloc>> <invalid sloc> 'unsigned int'
|   |-BuiltinAttr 0x560139b6ddc8 <<invalid sloc>> Implicit 378
|   |-NoThrowAttr 0x560139b6de90 <col:10> Implicit
|   `-ConstAttr 0x560139b6deb8 <col:10> Implicit

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions