microsoft / microsoft/vscode-cpptools

__has_attribute(X) bad evaluation

Abierto
#10,484 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

bug Language Service Visual Studio
Lenguaje dominante
TypeScript
Estrellas
6.2k
Forks
1.7k
Merge medio
14 h 46 min
PR fusionados (30 d)
61

Descripción

Environment
  • OS and Version: Ubuntu 22.10
  • VS Code Version: e2816fe7 (snap store)
  • C/C++ Extension Version: v1.13.9
  • If using SSH remote, specify OS of remote machine: none
  • C standard : gnu17
Bug Summary and Steps to Reproduce

Bug Summary:
I'm working on a C project. I wrote something like this (actually not exactly like this, but I tried to rewrite it with the same conditionals) :

#if defined(__has_attribute) 
    #define ATTRIBUTE_CHECKING 1
#endif

#if ATTRIBUTE_CHECKING && __has_attribute(copy)
    #define ATTRIBUTE_COPY 1
#else 
    #error "Attribute copy not available"
#endif

The problem is that I configured Intellisense with linux-gcc-x64 with gcc (12.2.0), and the condition

ATTRIBUTE_CHECKING && __has_attribute(copy)

is considered false when it's supposed to be true. I made this simple test, in the same workspace, with the same settings, ... :

#include <stdio.h>
int main()
{
    printf("%d\n", __has_attribute(copy));
    return 0;
}

and it printed "1".

I also tried with attribute access, and the same issue appears.

Steps to reproduce:

  1. Just copy the macros and the main function and you'll see

Expected behavior:
I think it's supposed to be true considering my config.

NOTE
For the "logs from the language server logging", I deleted the macros detailed above and ctrl+z' them, then copied the result into the proper section, since it wasn't enabled before.

Configuration and Logs
c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/home/axel/Documents/programmation/c/FManC/test/third_party/"
            ],
            "defines": [],
            "compilerPath": "/bin/gcc",
            "cStandard": "gnu17",
            "cppStandard": "gnu++23",
            "intelliSenseMode": "linux-gcc-x64",
            "compilerArgs": [],
            "mergeConfigurations": false
        }
    ],
    "version": 4
}
C/C++: Log Diagnostics

-------- Diagnostics - 2/7/2023, 9:15:42 PM
Version: 1.13.9
Current Configuration:

{
    "name": "Linux",
    "includePath": [
        "${workspaceFolder}/**",
        "/home/axel/Documents/programmation/c/FManC/test/third_party/"
    ],
    "defines": [],
    "compilerPath": "/bin/gcc",
    "cStandard": "gnu17",
    "cppStandard": "gnu++23",
    "intelliSenseMode": "linux-gcc-x64",
    "compilerArgs": [],
    "mergeConfigurations": false,
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true
}

Translation Unit Mappings:

[ /home/axel/Documents/programmation/c/FManC/test.c ]:
    /home/axel/Documents/programmation/c/FManC/test.c
[ /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h ]:
    /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
    /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h *

Translation Unit Configurations:

[ /home/axel/Documents/programmation/c/FManC/test.c ]:
    Process ID: 41594
    Memory Usage: 107 MB
    Compiler Path: /bin/gcc
    Includes:
        /home/axel/Documents/programmation/c/FManC/test/third_party
        /usr/include/c++/12
        /usr/include/x86_64-linux-gnu/c++/12
        /usr/include/c++/12/backward
        /usr/lib/gcc/x86_64-linux-gnu/12/include
        /usr/local/include
        /usr/include/x86_64-linux-gnu
        /usr/include
    Standard Version: c++23
    IntelliSense Mode: linux-gcc-x64
    Other Flags:
        --g++
        --gnu_version=120200
[ /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h ]:
    Process ID: 42694
    Memory Usage: 107 MB
    Compiler Path: /bin/gcc
    Includes:
        /home/axel/Documents/programmation/c/FManC/test/third_party
        /usr/lib/gcc/x86_64-linux-gnu/12/include
        /usr/local/include
        /usr/include/x86_64-linux-gnu
        /usr/include
    Standard Version: c17
    IntelliSense Mode: linux-gcc-x64
    Other Flags:
        --gcc
        --gnu_version=120200
        --header_only_fallback
Total Memory Usage: 215 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 22328
Logs from the language server logging
loggingLevel: Debug
loggingLevel has changed to: Debug
cpptools/didChangeCppProperties
$/setTrace
cpptools/didChangeSettings
Enhanced Colorization is enabled.
Autocomplete is enabled.
Error squiggles are enabled.
Hover is enabled.
IntelliSense Engine = default.
$/setTrace
cpptools/didChangeSettings
Enhanced Colorization is enabled.
Autocomplete is enabled.
Error squiggles are enabled.
Hover is enabled.
IntelliSense Engine = default.
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h (id: 13161)
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/activeDocumentChange: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h
cpptools/getInlayHints: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h (id: 13162)
cpptools/getFoldingRanges: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h (id: 13163)
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h (id: 13164)
idle loop: reparsing the active document
Checking for syntax errors: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h
Queueing IntelliSense update for files in translation unit of: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
cpptools/finishUpdateSquiggles
Error squiggle count: 1
Error squiggle count: 0
Update IntelliSense time (sec): 0.254
cpptools/getSemanticTokens: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h (id: 13165)
cpptools/getSemanticTokens: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13166)
cpptools/getFoldingRanges: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h (id: 13167)
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13168)
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/activeDocumentChange: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
cpptools/getInlayHints: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13169)
cpptools/getFoldingRanges: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13170)
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13171)
idle loop: reparsing the active document
Checking for syntax errors: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
Queueing IntelliSense update for files in translation unit of: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
cpptools/finishUpdateSquiggles
Error squiggle count: 1
Update IntelliSense time (sec): 0.252
cpptools/getSemanticTokens: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13172)
cpptools/getFoldingRanges: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13173)
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13174)
cpptools/textEditorSelectionChange
textDocument/documentHighlight: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13175)
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13176)
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13177)
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13178)
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13179)
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13180)
cpptools/textEditorSelectionChange
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13181)
textDocument/didChange: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13182)
cpptools/getSemanticTokens: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13183)
cpptools/getDocumentSymbols: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13184)
cpptools/getDocumentSymbols
cpptools/getInlayHints: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13185)
Checking for syntax errors: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
  tag parsing file: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
Queueing IntelliSense update for files in translation unit of: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
sending 1 changes to server
cpptools/finishUpdateSquiggles
Error squiggle count: 3
Update IntelliSense time (sec): 2.252
cpptools/getFoldingRanges: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13186)
textDocument/didChange: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13187)
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13188)
cpptools/getSemanticTokens: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13189)
cpptools/getDocumentSymbols: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13190)
cpptools/getDocumentSymbols
cpptools/getInlayHints: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13191)
Checking for syntax errors: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
  tag parsing file: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
Queueing IntelliSense update for files in translation unit of: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
sending 1 changes to server
cpptools/finishUpdateSquiggles
Error squiggle count: 1
Update IntelliSense time (sec): 2.252
cpptools/getFoldingRanges: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13192)
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13193)
Other Extensions

No response

Additional context
Here are the kind of macros I originally had

image
image

As you can see it seems like there's no attribute access.

The simple test

image

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Reproduzca la condición en test.c utilizando la configuración de c_cpp_properties.json y compare IntelliSense con el resultado de GCC. Inspeccione el procesamiento de FMC_attributes.h y FMC_platform.h; después, verifique que __has_attribute(copy) se evalúe de forma coherente en la condición indicada y que el diagnóstico de la condición falsa ya no aparezca.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
c, vscode
Área
tooling
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.