<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Rewriter crashes when compilation database contains files with same name"
   href="https://bugs.llvm.org/show_bug.cgi?id=38270">38270</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Rewriter crashes when compilation database contains files with same name
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>6.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>hyunsu.lim01@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=20586" name="attach_20586" title="Example build system and program that I created to reproduce the bug">attachment 20586</a> <a href="attachment.cgi?id=20586&action=edit" title="Example build system and program that I created to reproduce the bug">[details]</a></span>
Example build system and program that I created to reproduce the bug

# Overview

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.


# Steps to Reproduce

1) Create the build system that generates the following
`compile_commands.json`:
```json
[
    {
        "arguments": [
            "cc",
            "-c",
            "-o",
            "a.o",
            "a.c"
        ],
        "directory": "/home/user/build_system/lib",
        "file": "a.c"
    },
    {
        "arguments": [
            "cc",
            "-c",
            "-o",
            "a.o",
            "a.c"
        ],
        "directory": "/home/user/build_system/src",
        "file": "a.c"
    }
]
```
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`.

The example build system I created is attached for reference. For detailed
description about the attachment, check # About Attachment section

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.

The example program I created is attached for reference. For detailed
description about the attachment, check # About Attachment section

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`.


# Actual Results

The program with clang libtooling shows segfault.


# Expected Results

The program with clang libtooling should run cleanly, not showing segfault.


# Tested Environment

 - OS: Ubuntu LTS 16.04 Xenial
 - LLVM Version: 6.0.1


# About Attachment

This section describes the details of attachment.

- `build_example/`: Example build system
  - `lib/`
    - `a.c`: Example c file (shorter one)
    - `Makefile`: A makefile to compile `a.c`
  - `src/`
    - `a.c`: Example c file (longer one)
    - `Makefile`: A makefile to compile `a.c`
  - `compile_commands.json`: Compilation database. This file is generated by
running the command `$ bear make`
  - `Makefile`: A makefile to build the whole example build system
- `Makefile`: A makefile to build `target.cpp`
- `target.cpp`: A program that uses clang libtooling and clang Rewriter. This
program fails when run on the given compilation database, which shouldn't


# Other Comments

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.

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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>