[PATCH] D42966: Fix USR generation in the presence of #line directives or linemarkes

Mikhail Ramalho via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 2 07:19:23 PDT 2018


mikhail.ramalho added a comment.

Hi,

> I would say "yes". Let's not rely on linemarkers, unless we can explain
>  why that's a good idea.

Sounds reasonable to me, specially considering cases like rename and
find-declaration.

> Where do virtual files come from in the first place?

>From the linemarker:
https://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html

For instance:

$ cat foo.c

int f(int a);

1 "file1.c" 1
=============

int g(int b);

clang generates:

| -FunctionDecl 0x6866ff0 <foo.c:2:1, col:12> col:5 f 'int (int)' |
| `-ParmVarDecl 0x6866f30 <col:7, col:11> col:11 a 'int'          |
|

`-FunctionDecl 0x6867138 <file1.c:1:1, col:12> col:5 g 'int (int)'

  `-ParmVarDecl 0x68670b0 <col:7, col:11> col:11 b 'int'

Note that the location of f and g are different, despite being in the same
file.

The preprocessor inserts linemarkers by default:

$ clang foo.c -E

1. 1 "foo.c"
2. 1 "<built-in>" 1
3. 1 "<built-in>" 3
4. 349 "<built-in>" 3
5. 1 "<command line>" 1
6. 1 "<built-in>" 2
7. 1 "foo.c" 2

int f(int a);

1 "file1.c" 1
=============

int g(int b);

unless you call it with -P:

$ clang foo.c -E -P

int f(int a);

int g(int b);

> Repository:
> 
>   rC Clang
> 
> https://reviews.llvm.org/D42966


Repository:
  rC Clang

https://reviews.llvm.org/D42966





More information about the cfe-commits mailing list