microsoft / microsoft/vscode-cpptools

Error parsing C macro with __attribute__

Open
#10,694 11 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

embedded Feature: Configuration investigate: repro Language Service
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the diagnostic from the macro in libertas_cluster_base.h while using libertas_cluster_impl.c as the translation unit and the reported GCC C17 configuration. Start by tracing how IntelliSense parses attribute in this macro form; done means the valid C code no longer reports the “expected a type specifier” error while continuing to compile successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.