[PATCH] D84415: [analyzer][StdLibraryFunctionsChecker] Add POSIX pthread handling functions
Gabor Marton via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 25 02:00:29 PDT 2020
martong added inline comments.
================
Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:882
+ const QualType SizePtrTy = getPointerTy(SizeTy);
+ const QualType SizePtrRestrictTy = getRestrictTy(SizePtrTy);
----------------
balazske wrote:
> martong wrote:
> > balazske wrote:
> > > Another idea: Have a class that handles all the variants (simple, pointer, const pointer, const restrict pointer, restrict). It can have get functions that compute the type if not done yet, or get every variant at first time even if it is later not used (or has no sense).
> > > For example create it like `TypeVariants SizeTy{ACtx.getSizeType()};` and then call `SizeTy.getType()`, `SizeTy.asPtr()`, `SizeTy.asPtrRestrict()`, ... .
> > > ```
> > I'd rather keep the current form, because I think it makes it easier to compose types from different base types (and it is similar to the ASTMatchers in this sense).
> If I got it correctly, the problem with my approach above is that it has separate functions for every special type variant. The current is acceptable but looks not fully uniform to me (the type has a `withConst` and for getting a pointer or restrict there is a function call). We could have something like a "`TypeBuilder`" that has methods `withConst()`, `withRestrict()`, `withPointerTo()` (these can return a TypeBuilder too) and finally a (omittable) `getType()` that returns `Optional<QualType>`.
> ```
> const QualType ConstVoidPtrRestrictTy = TypeBuilder{ACtx, VoidTy}.withConst().withPointerTo().withRestrict().getType();
> ```
>
Yeah, `.withConst()` is making it nonuniform currently, you are right.
What if we had `getConstTy()` that receives an optional? Composability would be just perfect in this case :)
```
Optional<QualType> ConstPthread_attr_tPtrTy = getPointerTy(getConstTy(Pthread_attr_tTy));
```
WDYT?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D84415/new/
https://reviews.llvm.org/D84415
More information about the cfe-commits
mailing list