Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-20231

clang code model has trouble finding clang include files when using libc++

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Fixed
    • Affects Version/s: Qt Creator 4.6.0
    • Fix Version/s: Qt Creator 4.8.0-beta1
    • Component/s: C/C++/Obj-C++ Support
    • Labels:
      None
    • Environment:
      * gentoo linux
       ** using clang 6.0 (but I had similar problems with older versions in the past)
       * qbs based project, but I think this is broken for other build tools as well

      Description

      The code model has problems finding files inside clangs resource directory (for example "stddef.h") when the project is using libc++ and a clang kit. See the attachment for a simple qbs based demo project.

      When running qt-creator with 'QT_LOGGING_RULES=qtc.clang*=true' I can see the following output:

      ignoring duplicate directory "/usr/lib64/clang/6.0.0/include"
      #include "..." search starts here:
      #include <...> search starts here:
      /tmp/QtCreator-85XTcw/clang-uiheader-GGBOmg
      /usr/lib64/clang/6.0.0/include
      /usr/include/c++/v1
      /usr/include
      End of search list.

      Libc++ includes "stddef.h" via '#include_next', but because "/usr/lib64/clang/6.0.0/include" is present before "/usr/include/c++/v1" in the search list clang can not find the file.

      Note that clang removed the include directory in the correct place because someone inserted the direcotry already at the top of the list.

      I think this happens inside qt-creator code in 'CompilerOptionsBuilder::addPredefinedHeaderPathsOptions'. As far as I can tell this is not needed with a recent clang version. Clang will add the resource directory to the search path if needed.

      To check this I rebuild qt-creator with the variable 'CLANG_RESOURCE_DIR' inside 'clang_defines.pri' changed to a non existing path - so qt-creator can not add the correct include directory anymore. Then I tried my demo project with different build configurations - they all seem to work correctly. Debug output:
      clang kit, using libc++:

      ignoring nonexistent directory ""
      #include "..." search starts here:
      #include <...> search starts here:
       /tmp/QtCreator-JdXZCP/clang-uiheader-D6ZhTl
       /usr/include/c++/v1
       /usr/lib64/clang/6.0.0/include
       /usr/include
      

      clang kit, using stdlibc++:

      ignoring nonexistent directory ""
      #include "..." search starts here:
      #include <...> search starts here:
       /tmp/QtCreator-JdXZCP/clang-uiheader-D6ZhTl
       /usr/lib64/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7
       /usr/lib64/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7/x86_64-pc-linux-gnu
       /usr/lib64/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7/backward
       /usr/lib64/clang/6.0.0/include
       /usr/include
      

      gcc kit, using stdlibc++:

      ignoring nonexistent directory ""
      #include "..." search starts here:
      #include <...> search starts here:
       /tmp/QtCreator-JdXZCP/clang-uiheader-D6ZhTl
       /usr/lib64/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7
       /usr/lib64/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7/x86_64-pc-linux-gnu
       /usr/lib64/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7/backward
       /usr/lib64/gcc/x86_64-pc-linux-gnu/7.3.0/include
       /usr/lib64/gcc/x86_64-pc-linux-gnu/7.3.0/include-fixed
       /usr/include
      

        Attachments

        1. image-2018-08-22-10-48-36-850.png
          77 kB
          Michael Smirnoff
        2. qbsClangTest.zip
          3 kB
          Christian Stoitner
        3. screenshot-1.png
          281 kB
          Michael Smirnoff

          Issue Links

          For Gerrit Dashboard: QTCREATORBUG-20231
          # Subject Branch Project Status CR V

            Activity

              People

              Assignee:
              yvvan Ivan Donchevskii
              Reporter:
              cstoitner Christian Stoitner
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes