Skip to content

Compile database does not include force-included files #4293

@anatolyburakov

Description

@anatolyburakov

Issue Type: Bug

We have a codebase that is similar to Linux kernel in that it force-includes a specific header file with every file. This is reflected in the compile database as well:

{
    "directory": "/home/anatoly/build/DPDK",
    "command": "cc -Ilib/lib@@rte_eal@sta -Ilib -I../../DPDK/lib -I. -I../../DPDK/ -Iconfig -I../../DPDK/config -Ilib/librte_eal/common/include -I../../DPDK/lib/librte_eal/common/include -I../../DPDK/lib/librte_eal/linux/eal/include -Ilib/librte_eal/common -I../../DPDK/lib/librte_eal/common -Ilib/librte_eal/common/include/arch/x86 -I../../DPDK/lib/librte_eal/common/include/arch/x86 -Ilib/librte_eal -I../../DPDK/lib/librte_eal -Ilib/librte_kvargs -I../../DPDK/lib/librte_kvargs -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O3 -include rte_config.h -Wunused-parameter -Wsign-compare -Wcast-qual -D_GNU_SOURCE -fPIC -march=native -mno-avx512f -Wno-format-truncation -DRTE_LIBEAL_USE_GETENTROPY -DALLOW_EXPERIMENTAL_API  -MD -MQ 'lib/lib@@rte_eal@sta/librte_eal_linux_eal_eal_memory.c.o' -MF 'lib/lib@@rte_eal@sta/librte_eal_linux_eal_eal_memory.c.o.d' -o 'lib/lib@@rte_eal@sta/librte_eal_linux_eal_eal_memory.c.o' -c ../../DPDK/lib/librte_eal/linux/eal/eal_memory.c",
    "file": "../../DPDK/lib/librte_eal/linux/eal/eal_memory.c"
  },

(note the -include rte_config.h in the command-line)

Yet, whenever i open the file, i get an error about pointers to incomplete type, because

  1. At the start of the file, there's an #ifdef which conditionally includes certain system headers, and the preprocessor macro it depends on is defined in rte_config.h
  2. Because rte_config.h is not included by the code analyzer, this macro is not defined, so the headers don't get included
  3. Later, some headers end up including rte_config.h, which defines the macro
  4. Later in code, some code hidden behind the same #ifdef is enabled, only this time the macro has been defined, but because of 2 the structure definitions are missing since they come from the would-be-included header

Contents of my c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/../build/${workspaceFolderBasename}/",
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_GNU_SOURCE"
            ],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c99",
            "cppStandard": "c++17",
            "intelliSenseMode": "${default}",
            "forcedInclude": [
                "${workspaceFolder}/config/rte_config.h"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": false
            },
            "compileCommands": "/home/anatoly/build/DPDK/compile_commands.json"
        }
    ],
    "version": 4
}

So, the C/C++ extension is configured to force-include that file with everything. If i remove the compileCommands, this issue is fixed. However, since compileCommands more accurately reflect how the files are built, it would be nice to have them fully working.

Extension version: 0.25.1
VS Code version: Code - Insiders 1.39.0-insider (575062278d181c075ea8dce345ab3d20a127309c, 2019-09-20T06:11:13.647Z)
OS version: Windows_NT x64 10.0.17763
Remote OS version: Linux x64 5.1.3-050103-generic

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions