Error parsing C macro with __attribute__
Environment
- OS and Version: Ubuntu 22/04
- VS Code Version: 1.73.1
- C/C++ Extension Version: 1.15.0
Bug Summary and Steps to Reproduce
Bug Summary:
Steps to reproduce:
#define BYTE_ALIGNED_TEST( __Declaration__ ) __Declaration__ __attribute__((__packed__))
BYTE_ALIGNED_TEST(
typedef struct test_struct {
uint16_t i;
uint8_t j;
}) test_struct;
Expected behavior: The code compiles fine.
But Intellisense reports an error: [{ "resource": "/home/weiqj/workspace/hornet/src/core/net/cluster_lib/libertas_cluster_base.h", "owner": "C/C++: IntelliSense", "code": "79", "severity": 8, "message": "expected a type specifier", "source": "C/C++", "startLineNumber": 57, "startColumn": 1, "endLineNumber": 57, "endColumn": 18 }]
Configuration and Logs
-------- Diagnostics - 3/16/2023, 8:22:21 PM
Version: 1.15.0
Current Configuration:
{
"name": "Hornet",
"includePath": [
"/opt/gcc-arm-none-eabi-10.3-2021.10/lib/gcc/arm-none-eabi/10.3.1/include/",
"/home/weiqj/workspace/hornet/src/",
"/home/weiqj/workspace/hornet/src/FreeRTOS-Kernel/include/*",
"/home/weiqj/workspace/hornet/src/vendors/nordic/nrf5/*",
"/home/weiqj/workspace/hornet/src/vendors/nordic/nrf5/freertos-libertas/*",
"/home/weiqj/workspace/hornet/src/devices/nrf52840/dongle/switch/*",
"/opt/nRF5_SDK_17.1.0_ddde560/external/freertos/portable/ARM/nrf52/*",
"/opt/nRF5_SDK_17.1.0_ddde560/external/freertos/portable/CMSIS/nrf52/*",
"/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx",
"/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx/mdk",
"/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx/hal",
"/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx/soc",
"/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx/drivers/src",
"/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx/drivers/include",
"/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/experimental_section_vars",
"/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/strerror",
"/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/delay",
"/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/util",
"/opt/nRF5_SDK_17.1.0_ddde560/components/boards",
"/opt/nRF5_SDK_17.1.0_ddde560/integration/nrfx",
"/opt/nRF5_SDK_17.1.0_ddde560/integration/nrfx/legacy",
"/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/queue",
"/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/fifo",
"/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/log",
"/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/log/src",
"/opt/nRF5_SDK_17.1.0_ddde560/components/drivers_nrf/nrf_soc_nosd",
"/opt/nRF5_SDK_17.1.0_ddde560/components/toolchain/cmsis/include/*",
"/home/weiqj/workspace/hornet/*",
"/home/weiqj/workspace/hornet/src/platform/nordic/nrf52840/dongle"
],
"defines": [
"__GNUC__",
"NO_XERCESC",
"__XTENSA__",
"HORNET_LIBERTAS_APP_ENGINE_ENABLED=1",
"HORNET_DEVICE_TYPE=HORNET_ROUTER",
"LIBERTAS_CLUSTER_LIB_APP_SUPPORT"
],
"compilerPath": "/opt/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-arm",
"compilerArgs": [
"-mfloat-abi=hard"
],
"browse": {
"path": [
"/opt/gcc-arm-none-eabi-10.3-2021.10/lib/gcc/arm-none-eabi/10.3.1/include/",
"/opt/gcc-arm-none-eabi-10.3-2021.10/arm-none-eabi/include/",
"${workspaceFolder}/src/",
"${workspaceFolder}/src/FreeRTOS-Kernel/include/*",
"${workspaceFolder}/src/vendors/nordic/nrf5/*",
"${workspaceFolder}/src/vendors/nordic/nrf5/freertos-libertas/*",
"${workspaceFolder}/src/devices/nrf52840/dongle/switch/*",
"/opt/nRF5_SDK_17.1.0_ddde560/external/freertos/portable/ARM/nrf52/*",
"/opt/nRF5_SDK_17.1.0_ddde560/external/freertos/portable/CMSIS/nrf52/*",
"/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx",
"/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx/mdk",
"/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx/hal",
"/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx/soc",
"/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx/drivers/src",
"/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx/drivers/include",
"/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/experimental_section_vars",
"/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/strerror",
"/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/delay",
"/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/util",
"/opt/nRF5_SDK_17.1.0_ddde560/components/boards",
"/opt/nRF5_SDK_17.1.0_ddde560/integration/nrfx",
"/opt/nRF5_SDK_17.1.0_ddde560/integration/nrfx/legacy",
"/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/queue",
"/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/fifo",
"/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/log",
"/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/log/src",
"/opt/nRF5_SDK_17.1.0_ddde560/components/drivers_nrf/nrf_soc_nosd",
"/opt/nRF5_SDK_17.1.0_ddde560/components/toolchain/cmsis/include/*",
"${workspaceFolder}/*",
"${workspaceFolder}/src/platform/nordic/nrf52840/dongle"
],
"limitSymbolsToIncludedHeaders": true
},
"compilerPathIsExplicit": true,
"cStandardIsExplicit": true,
"cppStandardIsExplicit": true,
"intelliSenseModeIsExplicit": true,
"rawCompilerPath": "/opt/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc",
"mergeConfigurations": false
}
Translation Unit Mappings:
[ /home/weiqj/workspace/hornet/src/core/net/cluster_lib/libertas_cluster_impl.c ]:
/home/weiqj/workspace/hornet/src/core/net/cluster_lib/libertas_cluster_impl.c
/home/weiqj/workspace/hornet/src/core/net/cluster_lib/libertas_cluster_base.h *
Translation Unit Configurations:
[ /home/weiqj/workspace/hornet/src/core/net/cluster_lib/libertas_cluster_impl.c ]:
Process ID: 65014
Memory Usage: 854 MB
Includes:
/opt/gcc-arm-none-eabi-10.3-2021.10/lib/gcc/arm-none-eabi/10.3.1/include
/home/weiqj/workspace/hornet/src
/home/weiqj/workspace/hornet/src/FreeRTOS-Kernel/include
/home/weiqj/workspace/hornet/src/vendors/nordic/nrf5
/home/weiqj/workspace/hornet/src/vendors/nordic/nrf5/freertos-libertas
/home/weiqj/workspace/hornet/src/devices/nrf52840/dongle/switch
/opt/nRF5_SDK_17.1.0_ddde560/external/freertos/portable/ARM/nrf52
/opt/nRF5_SDK_17.1.0_ddde560/external/freertos/portable/CMSIS/nrf52
/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx
/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx/mdk
/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx/hal
/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx/soc
/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx/drivers/src
/opt/nRF5_SDK_17.1.0_ddde560/modules/nrfx/drivers/include
/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/experimental_section_vars
/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/strerror
/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/delay
/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/util
/opt/nRF5_SDK_17.1.0_ddde560/components/boards
/opt/nRF5_SDK_17.1.0_ddde560/integration/nrfx
/opt/nRF5_SDK_17.1.0_ddde560/integration/nrfx/legacy
/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/queue
/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/fifo
/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/log
/opt/nRF5_SDK_17.1.0_ddde560/components/libraries/log/src
/opt/nRF5_SDK_17.1.0_ddde560/components/drivers_nrf/nrf_soc_nosd
/opt/nRF5_SDK_17.1.0_ddde560/components/toolchain/cmsis/include
/home/weiqj/workspace/hornet
/home/weiqj/workspace/hornet/src/platform/nordic/nrf52840/dongle
/usr/include/x86_64-linux-gnu/c++/9
/usr/include/c++/9
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
Defines:
__GNUC__
NO_XERCESC
__XTENSA__
HORNET_LIBERTAS_APP_ENGINE_ENABLED=1
HORNET_DEVICE_TYPE=HORNET_ROUTER
LIBERTAS_CLUSTER_LIB_APP_SUPPORT
Standard Version: c17
IntelliSense Mode: linux-gcc-arm
Total Memory Usage: 854 MB
------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 15681
Number of files parsed: 6347
Other Extensions
No response
Additional context
No response
Normally this should work if we properly detect your compiler as being "gcc" (your logging indicates we are not). Can you try adding defines like the ones below
"__GNUC__=10",
"__GNUC_MINOR__=4",
"__GNUC_PATCHLEVEL__=0"
Normally this should work if we properly detect your compiler as being "gcc" (your logging indicates we are not). Can you try adding defines like the ones below
"__GNUC__=10", "__GNUC_MINOR__=4", "__GNUC_PATCHLEVEL__=0"
Thanks for your quick response. I added the defines. Unfortunately, it still doesn't work.
@sean-mcmanus One more question. Was my code snippet parsed correctly on your VSCode?
Yes, it works for me (even with out the defines I mentioned previously), i.e. I see
other: --gcc
other: --gnu_version=103000
but for some reason those are missing from your logging, which I believe is what is causing the __attribute__ to incorrectly not be recognized.
What shall I put into c_cpp_properties.json? I am using arm-none-eabi-gcc for embedded MCU development.
I'm not sure yet. We may be able to investigate more next week.
Appreciate your effort very much!
This is ridiculous. I removed the nordic library from the includePath, then the parser worked.
But this morning, Ubuntu automatically updated VSCode to the latest version. It no longer works, with a warning: variable "uint8_t" is not a type name.
@weiqj That sounds like a different issue (are you able to provide more info?). Updates to VS Code itself generally should not affect our extension's IntelliSense results so you should check the version of the C/C++ extension being used.
@sean-mcmanus : not sure if this is still valid, i can create a new issue if you like. Yes the uint8_t comes from intellisense not giving valid defines to all include files which are integrated into the GCC. The problem arises from these lines in stdint.h which need them:
#ifdef __UINT8_TYPE__
typedef __UINT8_TYPE__ uint8_t;
#endif
#ifdef __UINT16_TYPE__
typedef __UINT16_TYPE__ uint16_t;
#endif
#ifdef __UINT32_TYPE__
typedef __UINT32_TYPE__ uint32_t;
#endif
#ifdef __UINT64_TYPE__
typedef __UINT64_TYPE__ uint64_t;
#endif
after putting these #defines into intelisense config:
"defines": [
"__UINT_LEAST16_MAX__=65535",
"__UINT_LEAST8_TYPE__=unsigned char",
"__UINT8_MAX__=255",
"__UINT_FAST64_MAX__=18446744073709551615ULL",
"__UINT_FAST8_MAX__=4294967295U",
"__UINT_LEAST64_MAX__=18446744073709551615ULL",
"__UINT_LEAST8_MAX__=255",
"__UINTMAX_TYPE__=long long unsigned int",
"__UINT32_MAX__=4294967295UL",
"__UINT16_C(c)=c",
"__UINT16_MAX__=65535",
"__UINT8_TYPE__=unsigned char",
"__UINT64_C(c)=c ## ULL",
"__UINT_LEAST16_TYPE__=short unsigned int",
"__UINT64_MAX__=18446744073709551615ULL",
"__UINTMAX_C(c)=c ## ULL",
"__UINT_FAST32_MAX__=4294967295U",
"__UINT_LEAST64_TYPE__=long long unsigned int",
"__UINT_FAST16_TYPE__=unsigned int",
"__UINT_LEAST32_MAX__=4294967295UL",
"__UINT16_TYPE__=short unsigned int",
"__UINTPTR_MAX__=4294967295U",
"__UINT_FAST64_TYPE__=long long unsigned int",
"__UINT_LEAST32_TYPE__=long unsigned int",
"__UINT8_C(c)=c",
"__UINT64_TYPE__=long long unsigned int",
"__UINT32_C(c)=c ## UL",
"__UINT_FAST32_TYPE__=unsigned int",
"__UINTMAX_MAX__=18446744073709551615ULL",
"__UINT32_TYPE__=long unsigned int",
"__UINTPTR_TYPE__=unsigned int",
"__UINT_FAST16_MAX__=4294967295U",
"__UINT_FAST8_TYPE__=unsigned int"
],
will fix this issue.
but the attribute i also still have:
__attribute__((used, section(".requests")))
static volatile LIMINE_BASE_REVISION(2);
gives two errors: attribute -> explicit type is missing ('int' assumed)C/C++(260) static ->expected a '{'C/C++(130)
im just fiddling around with the template from here in vcode:
https://github.com/limine-bootloader/limine-c-template
you just need to run make once to get the header files (stdint etc.). after that. you can see the intellisense errors in the kernel/src/kernel.c file. compilation runs without errors.
Same issue here. Any workaround to prevent the error from showing up? Thx.