microsoft / microsoft/vscode-cpptools

__has_attribute(X) bad evaluation

Offen
#10,484 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug Language Service Visual Studio
Vorherrschende Sprache
TypeScript
Sterne
6.2k
Forks
1.7k
Ø Merge
14 Std. 46 Min.
Gemergte PRs (30 T.)
61

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduzieren Sie die Bedingung in test.c unter Verwendung der Konfiguration c_cpp_properties.json und vergleichen Sie IntelliSense mit dem Ergebnis von GCC. Untersuchen Sie die Verarbeitung von FMC_attributes.h und FMC_platform.h. Überprüfen Sie anschließend, dass __has_attribute(copy) in der gemeldeten Bedingung konsistent ausgewertet wird und dass die Diagnose für die falsche Bedingung nicht mehr erscheint.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
c, vscode
Bereich
tooling
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.