Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memcpy() is treated as a macro instead of a function #11997

Closed
VicBoss1984 opened this issue Feb 21, 2024 · 0 comments
Closed

memcpy() is treated as a macro instead of a function #11997

VicBoss1984 opened this issue Feb 21, 2024 · 0 comments

Comments

@VicBoss1984
Copy link

VicBoss1984 commented Feb 21, 2024

Environment

  • OS and Version: macOS 14.3.1
  • Kernel Version: Darwin 23.3.0
  • VS Code Version: 1.86.2
  • C/C++ Extension Version: v1.18.5

Bug Summary and Steps to Reproduce

Bug Summary: functions such as memcpy() from the C standard library are treated as macros instead of functions, which causes syntax highlighting to incorrectly highlight memcpy() as a macro instead of as a function.

Steps to reproduce:

  1. Copy-paste the attached molappend_atom() code into any empty '.c' file in a Visual Studio Code window.
  2. Save the newly populated file.
  3. Scroll down the invocation of memcpy() in molappend_atom() in the active VS Code editor window.
  4. Activate the "Developer: Inspect Editor Tokens and Scopes view"
  5. Hover over to the memcpy() invocation in the molappend_atom() function
  6. Notice how the output from the "Developer: Inspect Editor Tokens and Scopes view" will give you a different output if you hovered over any other function in the sample code
  7. The "Developer: Inspect Editor Tokens and Scopes view" will claim that memcpy() is being classified as a macro instead of a function
  8. You can also hover over memcpy()'s invocation without the editor tokens inspection view and notice how it looks like a macro definition as opposed to a normal function from the C standard library.

Sample code for the void molappend_atom(molecule *molecule, atom *atom); function:

#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdio.h>

typedef struct atom {
  char element[3];
  double x, y, z;
} atom;

typedef struct bond {
  unsigned short a1;
  unsigned short a2;
  atom *atoms;
  unsigned char epairs;
  double x1, x2, y1, y2, z, len, dx, dy;
} bond;

typedef struct molecule {
  unsigned short atom_max, atom_no;
  atom *atoms, **atom_ptrs;
  unsigned short bond_max, bond_no;
  bond *bonds, **bond_ptrs;
} molecule;

// Absolutely crucial functions, the append ones
void molappend_atom(molecule *molecule, atom *atom) {
  
  if (molecule->atom_no == molecule->atom_max) {
    if (molecule->atom_max == 0) {
      molecule->atom_max++;
      molecule->atoms = realloc(molecule->atoms, sizeof(struct atom) * molecule->atom_max);
      for (int ctr = 0; ctr < molecule->atom_no; ctr++) {
        molecule->atom_ptrs[ctr] = &molecule->atoms[ctr];
      }
      if (molecule->atoms == NULL) {
        exit(1);
      }
      molecule->atom_ptrs = realloc(molecule->atom_ptrs, sizeof(struct atom*) * molecule->atom_max);
      if (molecule->atom_ptrs == NULL) {
        exit(1);
      }
    } else {
      molecule->atom_max = molecule->atom_max * 2;
      molecule->atoms = realloc(molecule->atoms, sizeof(struct atom) * molecule->atom_max);
      for (int ctr = 0; ctr < molecule->atom_no; ctr++) {
        molecule->atom_ptrs[ctr] = &molecule->atoms[ctr];
      }
      if (molecule->atoms == NULL) {
        exit(1);
      }
      molecule->atom_ptrs = realloc(molecule->atom_ptrs, sizeof(struct atom*) * molecule->atom_max);
      if (molecule->atom_ptrs == NULL) {
        exit(1);
      }
    }
  }

  molecule->atom_ptrs[molecule->atom_no] = &(molecule->atoms[molecule->atom_no]);
  memcpy(&(molecule->atoms[molecule->atom_no]), atom, sizeof(struct atom));
  molecule->atom_no++;
}```

Expected behavior: `memcpy()` should be classified as a function, but for some reason it is not being classified as a function. Maybe `memcpy()` is treated as a macro by the darwin kernel, but I am unsure why it is being treated as a macro instead of as a function.

Here are screenshots from my end that depict the situation visually, for your reference:

<img width="514" alt="img1" src="https://github.com/microsoft/vscode-cpptools/assets/85129181/694585f6-6291-4d61-9ee6-c390f44ad4d5">
<img width="778" alt="img2" src="https://github.com/microsoft/vscode-cpptools/assets/85129181/4961e079-a732-41fa-8623-b976f54d4287">
<img width="383" alt="img3" src="https://github.com/microsoft/vscode-cpptools/assets/85129181/24d91bdf-7970-4b37-b226-37cd1b7d7cde">
<img width="337" alt="img4" src="https://github.com/microsoft/vscode-cpptools/assets/85129181/9c19bd37-157e-43e8-9ac5-e9a5936f8ea9">


### Configuration and Logs

```shell
Configurations in `c_cpp_properties.json`:

"{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "macos-clang-arm64"
        }
    ],
    "version": 4
}"

Logs from running `C/C++: Log Diagnostics`:

"-------- Diagnostics - 2/21/2024, 5:28:32 PM
Version: 1.18.5
Current Configuration:
{
    "name": "Mac",
    "includePath": [
        "/Users/ajawad/Computing/Projects/AngelofDeathProject/CIS2750A4/**"
    ],
    "defines": [],
    "macFrameworkPath": [
        "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
    ],
    "compilerPath": "/usr/bin/clang",
    "cStandard": "c17",
    "cppStandard": "c++17",
    "intelliSenseMode": "macos-clang-arm64",
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "compilerPathInCppPropertiesJson": "/usr/bin/clang",
    "mergeConfigurations": false,
    "browse": {
        "path": [
            "/Users/ajawad/Computing/Projects/AngelofDeathProject/CIS2750A4/**",
            "${workspaceFolder}"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
cpptools version (native): 1.18.3.0
Translation Unit Mappings:
[ /Users/ajawad/Computing/Projects/AngelofDeathProject/CIS2750A4/temp/molappend_atom.c ]:
    /Users/ajawad/Computing/Projects/AngelofDeathProject/CIS2750A4/temp/molappend_atom.c
[ /Users/ajawad/Computing/Projects/AngelofDeathProject/CIS2750A4/mol.c ]:
    /Users/ajawad/Computing/Projects/AngelofDeathProject/CIS2750A4/mol.c
    /Users/ajawad/Computing/Projects/AngelofDeathProject/CIS2750A4/mol.h *
Translation Unit Configurations:
[ /Users/ajawad/Computing/Projects/AngelofDeathProject/CIS2750A4/temp/molappend_atom.c ]:
    Process ID: 89677
    Memory Usage: 24 MB
    Compiler Path: /usr/bin/clang
    Includes:
        /usr/local/include
        /Library/Developer/CommandLineTools/usr/lib/clang/15.0.0/include
        /Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk/usr/include
        /Library/Developer/CommandLineTools/usr/include
    Frameworks:
        /Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk/System/Library/Frameworks
    Standard Version: c17
    IntelliSense Mode: macos-clang-arm64
    Other Flags:
        --clang
        --clang_version=160000
[ /Users/ajawad/Computing/Projects/AngelofDeathProject/CIS2750A4/mol.c ]:
    Process ID: 89712
    Memory Usage: 33 MB
    Compiler Path: /usr/bin/clang
    Includes:
        /usr/local/include
        /Library/Developer/CommandLineTools/usr/lib/clang/15.0.0/include
        /Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk/usr/include
        /Library/Developer/CommandLineTools/usr/include
    Frameworks:
        /Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk/System/Library/Frameworks
    Standard Version: c17
    IntelliSense Mode: macos-clang-arm64
    Other Flags:
        --clang
        --clang_version=160000
Total Memory Usage: 57 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 11334"

If necessary, the logs from the language server logging can be provided. Just let me know if it is necessary and I will provide it as soon as possible.

Other Extensions

No response

Additional context

Here are images that depict what I am seeing on my end:

img1 img2 img3 img4
@github-actions github-actions bot locked and limited conversation to collaborators Apr 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant