Skip to content

LibTooling cannot correctly find header files with the same name in different folder when running on multiple source files #54410

@PHIKN1GHT

Description

@PHIKN1GHT

If we have a/a.c:

#include "A.h"
#include "stdio.h"
extern void hello_e();
int main() {
  hello_e();
  printf("%f\n", PI);
  return 0;
}

and b/b.c:

#include "A.h"
#include <stdio.h>

void hello_e() { printf("%f\n", M_E); }

and a/aa/A.h

#define PI 3.14

and b/A.h

#include <math.h>
// to use M_E

With a simple compile_commands.json:

[
  {
    "arguments": [
      "/usr/bin/gcc",
      "-c",
      "-o",
      "b",
      "b.c"
    ],
    "directory": "/home/me/testcase/b",
    "file": "/home/me/testcase/b/b.c",
    "output": "/home/me/testcase/b/b"
  },
  {
    "arguments": [
      "/usr/bin/gcc",
      "-c",
      "-Iaa",
      "../b/b",
      "-o",
      "../test",
      "a.c"
    ],
    "directory": "/home/me/testcase/a",
    "file": "/home/me/testcase/a/a.c",
    "output": "/home/me/testcase/test"
  }
]

Check these two files with: clang-check a/a.c b/b.c
Then clang-check will complain for:

warning: ../b/b: 'linker' input unused [-Wunused-command-line-argument]
b.c:1:10: fatal error: 'A.h' file not found
#include "A.h"
         ^~~~~~~~~
1 error generated.
Error while processing testcase/b/b.c.

In which it seems failed to find the b/A.h for b/b.c.
Is this an intented behavior or just a bug? What is the correct way to use clang-check (or use libtooling) to do CTU analyze on multiple source files?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions