[llvm-bugs] [Bug 38540] New: Incorrect include paths applied from compile_commands.json
    via llvm-bugs 
    llvm-bugs at lists.llvm.org
       
    Mon Aug 13 05:38:20 PDT 2018
    
    
  
https://bugs.llvm.org/show_bug.cgi?id=38540
            Bug ID: 38540
           Summary: Incorrect include paths applied from
                    compile_commands.json
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: pradelle at silexica.com
                CC: llvm-bugs at lists.llvm.org
Created attachment 20686
  --> https://bugs.llvm.org/attachment.cgi?id=20686&action=edit
Example reproduction for the issue
When the path to a particular include directory is passed to successive
compiler invocations using a compilation database (compile_commands.json file),
the first path is cached and reused for all invocations. When the first path in
the database is relative, it gets reused without fixing it according to the
location in which the different invocations are running. As a consequence, some
header files are reported as missing whereas they should be found.
# Reproduction
Create a source directory with source files in at least two directories of
different nesting such as:
main.c
subdirectory/src.c
include/header.h
The source files must include the header file.
Generate a compile_commands.json file such that:
 - the first command adds the "include" directory using a relative path (for
instance "-I include" for "main.c")
 - the second command adds the same "include" directory using its absolute path
Run "clang-check" with "-p path_to_compile_commands.json_directory". Notice how
the preprocessing of the second C file fails by reporting a missing header
file.
A similar example is provided as an attachment. Run it with "make" in the
directory where the Makefile is located (root directory).
# Suggested fix
It looks like the issued is caused by the caching of directory entries in
frontend/InitHeaderSearch.cpp (in AddUnmappedPath). Every directory is searched
for in a FileManager that caches all the paths seen so far, including in
previous invocations, and returns the first entry cached.
The problem is solved by making every path absolute before searching for them
in the FileManager.
-- 
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/20180813/0c0119c6/attachment.html>
    
    
More information about the llvm-bugs
mailing list