microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.51k stars 1.55k forks source link

Can't get "Code Analysis Mode" to work with ESP-IDF #11982

Closed Tomblarom closed 7 months ago

Tomblarom commented 7 months ago

Environment

OS: Windows 10 22H2 VS code: 1.86.2 C/C++ extension: 1.19.2 ESP-IDF: 5.2 ESP-IDF extension: 1.7.0 Python: 3.11.4

Disclaimer

Actually, I'm not sure if this is a bug or just a dumb newbie issue, but trying to troubleshoot took already way too long. I need proper support. And I contacted ESP-IDF devs first: https://github.com/espressif/vscode-esp-idf-extension/issues/1140

Description

I'm struggeling to get the automatic "Code Analysis Mode" of C/C++ extension to work. I downloaded and installed the latest ESP-IDF v5.2 through the VS Code IDF extension and additionally did it a second time through the online-installer 2.24. With this I'm able to successfully compile. However my environment lacks live/automatic Code Analysis Mode (when I write false C/C++ code it's not beeing detected). By default its on Manual and I tried to enable "C_Cpp.codeAnalysis.clangTidy.enabled": true, but this results in random expections like this:

Error while processing C/C++(clang-diagnostic-error)
rv_utils.h(52, 5): use of undeclared identifier 'asm'
rv_utils.h(61, 5): use of undeclared identifier 'asm'
rv_utils.h(82, 5): use of undeclared identifier 'asm'
rv_utils.h(92, 12): use of undeclared identifier 'asm'
csr.h(166, 3): expanded from macro 'RV_READ_CSR'
rv_utils.h(102, 5): use of undeclared identifier 'asm'
csr.h(169, 3): expanded from macro 'RV_WRITE_CSR'
rv_utils.h(128, 5): use of undeclared identifier 'asm'
csr.h(169, 3): expanded from macro 'RV_WRITE_CSR'
rv_utils.h(150, 28): use of undeclared identifier 'asm'
csr.h(180, 3): expanded from macro 'RV_CLEAR_CSR'
rv_utils.h(152, 5): use of undeclared identifier 'asm'
csr.h(176, 3): expanded from macro 'RV_SET_CSR'
rv_utils.h(158, 28): use of undeclared identifier 'asm'
csr.h(180, 3): expanded from macro 'RV_CLEAR_CSR'
rv_utils.h(160, 5): use of undeclared identifier 'asm'
csr.h(176, 3): expanded from macro 'RV_SET_CSR'
rv_utils.h(232, 5): use of undeclared identifier 'asm'
csr.h(176, 3): expanded from macro 'RV_SET_CSR'
rv_utils.h(237, 5): use of undeclared identifier 'asm'
csr.h(180, 3): expanded from macro 'RV_CLEAR_CSR'
rv_utils.h(285, 5): use of undeclared identifier 'asm'
csr.h(169, 3): expanded from macro 'RV_WRITE_CSR'
rv_utils.h(286, 5): use of undeclared identifier 'asm'
csr.h(169, 3): expanded from macro 'RV_WRITE_CSR'
rv_utils.h(287, 5): use of undeclared identifier 'asm'
csr.h(169, 3): expanded from macro 'RV_WRITE_CSR'
rv_utils.h(288, 5): use of undeclared identifier 'asm'
csr.h(169, 3): expanded from macro 'RV_WRITE_CSR'
rv_utils.h(297, 5): use of undeclared identifier 'asm'
csr.h(169, 3): expanded from macro 'RV_WRITE_CSR'
rv_utils.h(298, 5): use of undeclared identifier 'asm'
csr.h(169, 3): expanded from macro 'RV_WRITE_CSR'
rv_utils.h(299, 5): use of undeclared identifier 'asm'
csr.h(169, 3): expanded from macro 'RV_WRITE_CSR'

I found a few issues that are related to my issue, but I can't get figure how to make their solutions work in my environment..

I tried to install the IDF Tool "Clang-Tidy" or esp-tidy, was not able to properly attach it to the C/C++ extension. I tried to change the compilerPath in c_cpp_properties.json to ${config:idf.toolsPathWin}\\tools\\esp-clang\\16.0.1-fe4f10a809\\esp-clang\\bin\\clang.exe (or clang++.exe or clang-tidy.exe), which lead to these exceptions:

Include file not found in browse.path.C/C++
'stdio.h' file not found C/C++(clang-diagnostic-error)

Steps to Reproduce

  1. Create the sample "hello_world" project and open it
  2. Install C/C++ extension (if not done already)
  3. Fix IntelliSenseEngine according to this guide
  4. Add the following to settings.json:
    "C_Cpp.codeAnalysis.runAutomatically": true,
    "C_Cpp.codeAnalysis.clangTidy.enabled": true,
  5. Now go to main.c and encounter the previously described error messages

Configuration and Logs

esp_idf_vsc_ext.log ESP-IDF.Doctor.command.log (includes verbose info, c_cpp_properties.json and launch.json)

Colengms commented 7 months ago

Hi @Tomblarom . The C/C++ extension provides a UI wrapper around clang-tidy. It does not provide code analysis directly. Unfortunately, implies its support may be limited to code that can be successfully processed by LLVM/clang.

You might consider following up with an issue against LLVM, requesting support for code intended for other compilers. Or we could perhaps make your issue a 'feature request' to replace use of clang-tidy with something that would also support additional compiler dialects.

Tomblarom commented 7 months ago

I got the hint to link the GNU toolchain. I did it by setting this in my settings.json:

"C_Cpp.codeAnalysis.clangTidy.args": ["--gcc-toolchain=\"C:\\Users\\X390\\.espressif\\tools\\riscv32-esp-elf\\esp-13.2.0_20230928\\riscv32-esp-elf\\bin\\riscv32-esp-elf-gcc.exe\""]