microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.53k stars 1.55k forks source link

Add IntelliSense modes for MPLAB (XC8/XC16/XC32) compilers #8533

Open DanieleNardi opened 2 years ago

DanieleNardi commented 2 years ago

Bug type: Language Service

uint16_t type unrecognized with xc16 compiler

It's a small prject developed with Microchip's dsPIC33EP128MC502. An error message as follows appears when a uint16_t type is used:

"[{
    "resource": "main.c",
    "owner": "C/C++",
    "code": "757",
    "severity": 8,
    "message": "variable \"uint16_t\" is not a type name",
    "source": "C/C++",
    "startLineNumber": 230,
    "startColumn": 1,
    "endLineNumber": 230,
    "endColumn": 2
}]

Error squiggle only under the 'u' of uint16_t. Hover window shows correct definition of type. CTRL+Click works, redirect to compiler-specific stdint.h, where uint16_t is defined as follows:

#ifndef uint16_t
typedef unsigned int uint16_t;
#define uint16_t uint16_t
#define UINT16_MAX (65535U)
#endif

Other types defined in stdint.h in the same way work fine. Simple call to compiler (from Microchip's IDE or command line) doesn't show this error.

Steps to reproduce Create c file, .c extension, including stdint.h. Declare a uint16_t variable in .c file.

Expected behavior No error at all.

Code sample and logs

Screenshots

Additional context

sean-mcmanus commented 2 years ago

Can you provide the log from running the C/C++: Log Diagnostics command after opening the simplest repro file? It's possible there's some issue with the includePath, defines, or compilerArgs that end up getting used.

DanieleNardi commented 2 years ago
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/activeDocumentChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/getCodeActions: /path/to/file/ApplicationFW/nvdata.c (id: 811)
idle loop: reparsing the active document
Checking for syntax errors: /path/to/file/ApplicationFW/nvdata.c
Queueing IntelliSense update for files in translation unit of: /path/to/file/ApplicationFW/nvdata.c
cpptools/finishUpdateSquiggles
Error squiggle count: 1
Update IntelliSense time (sec): 0.265
cpptools/getSemanticTokens: /path/to/file/ApplicationFW/nvdata.c (id: 812)
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 813)
cpptools/getCodeActions: /path/to/file/ApplicationFW/nvdata.c (id: 814)
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 815)
cpptools/getSemanticTokens: /path/to/file/ApplicationFW/nvdata.c (id: 816)
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 817)
cpptools/getDocumentSymbols: /path/to/file/ApplicationFW/nvdata.c (id: 818)
cpptools/getDocumentSymbols
Checking for syntax errors: /path/to/file/ApplicationFW/nvdata.c
  tag parsing file: /path/to/file/ApplicationFW/nvdata.c
Queueing IntelliSense update for files in translation unit of: /path/to/file/ApplicationFW/nvdata.c
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
textDocument/completion: /path/to/file/ApplicationFW/nvdata.c (id: 819)
auto_complete::handle_completion: file:///path/to/file/ApplicationFW/nvdata.c (17:2)
Offering completion
sending 1 changes to server
sending 1 changes to server
sending 1 changes to server
cpptools/finishUpdateSquiggles
Error squiggle count: 2
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
textDocument/completion: /path/to/file/ApplicationFW/nvdata.c (id: 820)
auto_complete::handle_completion: file:///path/to/file/ApplicationFW/nvdata.c (17:3)
Offering completion
sending 1 changes to server
cpptools/getSemanticTokens: /path/to/file/ApplicationFW/nvdata.c (id: 821)
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 822)
cpptools/getCodeActions: /path/to/file/ApplicationFW/nvdata.c (id: 823)
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 824)
cpptools/getCodeActions: /path/to/file/ApplicationFW/nvdata.c (id: 825)
cpptools/getDocumentSymbols: /path/to/file/ApplicationFW/nvdata.c (id: 826)
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 827)
cpptools/getCodeActions: /path/to/file/ApplicationFW/nvdata.c (id: 828)
cpptools/getDocumentSymbols: /path/to/file/ApplicationFW/nvdata.c (id: 829)
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
completionItem/resolve (id: 830)
sending 1 changes to server
sending 1 changes to server
sending 1 changes to server
sending 1 changes to server
sending 1 changes to server
sending 1 changes to server
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 831)
cpptools/getCodeActions: /path/to/file/ApplicationFW/nvdata.c (id: 832)
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 833)
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 834)
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 835)
cpptools/getCodeActions: /path/to/file/ApplicationFW/nvdata.c (id: 836)
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 837)
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 838)
cpptools/getCodeActions: /path/to/file/ApplicationFW/nvdata.c (id: 839)
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 840)
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 841)
cpptools/getCodeActions: /path/to/file/ApplicationFW/nvdata.c (id: 842)
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 843)
cpptools/getCodeActions: /path/to/file/ApplicationFW/nvdata.c (id: 844)
textDocument/didChange: /path/to/file/ApplicationFW/nvdata.c
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 845)
cpptools/getCodeActions: /path/to/file/ApplicationFW/nvdata.c (id: 846)
idle loop: reparsing the active document
Checking for syntax errors: /path/to/file/ApplicationFW/nvdata.c
Queueing IntelliSense update for files in translation unit of: /path/to/file/ApplicationFW/nvdata.c
cpptools/getDocumentSymbols: /path/to/file/ApplicationFW/nvdata.c (id: 847)
sending 1 changes to server
sending 1 changes to server
sending 1 changes to server
sending 1 changes to server
sending 1 changes to server
sending 1 changes to server
sending 1 changes to server
sending 1 changes to server
sending 1 changes to server
sending 1 changes to server
sending 1 changes to server
sending 1 changes to server
sending 1 changes to server
sending 1 changes to server
cpptools/finishUpdateSquiggles
Error squiggle count: 2
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 848)
cpptools/getCodeActions: /path/to/file/ApplicationFW/nvdata.c (id: 849)
cpptools/getSemanticTokens: /path/to/file/ApplicationFW/nvdata.c (id: 850)
Checking for syntax errors: /path/to/file/ApplicationFW/nvdata.c
  tag parsing file: /path/to/file/ApplicationFW/nvdata.c
Queueing IntelliSense update for files in translation unit of: /path/to/file/ApplicationFW/nvdata.c
cpptools/finishUpdateSquiggles
Error squiggle count: 2
Update IntelliSense time (sec): 14.566
cpptools/getSemanticTokens: /path/to/file/ApplicationFW/nvdata.c (id: 851)
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 852)
cpptools/getCodeActions: /path/to/file/ApplicationFW/nvdata.c (id: 853)
cpptools/getDocumentSymbols
cpptools/getDocumentSymbols
cpptools/getDocumentSymbols
willSaveWaitUntil: 0ms
textDocument/didSave: /path/to/file/ApplicationFW/nvdata.c
  tag parsing file: /path/to/file/ApplicationFW/nvdata.c
cpptools/fileChanged: /path/to/file/ApplicationFW/nvdata.c
idle loop: reparsing the active document
Checking for syntax errors: /path/to/file/ApplicationFW/nvdata.c
Queueing IntelliSense update for files in translation unit of: /path/to/file/ApplicationFW/nvdata.c
cpptools/finishUpdateSquiggles
Error squiggle count: 2
Update IntelliSense time (sec): 0.255
cpptools/getSemanticTokens: /path/to/file/ApplicationFW/nvdata.c (id: 855)
cpptools/getFoldingRanges: /path/to/file/ApplicationFW/nvdata.c (id: 856)
cpptools/getCodeActions: /path/to/file/ApplicationFW/nvdata.c (id: 857)
textDocument/hover: /path/to/file/ApplicationFW/nvdata.c (id: 858)
cpptools/getCodeActions: /path/to/file/ApplicationFW/nvdata.c (id: 859)
cpptools/getCodeActions: /path/to/file/ApplicationFW/nvdata.c (id: 860)
cpptools/getCodeActions: /path/to/file/ApplicationFW/nvdata.c (id: 861)

Source code is

#include <nvdata.h>
#include <stdint.h>

NV_DATA nvdata;

void loadFromNv()
{

}

uint8_t nvdata_get_disp_current()
{
    return nvdata.Disp_current;
}

uint16_t myNumber = 0;

uint16_t nvdata_get_number()
{
    return 0;
}

Screenshot of squiggle image

Hover output

#define uint16_t uint16_t
Expands to:

uint16_t
variable "uint16_t" is not a type nameC/C++(757)
DanieleNardi commented 2 years ago

Last but not least, compiler is xc16 v1.70

sean-mcmanus commented 2 years ago

You provided the wrong logging -- can you provide the logging from running the C/C++: Log Diagnostics command (output in the C/C++ Diagnostics pane)?

DanieleNardi commented 2 years ago

Is this the correct one?

-------- Diagnostics - 12/14/2021, 7:00:49 PM
Version: 1.8.0-insiders2
Current Configuration:
{
    "name": "Cage Heater Application",
    "includePath": [
        "${workspaceFolder}/ApplicationFW",
        "/xc16/include",
        "/opt/microchip/xc16/v1.70/include",
        "/xc16/include/lega-c",
        "/xc16/support/generic/h"
    ],
    "defines": [],
    "compilerPath": "/xc16/bin/xc16-gcc",
    "cStandard": "c99",
    "intelliSenseMode": "linux-gcc-x86",
    "compilerArgs": [
        "-c",
        "-include ${workspaceFolder}/ApplicationFW/Microchip/packs/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/support/dsPIC33E/h/p33EP128MC502.h",
        "-mcpu=33EP128MC502",
        "-MP",
        "-MMD",
        "-mno-eds-warn",
        "-g",
        "-omf=elf",
        "-legacy-libc",
        "-O0",
        "-msmart-io=1",
        "-Wall",
        "-msfr-warn=off",
        "-mdfp=\"${workspaceFolder}/ApplicationFW/Microchip/packs/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16\""
    ],
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": false,
    "intelliSenseModeIsExplicit": true,
    "mergeConfigurations": false,
    "browse": {
        "path": [
            "${workspaceFolder}/ApplicationFW",
            "/xc16/include",
            "/opt/microchip/xc16/v1.70/include",
            "/xc16/include/lega-c",
            "/xc16/support/generic/h",
            "${workspaceFolder}"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Translation Unit Mappings:
[ /path/to/file/ApplicationFW/nvdata.c ]:
    /path/to/file/ApplicationFW/nvdata.c
    /path/to/file/ApplicationFW/mcc_generated_files/i2c1.h *
    /path/to/file/ApplicationFW/nvdata.h *
    /path/to/file/ApplicationFW/Microchip/packs/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/support/dsPIC33E/h/p33EP128MC502.h *
[ /path/to/file/ApplicationFW/main.c ]:
    /path/to/file/ApplicationFW/main.c
    /path/to/file/ApplicationFW/mcc_generated_files/i2c1.h
    /path/to/file/ApplicationFW/nvdata.h
    /path/to/file/ApplicationFW/Microchip/packs/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/support/dsPIC33E/h/p33EP128MC502.h
[ /path/to/file/ApplicationFW/mcc_generated_files/system.c ]:
    /path/to/file/ApplicationFW/mcc_generated_files/system.c
    /path/to/file/ApplicationFW/mcc_generated_files/i2c1.h
    /path/to/file/ApplicationFW/Microchip/packs/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/support/dsPIC33E/h/p33EP128MC502.h
[ /path/to/file/ApplicationFW/mcc_generated_files/i2c1.c ]:
    /path/to/file/ApplicationFW/mcc_generated_files/i2c1.c
    /path/to/file/ApplicationFW/mcc_generated_files/i2c1.h
    /path/to/file/ApplicationFW/Microchip/packs/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/support/dsPIC33E/h/p33EP128MC502.h
Translation Unit Configurations:
[ /path/to/file/ApplicationFW/nvdata.c ]:
    Process ID: 1433
    Memory Usage: 255 MB
    Compiler Path: /xc16/bin/xc16-gcc
    Includes:
        /path/to/file/ApplicationFW
        /opt/microchip/xc16/v1.70/include
        /path/to/file/ApplicationFW/Microchip/packs/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/support/generic/h
        /path/to/file/ApplicationFW/Microchip/packs/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/support/dsPIC33E/h
        /opt/microchip/xc16/v1.70/include/lega-c
        /opt/microchip/xc16/v1.70/support/generic/h
        /opt/microchip/xc16/v1.70/support/dsPIC33E/h
    Standard Version: c99
    IntelliSense Mode: linux-gcc-x86
    Other Flags:
        --gcc
        --gnu_version=40501
[ /path/to/file/ApplicationFW/main.c ]:
    Process ID: 14769
    Memory Usage: 213 MB
    Compiler Path: /xc16/bin/xc16-gcc
    Includes:
        /path/to/file/ApplicationFW
        /opt/microchip/xc16/v1.70/include
        /path/to/file/ApplicationFW/Microchip/packs/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/support/generic/h
        /path/to/file/ApplicationFW/Microchip/packs/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/support/dsPIC33E/h
        /opt/microchip/xc16/v1.70/include/lega-c
        /opt/microchip/xc16/v1.70/support/generic/h
        /opt/microchip/xc16/v1.70/support/dsPIC33E/h
    Standard Version: c99
    IntelliSense Mode: linux-gcc-x86
    Other Flags:
        --gcc
        --gnu_version=40501
[ /path/to/file/ApplicationFW/mcc_generated_files/system.c ]:
    Process ID: 14942
    Memory Usage: 187 MB
    Compiler Path: /xc16/bin/xc16-gcc
    Includes:
        /path/to/file/ApplicationFW
        /opt/microchip/xc16/v1.70/include
        /path/to/file/ApplicationFW/Microchip/packs/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/support/generic/h
        /path/to/file/ApplicationFW/Microchip/packs/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/support/dsPIC33E/h
        /opt/microchip/xc16/v1.70/include/lega-c
        /opt/microchip/xc16/v1.70/support/generic/h
        /opt/microchip/xc16/v1.70/support/dsPIC33E/h
    Standard Version: c99
    IntelliSense Mode: linux-gcc-x86
    Other Flags:
        --gcc
        --gnu_version=40501
[ /path/to/file/ApplicationFW/mcc_generated_files/i2c1.c ]:
    Process ID: 28645
    Memory Usage: 200 MB
    Compiler Path: /xc16/bin/xc16-gcc
    Includes:
        /path/to/file/ApplicationFW
        /opt/microchip/xc16/v1.70/include
        /path/to/file/ApplicationFW/Microchip/packs/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/support/generic/h
        /path/to/file/ApplicationFW/Microchip/packs/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/support/dsPIC33E/h
        /opt/microchip/xc16/v1.70/include/lega-c
        /opt/microchip/xc16/v1.70/support/generic/h
        /opt/microchip/xc16/v1.70/support/dsPIC33E/h
    Standard Version: c99
    IntelliSense Mode: linux-gcc-x86
    Other Flags:
        --gcc
        --gnu_version=40501
Total Memory Usage: 855 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 4352
sean-mcmanus commented 2 years ago

It appears we're not able to query the compilerPath for system includes and defines and it's discarding the compilerArgs, so your forced include -include ${workspaceFolder}/ApplicationFW/Microchip/packs/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/support/dsPIC33E/h/p33EP128MC502.h is not being used. If you check your normal C/C++ logging with the C_Cpp.loggingLevel set to "Debug" you should see some messages about the compiler querying failing after opening the workspace. You should be able to use the forcedInclude property to set your forced include instead. Is your compiler really based on gcc version 4.5.1?

Are your include paths correct? Where does stdint.h exist?

        /path/to/file/ApplicationFW
        /opt/microchip/xc16/v1.70/include
        /path/to/file/ApplicationFW/Microchip/packs/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/support/generic/h
        /path/to/file/ApplicationFW/Microchip/packs/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/support/dsPIC33E/h
        /opt/microchip/xc16/v1.70/include/lega-c
        /opt/microchip/xc16/v1.70/support/generic/h
        /opt/microchip/xc16/v1.70/support/dsPIC33E/h

i.e. do they match what your compiler uses as it's default? Are you able to run /xc16/bin/xc16-gcc -Wp,-v -E -dD -x c /dev/null to get your system includes/defines? If not, you should set your compilerPath to "" and try to manually specify the includes/defines.

Colengms commented 2 years ago

@sean-mcmanus Is this a duplicate of https://github.com/microsoft/vscode-cpptools/issues/7534 ?

sean-mcmanus commented 2 years ago

Well, that explains the compiler query failing. Not sure if it's possible to workaround that to get uint16_t to be detected.

DanieleNardi commented 2 years ago

You should be able to use the forcedInclude property to set your forced include instead.

Done, but issue still here.

Is your compiler really based on gcc version 4.5.1?

Edit: it says yes when you launch /xc16/bin/xc16-gcc -v:

Microchip Language Tool Shell Version 1.70 (Build date: Mar  2 2021).
Copyright (c) 2012-2017 Microchip Technology Inc. All rights reserved
Using built-in specs.
COLLECT_GCC=/xc16/bin/bin/elf-gcc
Target: pic30-elf
Configured with: /home/xc16/release-builds/build_20210302/src/XC_GCC/gcc/configure --build=x86_64-linux --target=pic30-elf --disable-lto --disable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --disable-hosted-libstdcxx --with-gnu-as --with-gnu-ld --enable-languages=c --disable-nls --disable-libgomp --without-headers --disable-libffi --disable-bootstrap --prefix=/bin --libexecdir=/bin --program-prefix=pic30- --with-libelf=/home/xc16/release-builds/build_20210302/bin/XC_GCC-elf-linux64-xclm/host-libs/ --with-dwarf2 --with-gmp=/home/xc16/release-builds/build_20210302/bin/XC_GCC-elf-linux64-xclm/host-libs --with-ppl=/home/xc16/release-builds/build_20210302/bin/XC_GCC-elf-linux64-xclm/host-libs --with-cloog=/home/xc16/release-builds/build_20210302/bin/XC_GCC-elf-linux64-xclm/host-libs --with-zlib=/home/xc16/release-builds/build_20210302/bin/XC_GCC-elf-linux64-xclm/host-libs --with-bugurl=https://www.microchip.com/technical-support --with-host-libstdcxx=
Thread model: single
gcc version 4.5.1 (XC16, Microchip v1.70) Build date: Mar  2 2021 (Microchip Technology)

Are your include paths correct? Where does stdint.h exist?

Include paths look fine. stdint.h is in /opt/microchip/xc16/v1.70/include

Are you able to run /xc16/bin/xc16-gcc -Wp,-v -E -dD -x c /dev/null to get your system includes/defines?

Yes, I am. Output is the following:

Microchip Language Tool Shell Version 1.70 (Build date: Mar  2 2021).
Copyright (c) 2012-2017 Microchip Technology Inc. All rights reserved
ignoring nonexistent directory "/opt/microchip/xc16/v1.70/bin/bin/../pic30-elf/4.5.1/include"
ignoring nonexistent directory "/opt/microchip/xc16/v1.70/bin/bin/../pic30-elf/4.5.1/include-fixed"
ignoring nonexistent directory "/opt/microchip/xc16/v1.70/bin/bin/../pic30-elf/4.5.1/../../../../pic30-elf/sys-include"
ignoring nonexistent directory "/opt/microchip/xc16/v1.70/bin/bin/../pic30-elf/4.5.1/../../../../pic30-elf/include"
ignoring nonexistent directory "/bin/lib/gcc/pic30-elf/4.5.1/include"
ignoring nonexistent directory "/bin/lib/gcc/pic30-elf/4.5.1/include-fixed"
ignoring nonexistent directory "/bin/pic30-elf/sys-include"
ignoring nonexistent directory "/bin/pic30-elf/include"
#include "..." search starts here:
#include <...> search starts here:
 /opt/microchip/xc16/v1.70/bin/bin/../../include/lega-c
 /opt/microchip/xc16/v1.70/bin/bin/../../support/generic/h
End of search list.
# 1 "/dev/null"
# 1 "<built-in>"
#define __STDC__ 1
#define __STDC_HOSTED__ 1
#define __GNUC__ 4
#define __GNUC_MINOR__ 5
#define __GNUC_PATCHLEVEL__ 1
#define __SIZE_TYPE__ unsigned int
#define __PTRDIFF_TYPE__ int
#define __WCHAR_TYPE__ short unsigned int
#define __WINT_TYPE__ unsigned int
#define __INTMAX_TYPE__ long long int
#define __UINTMAX_TYPE__ long long unsigned int
#define __CHAR16_TYPE__ short unsigned int
#define __CHAR32_TYPE__ unsigned int
#define __GXX_ABI_VERSION 1002
#define __USING_SJLJ_EXCEPTIONS__ 1
#define __SCHAR_MAX__ 127
#define __SHRT_MAX__ 32767
#define __INT_MAX__ 32767
#define __LONG_MAX__ 2147483647L
#define __LONG_LONG_MAX__ 9223372036854775807LL
#define __WCHAR_MAX__ 65535U
#define __WCHAR_MIN__ 0U
#define __WINT_MAX__ 65535U
#define __WINT_MIN__ 0U
#define __PTRDIFF_MAX__ 32767
#define __SIZE_MAX__ 65535U
#define __CHAR_BIT__ 8
#define __INTMAX_MAX__ 9223372036854775807LL
#define __INTMAX_C(c) c ## LL
#define __UINTMAX_MAX__ 18446744073709551615ULL
#define __UINTMAX_C(c) c ## ULL
#define __FLT_EVAL_METHOD__ 0
#define __DEC_EVAL_METHOD__ 2
#define __FLT_RADIX__ 2
#define __FLT_MANT_DIG__ 24
#define __FLT_DIG__ 6
#define __FLT_MIN_EXP__ (-125)
#define __FLT_MIN_10_EXP__ (-37)
#define __FLT_MAX_EXP__ 128
#define __FLT_MAX_10_EXP__ 38
#define __FLT_MAX__ 3.4028234663852886e+38F
#define __FLT_MIN__ 1.1754943508222875e-38F
#define __FLT_EPSILON__ 1.1920928955078125e-7F
#define __FLT_DENORM_MIN__ 1.4012984643248171e-45F
#define __FLT_HAS_DENORM__ 1
#define __FLT_HAS_INFINITY__ 1
#define __FLT_HAS_QUIET_NAN__ 1
#define __DBL_MANT_DIG__ 24
#define __DBL_DIG__ 6
#define __DBL_MIN_EXP__ (-125)
#define __DBL_MIN_10_EXP__ (-37)
#define __DBL_MAX_EXP__ 128
#define __DBL_MAX_10_EXP__ 38
#define __DBL_MAX__ ((double)3.4028234663852886e+38L)
#define __DBL_MIN__ ((double)1.1754943508222875e-38L)
#define __DBL_EPSILON__ ((double)1.1920928955078125e-7L)
#define __DBL_DENORM_MIN__ ((double)1.4012984643248171e-45L)
#define __DBL_HAS_DENORM__ 1
#define __DBL_HAS_INFINITY__ 1
#define __DBL_HAS_QUIET_NAN__ 1
#define __LDBL_MANT_DIG__ 53
#define __LDBL_DIG__ 15
#define __LDBL_MIN_EXP__ (-1021)
#define __LDBL_MIN_10_EXP__ (-307)
#define __LDBL_MAX_EXP__ 1024
#define __LDBL_MAX_10_EXP__ 308
#define __DECIMAL_DIG__ 17
#define __LDBL_MAX__ 1.7976931348623157e+308L
#define __LDBL_MIN__ 2.2250738585072014e-308L
#define __LDBL_EPSILON__ 2.2204460492503131e-16L
#define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L
#define __LDBL_HAS_DENORM__ 1
#define __LDBL_HAS_INFINITY__ 1
#define __LDBL_HAS_QUIET_NAN__ 1
#define __DEC32_MANT_DIG__ 7
#define __DEC32_MIN_EXP__ (-94)
#define __DEC32_MAX_EXP__ 97
#define __DEC32_MIN__ 1E-95DF
#define __DEC32_MAX__ 9.999999E96DF
#define __DEC32_EPSILON__ 1E-6DF
#define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF
#define __DEC64_MANT_DIG__ 16
#define __DEC64_MIN_EXP__ (-382)
#define __DEC64_MAX_EXP__ 385
#define __DEC64_MIN__ 1E-383DD
#define __DEC64_MAX__ 9.999999999999999E384DD
#define __DEC64_EPSILON__ 1E-15DD
#define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD
#define __DEC128_MANT_DIG__ 34
#define __DEC128_MIN_EXP__ (-6142)
#define __DEC128_MAX_EXP__ 6145
#define __DEC128_MIN__ 1E-6143DL
#define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL
#define __DEC128_EPSILON__ 1E-33DL
#define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL
#define __REGISTER_PREFIX__ 
#define __USER_LABEL_PREFIX__ _
#define __VERSION__ "4.5.1 (XC16, Microchip v1.70) Build date: Mar  2 2021"
#define __GNUC_GNU_INLINE__ 1
#define __NO_INLINE__ 1
#define __FINITE_MATH_ONLY__ 0
#define __PRAGMA_REDEFINE_EXTNAME 1
#define __SIZEOF_INT__ 2
#define __SIZEOF_LONG__ 4
#define __SIZEOF_LONG_LONG__ 8
#define __SIZEOF_SHORT__ 2
#define __SIZEOF_FLOAT__ 4
#define __SIZEOF_DOUBLE__ 4
#define __SIZEOF_LONG_DOUBLE__ 8
#define __SIZEOF_SIZE_T__ 2
#define __SIZEOF_WCHAR_T__ 2
#define __SIZEOF_WINT_T__ 2
#define __SIZEOF_PTRDIFF_T__ 2
#define __SIZEOF_POINTER__ 2
#define __OPTIMIZATION_LEVEL__ 0
#define __LARGE_ARRAYS__ 0
#define __BUILTIN_ITTYPE 1
#define __C30_VERSION__ 1070
#define __XC16_VERSION 1070
#define __XC16_VERSION__ 1070
#define __XC__ 1
#define __XC16 1
#define __C30 1
#define __dsPIC30 1
#define __C30__ 1
#define __XC16__ 1
#define __dsPIC30__ 1
#define __XC16ELF 1
#define __C30ELF 1
#define __dsPIC30ELF 1
#define __C30ELF__ 1
#define __XC16ELF__ 1
#define __dsPIC30ELF__ 1
#define C30 1
#define XC16 1
#define dsPIC30 1
#define __HAS_DSP__ 1
#define __BIGGEST_ALIGNMENT__ 2
# 1 "<command-line>"
# 1 "/dev/null"

Just to be clear, /xc16 is a link to /opt/microchip/xc16/v1.70

Colengms commented 2 years ago

Hi @DanieleNardi . Forgive me if I've missed something, but I'm not able to reproduce this issue. I've installed xc16 onto Ubuntu 20.04, via WSL 2. I've configured the C/C++ extension identically to you (except did not use a /xc16 symlink, and did not include the paths or forced include from your workspace, which I do not have). The following code does not result in any squiggles with 1.8.0-insiders2:

#include <stdint.h>

int main()
{
    uint16_t i = 10;
    return 0;
}

Note that stdint.h is required for the definition of uint16_t. It is not a built-in type. If I move stdint.h to a forcedInclude instead of including it directly in the source file, that works for me as well.

Control-click may work regardless, as that feature spans all tag-parsed source files, not just headers included in the current translation unit.

If you still see an issue here in the C/C++ extension itself, could you provide a reduced example that we could use to reproduce the issue? (Perhaps in the form of a GitHub repo?)

DanieleNardi commented 2 years ago

Hi, I created a repo which replicates the issue, here. Looks like it depends on the inclusion of device's include files:

#include <stdint.h>
#include <xc.h>

int main()
{
    int pippo = 0;
    uint16_t myNumber = 0;

    myNumber++;
}

If you remove the xc.h inclusion, uint16_t is recognized properly.

Colengms commented 2 years ago

Hi @DanieleNardi . Thanks. I can repro now.

I've been able to narrow down the repro a bit. It appears to be a result of the following statement (or one like it), in one of the XC16 headers:

extern __attribute__((space(prog))) __prog__ uint16_t _FICD;

Because IntelliSense is not knowledgeable of the __prog__ keyword, it's interpreting this as declaring a variable with the name uint16_t. The error you are seeing is referring to this not being a type name, because it thinks there is now a variable of the same name that takes precedence.

I'm not finding a lot of documentation on the __prog__ keyword on the web. Is it specific to XC16? We could convert this to a request to add support for __prog__. Though, since we don't officially support an IntelliSense mode for XC16, a better request might be to add an IntelliSense mode for XC16 (or for the family of compilers that require support for __prog__).

Colengms commented 2 years ago

You can also work around the issue by adding the following to your defines in c_cpp_properties.json: "__prog__="

Let me know if you'd like to turn this into a feature request, or close.

DanieleNardi commented 2 years ago

I think it could be useful to add support of XCxx compilers family, so let's proceed with feature request.

Thank you very much for your support!

github-actions[bot] commented 2 years ago

This feature request is being closed due to insufficient upvotes. When enough upvotes are received, this issue will be eligible for our backlog.

github-actions[bot] commented 2 years ago

This feature request has received enough votes to be added to our backlog.

komp0t commented 10 months ago

Similar problem as the author. image Linked here image

Define in c_cpp_properties.json: "__prog__=" not working Help, I tried everything

bobbrow commented 10 months ago

@komp0t how exactly did you put it in c_cpp_properties.json? It should look like this in the configuration:

  "defines": [ "__prog__=" ],
komp0t commented 10 months ago

That's right. I've seen a lot of replies on this topic. image

bobbrow commented 10 months ago

It's because you have configurationProvider set. That means we will use the configuration given to us from the CMake Tools extension (if it exists) and ignore the "defines" and "compileCommands." If CMake Tools and compile commands do not provide a configuration, then we will use the "defines" as a backup.

bobbrow commented 10 months ago

In other words, unfortunately this workaround isn't compatible with the configurationProvider and compileCommands properties. You would have to hack your build system to output the workaround which might be easier to do with compileCommands than with configurationProvider.

komp0t commented 10 months ago

Thanks, I think I understand what's going on. Do you know how to specify prog and other definitions without overriding them? Using compileCommands from CMake build system.

bobbrow commented 10 months ago

Oh, actually, can you try adding this to the configuration? I believe this was added for cases like this. It should allow you to continue to use configurationProvider and compileCommands with your addition to the defines.

"mergeConfigurations": true
komp0t commented 10 months ago

When using only compileCommands, the problem remains. image image

If I use configurationProvider all definitions are reset. #include continue to work image image

komp0t commented 10 months ago

I solved the problem as follows.

c_cpp_properties.json

        "mergeConfigurations": true,
        "defines": ["__prog__="],
        "configurationProvider": "ms-vscode.cmake-tools"

it is also necessary to reset the default paths so that there are no conflicts

c_cpp_properties.json

       "compilerPath": ""

Maybe there is a path to install IncludePath via cmake command. If you know, can you tell me?

bobbrow commented 10 months ago

Maybe there is a path to install IncludePath via cmake command. If you know, can you tell me?

I'm not sure I understand what you are asking for. Is it to set the paths for the system headers?

If you set the compilerPath to "" the C++ extension will not search for your system headers. I imagine that we wouldn't be able to get them from this compiler anyway, so you will need to add them to the "includePath": [ ] array. That property should also get merged into the configuration with the defines.