vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

Code Analysis with useBuildPath=true gives 'stddef.h' file not found unless clangTidy.path is changed

Open sean-mcmanus opened this issue 2 years ago • 3 comments

If C_Cpp.codeAnalysis.clangTidy.useBuildPath is true then 'stddef.h' file not found may occur with the clang-tidy version that ships with our extension. The workaround is to set C_Cpp.codeAnalysis.clangTidy.path or possibly to launch VS Code with certain environment variables set (that works on Windows with the VS developer command prompt, but I'm not sure if there's a Linux/Mac equivalent). The problem is there is a particular clang system header include path that isn't being used. I don't know if there's a way to fix this via potentially some change to how we're building the clang-tidy binary or if we could manually locate/add the missing system include path header. I recall the missing path is something like /usr/lib/llvm-10/lib/clang/10.0.0/include -- when clang 10 is installed on the machine...it's possibly related to the fact that we build clang 14 and it's possible the issue may not repro if the matching version of the /usr/lib/llvm- is installed.

A user report is at https://github.com/microsoft/vscode-cpptools/issues/9555, but it got morphed into a bug on relative paths.

sean-mcmanus avatar Jul 12 '22 21:07 sean-mcmanus

I have the same in my current clang-tidy/cmake project. My system uses Ubuntu 20.04 with clang-tidy 10.0 installed by default. The clang-tidy from vscode gives the error:

/usr/include/wchar.h:35:10: error: 'stddef.h' file not found [clang-diagnostic-error]
#include <stddef.h>
         ^~~~~~~~~~

Then I tried to include the headers from the Ubuntu version of clang-tidy (10.0) by adding -I/usr/lib/llvm-10/lib/clang/10.0.0/include to compileCommands.json. The resulting output was to following:

/usr/lib/llvm-10/lib/clang/10.0.0/include/emmintrin.h:2374:19: error: use of undeclared identifier '__builtin_ia32_pmaxsw128' [clang-diagnostic-error]
  return (__m128i)__builtin_ia32_pmaxsw128((__v8hi)__a, (__v8hi)__b);
                  ^
/usr/lib/llvm-10/lib/clang/10.0.0/include/emmintrin.h:2394:19: error: use of undeclared identifier '__builtin_ia32_pmaxub128' [clang-diagnostic-error]
  return (__m128i)__builtin_ia32_pmaxub128((__v16qi)__a, (__v16qi)__b);
                  ^
/usr/lib/llvm-10/lib/clang/10.0.0/include/emmintrin.h:2414:19: error: use of undeclared identifier '__builtin_ia32_pminsw128' [clang-diagnostic-error]
  return (__m128i)__builtin_ia32_pminsw128((__v8hi)__a, (__v8hi)__b);
                  ^
/usr/lib/llvm-10/lib/clang/10.0.0/include/emmintrin.h:2434:19: error: use of undeclared identifier '__builtin_ia32_pminub128' [clang-diagnostic-error]
  return (__m128i)__builtin_ia32_pminub128((__v16qi)__a, (__v16qi)__b);

To "fix" the issue I had to manully add the clang-tidy-14 package via the llvm-ppa and install clang-tidy-14. By setting -I/usr/lib/llvm-14/lib/clang/14.0.6/include it worked. But I don't know if this is a good workaround, since the user must manually install the same clang-tidy version as in the vs-code extension and add more include folderes to the build.

se7kn8 avatar Aug 09 '22 18:08 se7kn8

Did you try setting C_Cpp.codeAnalysis.clangTidy.path to the one that is installed (10 or 14) without adding any extra system includes?

sean-mcmanus avatar Aug 09 '22 18:08 sean-mcmanus

Yes, forgot to mentation with C_Cpp.codeAnalysis.clangTidy.path pointing to an installed clang-tidy it worked without problems.

se7kn8 avatar Aug 09 '22 20:08 se7kn8