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

A result type of __builtin_choose_expr that returns a pointer to a function is not correctly inferred in clang mode #9368

Closed
mame opened this issue May 26, 2022 · 5 comments
Assignees
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service verified Bug has been reproduced Visual Studio Inherited from Visual Studio
Milestone

Comments

@mame
Copy link

mame commented May 26, 2022

Bug type: Language Service

Describe the bug

  • OS and Version: Windows 11
  • VS Code Version: 1.67.2
  • C/C++ Extension Version: 1.9.8
  • Other extensions you installed: Nothing
  • If using SSH remote, specify OS of remote machine: Ubuntu on WSL
  • When __builtin_choose_expr returns a pointer to a function, the result type seems not to be inferred correctly.

Steps to reproduce

  1. Save the code sample as a file and open it in VSCode.
  2. You will see an error expression preceding parentheses of apparent call must have (pointer-to-) function type

Expected behavior

No error is shown.

Code sample and logs

  • Code sample
int foo(void) {
    puts("foo");
}

int bar(void) {
    puts("bar");
}

int main(void) {
    __builtin_choose_expr(1, foo, bar)();
}

Screenshots

image

NOTE: Screenshot is incorrect and missing an `_`.

Additional context

This idiom is heavily used in the source code of the programming language Ruby.

https://github.com/ruby/ruby/blob/2556e15d7520913119175c8166b1f9d17eb33415/include/ruby/internal/anyargs.h#L287

RBIMPL_ANYARGS_DISPATCH_rb_define_method((arity), (func)) returns a pointer to a function by using __builtin_choose_expr, and then the function is invoked.

@sean-mcmanus sean-mcmanus self-assigned this May 31, 2022
@sean-mcmanus sean-mcmanus changed the title A result type of _builtin_choose_expr that returns a pointer to a function is not correctly inferred A result type of __builtin_choose_expr that returns a pointer to a function is not correctly inferred May 31, 2022
@sean-mcmanus
Copy link
Contributor

The bug doesn't repro when the missing _ is added -- are you still reproing this with __builtin_choose_expr? If so, can you give the exact compiler and cStandard setting that is being used for the repro and/or output of C/C++: Log Diagnostics?

@sean-mcmanus sean-mcmanus added Language Service more info needed The issue report is not actionable in its current state not reproing We're not able to reproduce the issue (it's unlikely to get fixed until we find one). labels May 31, 2022
@mame
Copy link
Author

mame commented Jun 1, 2022

Thank you for your reply. Sorry, I seem to have lost the underscore when taking the screenshot. The issue still reproduces even with __builtin_choose_expr as follows.

image

The example project has no c_cpp_properties.json. I created the file as follows, and the issue is still reproduced.

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++14",
            "intelliSenseMode": "linux-clang-x64"
        }
    ],
    "version": 4
}

Here is the output of C/C++: Log diagnostics

-------- Diagnostics - 6/1/2022, 11:15:36 AM
Version: 1.9.8
Current Configuration:
{
    "name": "Linux",
    "includePath": [
        "${workspaceFolder}/**"
    ],
    "defines": [],
    "compilerPath": "/usr/bin/clang",
    "cStandard": "c17",
    "cppStandard": "c++14",
    "intelliSenseMode": "linux-clang-x64",
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "compilerArgs": [],
    "mergeConfigurations": false,
    "browse": {
        "path": [
            "${workspaceFolder}/**"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Translation Unit Mappings:
[ /home/mame/work/ruby/t.c ]:
    /home/mame/work/ruby/t.c
Translation Unit Configurations:
[ /home/mame/work/ruby/t.c ]:
    Process ID: 417522
    Memory Usage: 11 MB
    Compiler Path: /usr/bin/clang
    Includes:
        /usr/lib/llvm-14/lib/clang/14.0.0/include
        /usr/local/include
        /usr/include/x86_64-linux-gnu
        /usr/include
    Standard Version: c17
    IntelliSense Mode: linux-clang-x64
    Other Flags:
        --clang
        --clang_version=140000
Total Memory Usage: 11 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 27641
Number of files parsed: 1

FYI: This is a screenshot of the issue with a working real-world application (Ruby)

image

https://github.com/ruby/ruby/blob/936e54063d4de0e44925e9139cb4d25cce27c187/array.c#L8746-L8779

rb_define_method is a macro, and the expanded code uses __builtin_choose_expr that returns a function pointer.

@sean-mcmanus sean-mcmanus added verified Bug has been reproduced and removed more info needed The issue report is not actionable in its current state not reproing We're not able to reproduce the issue (it's unlikely to get fixed until we find one). labels Jun 1, 2022
@sean-mcmanus
Copy link
Contributor

This is the "same" issue as #8294, which got fixed for gcc mode but not clang mode.

@sean-mcmanus sean-mcmanus added this to the Tracking milestone Jun 1, 2022
@sean-mcmanus sean-mcmanus added bug Visual Studio Inherited from Visual Studio labels Jun 1, 2022
@mame
Copy link
Author

mame commented Jun 1, 2022

Thank you! I confirmed the errors dissapper if I change the compilerPath to "/usr/bin/gcc" in c_cpp_properties.json.

@sean-mcmanus sean-mcmanus changed the title A result type of __builtin_choose_expr that returns a pointer to a function is not correctly inferred A result type of __builtin_choose_expr that returns a pointer to a function is not correctly inferred in clang mode Jun 8, 2022
@sean-mcmanus sean-mcmanus modified the milestones: Tracking, 1.13.4 Nov 18, 2022
@sean-mcmanus sean-mcmanus added the fixed Check the Milestone for the release in which the fix is or will be available. label Nov 18, 2022
@sean-mcmanus
Copy link
Contributor

This is fixed in 1.13.4 (pre-release): https://github.com/microsoft/vscode-cpptools/releases/tag/v1.13.4, although there's a related issue at #10168 that won't be fixed till 1.14.0.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service verified Bug has been reproduced Visual Studio Inherited from Visual Studio
Projects
None yet
Development

No branches or pull requests

2 participants