[llvm-bugs] [Bug 38270] New: Rewriter crashes when compilation database contains files with same name
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Jul 22 19:15:50 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=38270
Bug ID: 38270
Summary: Rewriter crashes when compilation database contains
files with same name
Product: clang
Version: 6.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: hyunsu.lim01 at gmail.com
CC: llvm-bugs at lists.llvm.org
Created attachment 20586
--> https://bugs.llvm.org/attachment.cgi?id=20586&action=edit
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180723/9c8beed2/attachment.html>
More information about the llvm-bugs
mailing list