Comments (4)
I looked at the handling of variable argument in clang more closely while fixing a bug. Here is a summary:
- clang does not seem to know about the
va_list
type itself. According to the C spec, theva_list
type must be a complete object types. - clang creates a special built-in type
__builtin_va_list
. Clang appears to recognize that the type needs to be around whenva_list
is around. The mechanism for triggering this was unclear. The use of two underscores in the beginning of the name means that this is an identifier reserved for system use. - The way that variable argument information is represented is platform-specific and considered part of the platform ABI. Clang typedef's
__builtin_va_list
to the platform-specific type. The functionASTContext::getBuiltinVaListDecl
returns the typedef declaration. - The built-in type is used to type variable argument-related primitive operations.
It seems that the rewriter will need to specially recognize the type named va_list
. The rewriter should specially recognize the name typedef name __builtin_va_list
. There are a wide variety of platform-specific types used to represent variable argument information, including char *
and void *
. It is not practical to avoid rewriting those types because they could be used in ways completely unrelated to variable arguments.
The rewriter also needs to handle source-level typedefs that map to va_list
. We should have a function that recognizes type names that should not be rewritten because they are special names related to variable arguments.
There are two places in the rewriter code that try to handle va_list-typed variables: specialCaseVarIntros in ConstraintBuilder.cpp and PointerVariableConstraint in ProgramInfo.cpp. The former seems to only be applied to local variable definitions and looks for types named "va_list". It misses parameters. The latter checks all pointer types, but it only looks for the x86-x64 ABI-specific type to which __builtin_va_list is typedef'ed. A bug fix added recognition of va_list
. It is unclear why the rewriter needed to recognize the the type to which __builtin_va_list
is typedef'ed for x64. This suggests that either clang is using the desugared name when typing built-in primitives or that the rewriter is desugaring a name and losing typedef information. It is also unclear whether all the recognition can be done in PointerVariableConstraint and specialCaseVarIntros can be drooped.
from checkedc-clang.
I think the thing that was hanging me up was that there are three things you can do with a Type
: you can look at it in its current form, you can de-sugar it one "step", or you can take a big step to de-sugar it fully. I think a principled thing to do would be to take a given type and either de-sugar it one step or traverse it with the appropriate Visitor
looking for va_list
. At the time, I didn't have the bandwidth to do that. Maybe now is the time?
from checkedc-clang.
I think you can put this off for now. At this point, I think it is better to focus on enhancing and evaluating the rewriter.
from checkedc-clang.
Closing this work item as stale. The convert tool has been mostly rewritten (see PR #642). We can reopen this or create a new issue if we decide further work is needed.
from checkedc-clang.
Related Issues (20)
- Do not emit bounds checking warnings or errors for bounds-safe interfaces in certain contexts
- Consider emitting warnings for uses of pointers that violate their bounds-safe interfaces
- Allow `printf`-like calls in checked scopes if they pass `-Wformat` validation HOT 3
- Another crash while using checkedC HOT 2
- Move language conformance tests related to Where clauses to the checkedc repository
- Type-(un)safe unions (bug, and suggestion) ?
- Invertibility does not use semantic expression comparison
- Missing checks in calls to variadic functions inside checked scope HOT 1
- Missing checks in calls to variadic functions inside checked scope
- Equality should not be recorded between expressions such as x and x + 1 HOT 1
- "stdlib.h" not found in stdlib_checked.h HOT 3
- Fail to catch an out-of-bounds access at compile time
- Option to warn for each inserted runtime check that can't be proved unnecessary
- Eliminate null checks if the OS is known to trap failures safely
- No error on assignment to global variable used in bounds of another global variable (unsound) HOT 1
- Local variable bounds dependent on global variable can be invalidated by function call (unsound) HOT 1
- Maintain a complete, up-to-date list of unimplemented parts of the Checked C specification
- Checked-pointer local variable can be initialized with itself (unsound) HOT 1
- Compiler issues in Apple Silicon Systems HOT 1
- This repo is missing important files
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from checkedc-clang.