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

Builtin integer overflow functions not known #271

Closed
PhilippWendler opened this issue Jan 31, 2023 · 3 comments · Fixed by #273
Closed

Builtin integer overflow functions not known #271

PhilippWendler opened this issue Jan 31, 2023 · 3 comments · Fixed by #273
Labels
language C/C++ Language Support

Comments

@PhilippWendler
Copy link
Contributor

GCC has a set of builtin functions for performing integer arithmetic with overflow checking, for example __builtin_sadd_overflow etc. These are not present in CDT's list of builtin functions, so code using them will be parsed with wrong types for these function calls.

It seems that adding them should be easy, however, there are some functions like __builtin_add_overflow which are declared like this:

bool __builtin_add_overflow(type1 a, type2 b, type3 *res)

type1, type2, and type3 can be any integral type. How should this be represented inside CDT?

__builtin_types_compatible_p, which is also a builtin "function" with a signature that is not expressible in C , uses "" as type for each parameter, which createType(String) seems to translate to a basic type with kind eUnspecified and no modifiers. Maybe this fits here as well? If yes, should the type of res be a void pointer or maybe something like "*"?

@jonahgraham
Copy link
Member

@davmac314 did a few of the builtins last year, looking at their contributions would be a good place to start on how to implement these.

@jonahgraham jonahgraham added the language C/C++ Language Support label Jan 31, 2023
@PhilippWendler
Copy link
Contributor Author

Well, I already looked at the existing code and have an idea how to do it, but the questions that I mentioned regarding the types remain. If these are answered I can send a PR.

The contributions from davmac314 all seem to add concrete semantics for builtin functions for C++, this is not what I am attempting to do. I just want do add declarations.

@davmac314
Copy link
Contributor

IIRC the type string is parsed as a C type (if it is not empty) by createString(String). I think that for simply having the parser/checker accept calls to the function, the types should probably be "" for the first two arguments (i.e. don't check the argument types), and "void*" would work reasonably well for the third (make sure that a pointer is passed, though it will not check if the pointer is the correct type).

PhilippWendler added a commit to sosy-lab/eclipse-cdt that referenced this issue Feb 1, 2023
PhilippWendler added a commit to sosy-lab/eclipse-cdt that referenced this issue Feb 1, 2023
PhilippWendler added a commit to sosy-lab/eclipse-cdt that referenced this issue Feb 1, 2023
PhilippWendler added a commit to sosy-lab/eclipse-cdt that referenced this issue Feb 1, 2023
PhilippWendler added a commit to sosy-lab/eclipse-cdt that referenced this issue Feb 1, 2023
PhilippWendler added a commit to sosy-lab/eclipse-cdt that referenced this issue Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language C/C++ Language Support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants