<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/112635>112635</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Clangd] C++20 modules support ignores CompileFlags.Add/Remove compiling a module preamble
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          petr-polezhaev
      </td>
    </tr>
</table>

<pre>
    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](https://github.com/user-attachments/assets/bf33d083-1cf8-4832-ae37-e809085375ae)

```
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
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVk2P4zYP_jXKhbDhyLHjHHLYTN682Ou2RY8L2aJt7ciSK8nJTn99IclOMotkiqJFgQKDiSzx4-EjUiSzVnQKcU-KAymOKza5Xpv9iM4ko5b4e8_wvKo1f9v_2qOCySKHi3A9kDJr9DAKiV8bPQxMcZt-s1qRMoNGMtVxsIgDOA2iU9ogtJJ1MGguWtEwJ7Sy0Bo9eEtp1PC6F--G0IopDlrJt7BB6A6iN6GCjUkiCNVqMwRLhL6ARMb9qdOLgEVmmh6EtRNakh1J9in-_784eyfPIyD5LOnX8S9-Foe4AAAg27sPAEIpFwYbp80boZTkn_wWoaeRuZ7Qk9OEnvA7G0aJ4eDlB-0ZxDvdyRpCT7VQhJ4CR4QeCD1AYh0n-bGJnzSHpG21rpkBh9alzTgOD320IjqPDj6W1ZMbJ3eTrichuQ9k0Uq1P7zj4_jOyA_8_F2G_kGOBiaUj-CJk_ckPRT-gJ5F_gE7s25xfJxcy-atGp7l4UvM25Nknb3KQNwNBXFkjtXM4owtfQflCw76jDc9AEi81MLPVfgZwFvePIeI30dt3FKKXoPkh3s7s8BZCx6PaeXL3GfN9k8Iul7Jc_diCNYf-BXKhQS4-QODbjIKMpIf4GPnX9BO0lkQ6uaYrklxEAPr0N8srXrnxnAr9EToqROun-q00UNIVTQJc441_YDKWUJPzFoMi7rNc55VebJu2irZVDlNGObbBKtsl1VFvi0YErr7gYp7iP8jxSHz6bjxtBSbtCwrUhzhp4YpdXs4LXAcUXFUjUALrTZA6KnXA87FvdQR_zorfJ13r_cOLRMSuc8uNEYbv5jUq9IXBcx0kw8upt72llTbe-ifn2A9TEI6GA0a_G0SVji8ovZAfWn-dbRCQZZmGVhstOL2X2JrydL_BFlXsA-5elgLn1v4DCa8Jb6XXrGX2bWvP50QhIOLNq8WGm18R5Bv95Z_7oWF2iB7tWCnMVSyD-g2AoQRpGsaPym4njkIDBi0EUkMLnHW-w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