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

Using Clang Diagnostics

Open rdlaner opened this issue 7 years ago • 6 comments

I just started using this extension and it has been working wonderfully for auto-completion. However, I am not able to get it to work for any kind of clang diagnostics. All the diagnostic settings are at their default values: // Enable diagnostic "clang.diagnostic.enable": true,

// The delay after which diagnostic starts (in millisecond) "clang.diagnostic.delay": 500,

// Tolerable size of the clang output for diagnostic "clang.diagnostic.maxBuffer": 262144,

I've also updated the clang.cflags setting to the following: "clang.cflags": ["-std=c99", "-Wall"]

Is there anything else I need to do in order to get diagnostics working? Thanks!

rdlaner avatar Apr 28 '17 17:04 rdlaner

Probably you need to determine include paths and definitions for the project. You need to create "settings.json" file like this "YOUR_PROJECT_ROOT/.vscode/settings.json".

{
	"clang.cflags":
	[
		"-DSTM32F40_41xxx",
		"-DHSE_VALUE=8000000",
		"-DARM_MATH_CM4",
		
		"-I${env.ARM_NONE_EABI_PATH}/lib/gcc/arm-none-eabi/6.3.1/include",
		"-I${env.ARM_NONE_EABI_PATH}/arm-none-eabi/include",
		"-I${workspaceRoot}/src",
		
		"-std=gnu99",
		"-Wall",
		"-fsyntax-only",
		"-Wunused-macros",
		//"-Weverything",
		"-Wno-parentheses"
	]
}

yh-sb avatar May 29 '17 10:05 yh-sb

Hi, I have added the include paths in the global user settings, but still I am not seeing any diagnostic output. I also tried adding these settings to the workspace settings file (the one you mentioned) without any change. Here are my user settings:

    "clang.cxxflags": [
    "-std=c++11",
    "-Wall",
    "-I${workspaceRoot}",
    "-I/usr/include/c++/4.2.1",
    "-I/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/"
],

Can you show me what the diagnostic output looks like? Is there a particular way to trigger it or is it triggered automatically?

rdlaner avatar May 29 '17 18:05 rdlaner

It looks like this:

yh-sb avatar May 30 '17 15:05 yh-sb

Are you using the Microsoft "C/C++" extension? I can get an output like the one you showed if I enabled the Microsoft "C/C++" extension. However, if I disable it and try just using the Clang extension, I don't see any output in the Problems tab whatsoever, even when there are known errors (ie, missing semi-colon).

rdlaner avatar May 30 '17 17:05 rdlaner

@rdlaner @r44083 @mitaki28 Hello guys,
I'm using VSCode 1.27.2. Clang diagnostic not working with arm-none-eabi-gcc, but the auto-completion works normally.

Here's the "setting.json"

{
    "files.trimTrailingWhitespace": true, // 保存时,删除每一行末尾的空格
    "editor.minimap.enabled": false, // 我个人不用minimap,就是右边那个东西
    "editor.dragAndDrop": false, // 选中文字后,可以拖动它们调整位置。我是不需要
    "editor.mouseWheelZoom": true,
    // "files.defaultLanguage": "c", // ctrl+N新建文件后默认的语言
    "editor.formatOnType": true, // 输入时就进行格式化,默认触发字符较少,分号可以触发
    "editor.snippetSuggestions": "top", // snippets代码优先显示补全
    // "code-runner.runInTerminal": true, // 设置成false会在“输出”中输出,无法输入
    // "code-runner.executorMap": {
    //     "c": "cd $dir && clang $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics --target=x86_64-w64-mingw -std=c11 && $dir$fileNameWithoutExt",
    //     "cpp": "cd $dir && clang++ $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics --target=x86_64-w64-mingw -std=c++17 && $dir$fileNameWithoutExt"
    // }, // 设置code runner的命令行
    // "code-runner.saveFileBeforeRun": true, // run code前保存
    // "code-runner.preserveFocus": true, // 若为false,run code后光标会聚焦到终端上。如果需要频繁输入数据可设为false
    // "code-runner.clearPreviousOutput": false, // 每次run code前清空属于code runner的终端消息
    "C_Cpp.clang_format_path": "D:\\OPT\\LLVM\\bin\\clang-format.exe",
    "C_Cpp.clang_format_sortIncludes": true, // 格式化时调整include的顺序(按字母排序)
    "C_Cpp.intelliSenseEngine": "Default", // 可以为Default或Tag Parser,后者较老,功能较简单。具体差别参考cpptools扩展文档
    "C_Cpp.errorSquiggles": "Disabled", // 因为有clang的lint,所以关掉
    "C_Cpp.autocomplete": "Disabled", // 因为有clang的补全,所以关掉
    "clang.executable": "D:\\OPT\\LLVM\\bin\\clang.exe",
    "clang.cflags": [ // 控制c语言静态检测的参数
        "--target=arm-none-eabi",
        "-std=c99",
        "-Wall",
        "-DUSE_HAL_DRIVER",
        "-DSTM32F446xx",
        "-I${cwd}",
        "-I${workspaceRoot}",
        "-I${workspaceRoot}/Drivers/STM32F4xx_HAL_Driver/Inc",
        "-I${workspaceRoot}/Drivers/Bsp/nrf",
        "-I${workspaceRoot}/Drivers/Bsp/IAP",
        "-I${workspaceRoot}/Drivers/CMSIS/Include",
        "-I${workspaceRoot}/Drivers/CMSIS/Device/ST/STM32F4xx/Include",
        "-I${workspaceRoot}/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy",
        "-I${workspaceRoot}/Inc",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\lib\\gcc\\arm-none-eabi\\7.3.1\\include",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\lib\\gcc\\arm-none-eabi\\7.3.1\\include-fixed",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/sys",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/newlib-nano",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/machine",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/c++/7.3.1",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/c++/7.3.1/arm-none-eabi/thumb/v7e-m/fpv4-sp/hard",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/c++/7.3.1/backward"
    ],
    "clang.cxxflags": [ // 控制c++静态检测时的参数
        "--target=arm-none-eabi",
        "-std=c++11",
        "-Wall",
        "-DUSE_HAL_DRIVER",
        "-DSTM32F446xx",
        "-I${cwd}",
        "-I${workspaceRoot}",
        "-I${workspaceRoot}/Drivers/STM32F4xx_HAL_Driver/Inc",
        "-I${workspaceRoot}/Drivers/Bsp/nrf",
        "-I${workspaceRoot}/Drivers/Bsp/IAP",
        "-I${workspaceRoot}/Drivers/CMSIS/Include",
        "-I${workspaceRoot}/Drivers/CMSIS/Device/ST/STM32F4xx/Include",
        "-I${workspaceRoot}/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy",
        "-I${workspaceRoot}/Inc",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\lib\\gcc\\arm-none-eabi\\7.3.1\\include",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\lib\\gcc\\arm-none-eabi\\7.3.1\\include-fixed",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/sys",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/newlib-nano",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/machine",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/c++/7.3.1",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/c++/7.3.1/arm-none-eabi/thumb/v7e-m/fpv4-sp/hard",
        "-I/D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/c++/7.3.1/backward"
    ],
    "clang.completion.enable": true,
    "clang.diagnostic.enable": true,
    "files.associations": {
        "main.h": "c",
        "nrf24_l01.h": "c"
    }
}

and the "c_cpp_properties.json"

{
    "configurations": [
        {
            "name": "STM32-Win32",
            "compilerPath": "arm-none-eabi-gcc.exe -mcpu=cortex-m4 -mthumb -mfloat-abi=hard",
            "includePath": [
                "${workspaceFolder}",
                "${workspaceFolder}/Drivers/STM32F4xx_HAL_Driver/Inc",
                "${workspaceFolder}/Drivers/Bsp/nrf",
                "${workspaceFolder}/Drivers/Bsp/IAP",
                "${workspaceFolder}/Drivers/CMSIS/Include",
                "${workspaceFolder}/Drivers/CMSIS/Device/ST/STM32F4xx/Include",
                "${workspaceFolder}/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy",
                "${workspaceFolder}/Inc",
                "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\lib\\gcc\\arm-none-eabi\\7.3.1\\include",
                "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\lib\\gcc\\arm-none-eabi\\7.3.1\\include-fixed",
                "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include",
                "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/sys",
                "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/newlib-nano",
                "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/machine",
                "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/c++/7.3.1",
                "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/c++/7.3.1/arm-none-eabi/thumb/v7e-m/fpv4-sp/hard",
                "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/c++/7.3.1/backward"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE",
                "USE_HAL_DRIVER",
                "STM32F446xx"
            ],
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\lib\\gcc\\arm-none-eabi\\7.3.1\\include",
                    "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\lib\\gcc\\arm-none-eabi\\7.3.1\\include-fixed",
                    "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include",
                    "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/sys",
                    "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/newlib-nano",
                    "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/machine",
                    "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/c++/7.3.1",
                    "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/c++/7.3.1/arm-none-eabi/thumb/v7e-m/fpv4-sp/hard",
                    "D:\\OPT\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin\\../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/include/c++/7.3.1/backward"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": "${workspaceRoot}/.vscode/browse.vc.db"
            },
            "cStandard": "c99",
            "cppStandard": "c++11"
        }
    ],
    "version": 4
}

diagnotic not working in the underlying pic

snipaste_2018-09-14_15-29-02

Here's the VSC extensions installed

snipaste_2018-09-14_16-20-59

How can I get it work?

thanks.

Ailikez avatar Sep 14 '18 08:09 Ailikez

Are you using the Microsoft "C/C++" extension? I can get an output like the one you showed if I enabled the Microsoft "C/C++" extension. However, if I disable it and try just using the Clang extension, I don't see any output in the Problems tab whatsoever, even when there are known errors (ie, missing semi-colon).

I'm experiencing the same problem. Have you ever solved this?

Alecton4 avatar Aug 08 '21 08:08 Alecton4