Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clangd] C++20 modules support ignores CompileFlags.Add/Remove compiling a module preamble #112635

Open
petr-polezhaev opened this issue Oct 16, 2024 · 2 comments
Labels
clang:modules C++20 modules and Clang Header Modules clangd

Comments

@petr-polezhaev
Copy link

When used with compile_commands.json clangd seem to ignore flag modifications from .clangd when (and only when) compiling module information, leading to module search issues

Given compile_commands.json:

[
    {
      "directory": "/path/to/example",
      "command": "/usr/bin/clang++ -std=c++23 -ffoobar test.cppm",
      "file": "test.cppm",
      "output": "build/test.cppm.o"
    },
    {
        "directory": "/path/to/example",
        "command": "/usr/bin/clang++ -std=c++23 -ffoobar main.cpp",
        "file": "main.cpp",
        "output": "build/main.cpp.o"
    }
  ]

.clangd:

CompileFlags:
    CompilationDatabase: "."
    Remove:
    - "-ffoobar"

test.cppm:

export module test;

export void test() {}

main.cpp:

import test;

int main() { return 0; }

Results in:
image

E[02:40:54.668] Scanning modules dependencies for /home/test/clangd_modules_test/test.cppm failed: error: unknown argument: '-ffoobar'

I[02:40:54.668] Built prerequisite modules for file /home/test/clangd_modules_test/test.cppm in 0.00 seconds
E[02:40:54.668] Scanning modules dependencies for /home/test/clangd_modules_test/main.cpp failed: error: unknown argument: '-ffoobar'

I[02:40:54.668] Built prerequisite modules for file /home/test/clangd_modules_test/main.cpp in 0.00 seconds

If I remove -ffoobar from compile_commands.json it works correctly

This breaks support for compiling with gcc (that requires -fmodule-ts and other arguments clang does not understand) and using clangd, while generating compile_commands.json with cmake. Using .clangd to remove unsupported options (and add other options needed for clang) works for the rest of the functionality but not for modules

@EugeneZelenko EugeneZelenko added clangd clang:modules C++20 modules and Clang Header Modules and removed new issue labels Oct 17, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 17, 2024

@llvm/issue-subscribers-clang-modules

Author: Petr Polezhaev (petr-polezhaev)

When used with `compile_commands.json` clangd seem to ignore flag modifications from `.clangd` when (and only when) compiling module information, leading to module search issues

Given compile_commands.json:

[
    {
      "directory": "/path/to/example",
      "command": "/usr/bin/clang++ -std=c++23 -ffoobar test.cppm",
      "file": "test.cppm",
      "output": "build/test.cppm.o"
    },
    {
        "directory": "/path/to/example",
        "command": "/usr/bin/clang++ -std=c++23 -ffoobar main.cpp",
        "file": "main.cpp",
        "output": "build/main.cpp.o"
    }
  ]

.clangd:

CompileFlags:
    CompilationDatabase: "."
    Remove:
    - "-ffoobar"

test.cppm:

export module test;

export void test() {}

main.cpp:

import test;

int main() { return 0; }

Results in:
image

E[02:40:54.668] Scanning modules dependencies for /home/test/clangd_modules_test/test.cppm failed: error: unknown argument: '-ffoobar'

I[02:40:54.668] Built prerequisite modules for file /home/test/clangd_modules_test/test.cppm in 0.00 seconds
E[02:40:54.668] Scanning modules dependencies for /home/test/clangd_modules_test/main.cpp failed: error: unknown argument: '-ffoobar'

I[02:40:54.668] Built prerequisite modules for file /home/test/clangd_modules_test/main.cpp in 0.00 seconds

If I remove -ffoobar from compile_commands.json it works correctly

This breaks support for compiling with gcc (that requires -fmodule-ts and other arguments clang does not understand) and using clangd, while generating compile_commands.json with cmake. Using .clangd to remove unsupported options (and add other options needed for clang) works for the rest of the functionality but not for modules

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 17, 2024

@llvm/issue-subscribers-clangd

Author: Petr Polezhaev (petr-polezhaev)

When used with `compile_commands.json` clangd seem to ignore flag modifications from `.clangd` when (and only when) compiling module information, leading to module search issues

Given compile_commands.json:

[
    {
      "directory": "/path/to/example",
      "command": "/usr/bin/clang++ -std=c++23 -ffoobar test.cppm",
      "file": "test.cppm",
      "output": "build/test.cppm.o"
    },
    {
        "directory": "/path/to/example",
        "command": "/usr/bin/clang++ -std=c++23 -ffoobar main.cpp",
        "file": "main.cpp",
        "output": "build/main.cpp.o"
    }
  ]

.clangd:

CompileFlags:
    CompilationDatabase: "."
    Remove:
    - "-ffoobar"

test.cppm:

export module test;

export void test() {}

main.cpp:

import test;

int main() { return 0; }

Results in:
image

E[02:40:54.668] Scanning modules dependencies for /home/test/clangd_modules_test/test.cppm failed: error: unknown argument: '-ffoobar'

I[02:40:54.668] Built prerequisite modules for file /home/test/clangd_modules_test/test.cppm in 0.00 seconds
E[02:40:54.668] Scanning modules dependencies for /home/test/clangd_modules_test/main.cpp failed: error: unknown argument: '-ffoobar'

I[02:40:54.668] Built prerequisite modules for file /home/test/clangd_modules_test/main.cpp in 0.00 seconds

If I remove -ffoobar from compile_commands.json it works correctly

This breaks support for compiling with gcc (that requires -fmodule-ts and other arguments clang does not understand) and using clangd, while generating compile_commands.json with cmake. Using .clangd to remove unsupported options (and add other options needed for clang) works for the rest of the functionality but not for modules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules clangd
Projects
None yet
Development

No branches or pull requests

3 participants