llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.08k stars 11.99k forks source link

[clangd] the IWYU pragma seems not work on macOS #82867

Open zhang-stephen opened 8 months ago

zhang-stephen commented 8 months ago

as title said, reproduce it with following steps:

  1. create .clangd configuration as following:
    
    ---
    CompileFlags:
    Remove: [-m*, -W*, -std=gnu*]
    CompilationDatabase: build/

If: PathMatch: .*.[ch]{1}

CompileFlags: Add: [-xc, -std=c11] Remove: [-xc++] Compiler: clang

Diagnostics: UnusedIncludes: Strict MissingIncludes: Strict

2. create `dummy.h`, its content:
```c
//dummy.h
#ifndef __DUMMY_H
#define __DUMMY_H

typedef enum {
    RED, GREEN, BLUE
} Colors;

#endif // __DUMMY_H
  1. create foo.h, just include the dummy.h, nothing else to do
  2. then clangd will raise a warning named as unused-includes, and this is expected
  3. add IWYU directive in foo.h, it looks like:
    // foo.h
    #include "dummy.h" // IWYU pragma: keep
  4. on windows, the warning of unused-includes would be suppressed, but on macOS, it CANNOT be suppressed. there is a screenshot for similiar scenario:

image

Environment: LLVM: 17.0.6 Windows: Windows 11 x64 23H2 MacOS: MacOS 14.3 Apple Silicon

llvmbot commented 8 months ago

@llvm/issue-subscribers-clangd

Author: Stephen Zhang (zhang-stephen)

as title said, reproduce it with following steps: 1. create `.clangd` configuration as following: ```yml --- CompileFlags: Remove: [-m*, -W*, -std=gnu*] CompilationDatabase: build/ --- If: PathMatch: .*\.[ch]{1} CompileFlags: Add: [-xc, -std=c11] Remove: [-xc++] Compiler: clang Diagnostics: UnusedIncludes: Strict MissingIncludes: Strict ``` 2. create `dummy.h`, its content: ```c //dummy.h #ifndef __DUMMY_H #define __DUMMY_H typedef enum { RED, GREEN, BLUE } Colors; #endif // __DUMMY_H ``` 3. create `foo.h`, just include the `dummy.h`, nothing else to do 4. then clangd will raise a warning named as `unused-includes`, and this is expected 5. add IWYU directive in `foo.h`, it looks like: ```c // foo.h #include "dummy.h" // IWYU pragma: keep ``` 6. on windows, the warning of `unused-includes` would be suppressed, but on macOS, it **CANNOT** be suppressed. there is a screenshot for similiar scenario: ![image](https://github.com/llvm/llvm-project/assets/17326718/ca2d1b9b-8695-442d-9749-59863320d170) Environment: LLVM: 17.0.6 Windows: Windows 11 x64 23H2 MacOS: MacOS 14.3 Apple Silicon
HighCommander4 commented 8 months ago

Works for me on Linux.

zhang-stephen commented 8 months ago

Works for me on Linux.

it's only reproduced on macOS. I have already tried to reproduce it in WSL ubuntu, but failed.

zhang-stephen commented 8 months ago

and I have tried // IWYU pragma: export, it does not work for me, the include line still be marked as unused.