Bug type: Language Service
Describe the bug
- Windows 10:
- Latest: 1.56
- C/C++ Extension Version: 1.4.0
- Other extensions you installed: CMake Tools (1.7.2)
A single C codebase that has 2 CMake targets/proejcts defined for it: One using CUDA and another not using it (plain C).
The same codebase is compiled to either of these depending on which target is current/active.
CUDA-related portions are within #ifdef __CUDACC__ blocks.
Compilation succeeds on both targets, producing working executables.
But the editing experience is not adjusting properly.
Switchin back and forth between targets doesn't inform the syntax highlighting and code anlysis of a CUDA target being enabled/disabled. It always just debahves as if the projects aren't using CUDA.
There is a .cu file who's #include is under an #ifdef __CUDACC__ block, and when opening it even while the CUDA target is active, none of the CUDA-specific syntax is considered properly, so is full of errors being reported visually - even though it compiles and runs just fine.
Steps to reproduce
- Start a new CUDA CMake project'
- Create a
code.h file with a #ifdef __CUDACC__ block declaring a __constant__ variable.
- Create a
cuda_code.cu file and include it into code.h under that #ifdef __CUDACC__, and add some CUDA-specific code in it.
- Include
code.h in main.cu (Add #include code.h).
- Duplicate
main.cu and rename it's file extension to just .c
- Duplicate the project definition in the
CMakeLists.txt file, renaming it to something else and making it a non-CUDA target/project (remove the CUDA term in the project() directive, as well as any target properties such as CUDA_SEPARABLE_COMPILATION), then change it's target executable to be main.c insteaf of main.cu.
- After CMake reconfigures, select the CUDA-enabled target as the active one, and open
cuda_code.cu - see how the syntax highlighting isn't working. Also open code.h and see how the #ifdef __CUDACC__ block is greyed out.
Expected behavior
The code analysis and syntax highlighting should get enabled and disabled appropriately when switchin between the CUDA vs. the non-CUDA targets.
Note: See attached animated-gif
Code sample and logs
#ifdef __CUDACC__
#ifndef NDEBUG
#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true) {
if (code != cudaSuccess) {
fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
if (abort) exit(code);
}
}
#else
#define gpuErrchk(ans) ans
#endif
#endif
-------- Diagnostics - 5/12/2021, 7:11:28 PM
Version: 1.4.0-insiders
Current Configuration:
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64",
"configurationProvider": "ms-vscode.cmake-tools",
"compilerArgs": [],
"intelliSenseModeIsExplicit": true,
"cStandardIsExplicit": true,
"cppStandardIsExplicit": true,
"compilerPathIsExplicit": true,
"browse": {
"path": [
"${workspaceFolder}/**"
],
"limitSymbolsToIncludedHeaders": true
}
}
Custom browse configuration:
{
"browsePath": [
"d:/code/c/raytracerxpu"
],
"standard": "c++14",
"compilerPath": "c:/program files (x86)/microsoft visual studio/2019/community/vc/tools/llvm/x64/bin/clang-cl.exe",
"compilerArgs": [
"-D_WINDOWS",
"-Xcompiler=\" /GR /EHsc\"",
"-Xcompiler=\"-O2 -Ob2\"",
"-DNDEBUG",
"--generate-code=arch=compute_52,code=[compute_52,sm_52]",
"-Xcompiler=-MD",
"-std=c++14"
]
}
Custom configurations:
[ D:\Code\C\RayTracerXPU\main.c ]
{
"defines": [
"WIN32",
"_WINDOWS",
"NDEBUG"
],
"includePath": [],
"compilerPath": "c:/program files (x86)/microsoft visual studio/2019/community/vc/tools/llvm/x64/bin/clang-cl.exe",
"compilerArgs": [
"/DWIN32",
"/D_WINDOWS",
"/O2",
"/Ob2",
"/DNDEBUG",
"-MD"
]
}
Translation Unit Mappings:
[ D:\Code\C\RayTracerXPU\main.c ]:
D:\CODE\C\RAYTRACERXPU\LIB\RENDER\RAYTRACER.H
D:\CODE\C\RAYTRACERXPU\LIB\CORE\TYPES.H
Translation Unit Configurations:
[ D:\Code\C\RayTracerXPU\main.c ]:
Process ID: 4504
Memory Usage: 64 MB
Compiler Path: c:/program files (x86)/microsoft visual studio/2019/community/vc/tools/llvm/x64/bin/clang-cl.exe
Includes:
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\LLVM\X64\LIB\CLANG\11.0.0\INCLUDE
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.28.29910\INCLUDE
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.28.29910\ATLMFC\INCLUDE
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\UCRT
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\SHARED
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\UM
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\WINRT
Defines:
WIN32
_WINDOWS
NDEBUG
WIN32
_WINDOWS
NDEBUG
Standard Version: c17
IntelliSense Mode: windows-clang-x64
Other Flags:
--ms_compatibility
--microsoft_version=1929
--ms_extensions
--clang
--clang_version=110000
Total Memory Usage: 64 MB
------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 4161
Screenshots

Additional context
I've also tried different settings (without success) such as:
"C_Cpp.intelliSenseEngine": "Tag Parser",
"C_Cpp.default.intelliSenseMode": "windows-clang-x64",
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
Setting to "Tag Parser" has the opposite effect: CUDA syntax seems to always be on, even when the non-CUDA project is active.
Bug type: Language Service
Describe the bug
A single C codebase that has 2 CMake targets/proejcts defined for it: One using CUDA and another not using it (plain C).
The same codebase is compiled to either of these depending on which target is current/active.
CUDA-related portions are within
#ifdef __CUDACC__blocks.Compilation succeeds on both targets, producing working executables.
But the editing experience is not adjusting properly.
Switchin back and forth between targets doesn't inform the syntax highlighting and code anlysis of a CUDA target being enabled/disabled. It always just debahves as if the projects aren't using CUDA.
There is a
.cufile who's#includeis under an#ifdef __CUDACC__block, and when opening it even while the CUDA target is active, none of the CUDA-specific syntax is considered properly, so is full of errors being reported visually - even though it compiles and runs just fine.Steps to reproduce
code.hfile with a#ifdef __CUDACC__block declaring a__constant__variable.cuda_code.cufile and include it intocode.hunder that#ifdef __CUDACC__, and add some CUDA-specific code in it.code.hinmain.cu(Add#include code.h).main.cuand rename it's file extension to just.cCMakeLists.txtfile, renaming it to something else and making it a non-CUDA target/project (remove theCUDAterm in theproject()directive, as well as any target properties such asCUDA_SEPARABLE_COMPILATION), then change it's target executable to bemain.cinsteaf ofmain.cu.cuda_code.cu- see how the syntax highlighting isn't working. Also opencode.hand see how the#ifdef __CUDACC__block is greyed out.Expected behavior
The code analysis and syntax highlighting should get enabled and disabled appropriately when switchin between the CUDA vs. the non-CUDA targets.
Note: See attached animated-gif
Code sample and logs
Configurations in
c_cpp_properties.jsonNone (default)
Logs from running
C/C++: Log Diagnosticsfrom the VS Code command paletteNothing special:
Screenshots

Additional context
I've also tried different settings (without success) such as:
Setting to "Tag Parser" has the opposite effect: CUDA syntax seems to always be on, even when the non-CUDA project is active.