<div dir="ltr"><div></div><div></div><div>This is the clang bug report. This bug report is also posted to the [Clang Bugzilla](<a href="https://bugs.llvm.org/show_bug.cgi?id=38270">https://bugs.llvm.org/show_bug.cgi?id=38270</a>)</div><div><br></div><div># Overview</div><div><br></div><div>If the compilation database contains the files with same name but different path and size, the program written using clang libtooling and clang Rewriter crashes.</div><div><br></div><div>The files that I used to reproduce the bug can be found [here](<a href="https://drive.google.com/open?id=183eG4cvORKlIWwJdPIkQlxE12riKnQaK">https://drive.google.com/open?id=183eG4cvORKlIWwJdPIkQlxE12riKnQaK</a>). Detailed description of these files are presented in **About Example Files** section.</div><div><br></div><div># Steps to Reproduce</div><div><br></div><div>1) Create the build system that generates the following `compile_commands.json`:</div><div>```json</div><div>[</div><div>    {</div><div>        "arguments": [</div><div>            "cc",</div><div>            "-c",</div><div>            "-o",</div><div>            "a.o",</div><div>            "a.c"</div><div>        ],</div><div>        "directory": "/home/user/build_system/lib",</div><div>        "file": "a.c"</div><div>    },</div><div>    {</div><div>        "arguments": [</div><div>            "cc",</div><div>            "-c",</div><div>            "-o",</div><div>            "a.o",</div><div>            "a.c"</div><div>        ],</div><div>        "directory": "/home/user/build_system/src",</div><div>        "file": "a.c"</div><div>    }</div><div>]</div><div>```</div><div>In here, the length of the content of `/home/user/build_system/src/a.c` **should be larger** than that of `/home/user/build_system/lib/a.c`.</div><div><br></div><div>2) Create a program with clang libtooling, which reads the compilation database and for every file in compilation database, does rewriting on every statement in the file.</div><div><br></div><div>3) Run the program on the created compilation database. The program runs cleanly on `lib/a.c`, but it shows segfault when processing `src/a.c`.</div><div><br></div><div><br></div><div># Actual Results</div><div><br></div><div>The program with clang libtooling shows segfault.</div><div><br></div><div><br></div><div># Expected Results</div><div><br></div><div>The program with clang libtooling should run cleanly, not showing segfault.</div><div><br></div><div><br></div><div># Tested Environment</div><div><br></div><div> - OS: Ubuntu LTS 16.04 Xenial</div><div> - LLVM Version: 6.0.1</div><div><br></div><div><br></div><div># About Example Files</div><div><br></div><div>This section describes the details of files that I [linked](<a href="https://drive.google.com/open?id=183eG4cvORKlIWwJdPIkQlxE12riKnQaK">https://drive.google.com/open?id=183eG4cvORKlIWwJdPIkQlxE12riKnQaK</a>).</div><div><br></div><div>- `build_example/`: Example build system</div><div>   - `lib/`</div><div>      - `a.c`: Example c file (shorter one)</div><div>      - `Makefile`: A makefile to compile `a.c`</div><div>   - `src/`</div><div>      - `a.c`: Example c file (longer one)</div><div>      - `Makefile`: A makefile to compile `a.c`</div><div>   - `compile_commands.json`: Compilation database. This file is generated by running the command `$ bear make`</div><div>   - `Makefile`: A makefile to build the whole example build system</div><div>- `Makefile`: A makefile to build `target.cpp`</div><div>- `target.cpp`: A program that uses clang libtooling and clang Rewriter. This program fails when run on the given compilation database, which shouldn't</div><div><br></div><div><br></div><div># Other Comments</div><div><br></div><div>I also used `clang-check` on `lib/a.c` and `src/a.c` (`$ clang-check lib/a.c src/a.c`), and it shows errors with `src/a.c` which are not actual errors.</div><div><br></div><div>I think when the `SourceManager` processes `src/a.c`, it uses the buffer that is created when processing `lib/a.c` (because it has same file name), and this causes an error.</div><div><br></div><div><br></div><div><br></div><div>Thanks.</div><div>Hyunsu Lim</div><div></div><div></div></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div dir="ltr" style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px">Best Regards,<br></div><div dir="ltr" style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px"><div>Hyunsu Lim</div></div></div></div>