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

Mikhail Ramalho via cfe-commits cfe-commits at lists.llvm.org
Wed May 2 07:17:35 PDT 2018


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 "foo.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 349 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 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
>
>
>
>


-- 

Mikhail Ramalho.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180502/4bae52ab/attachment.html>


More information about the cfe-commits mailing list