8 Commits

Author SHA1 Message Date
Samira Bazuzi
2575ea6e17
[clang][dataflow] Collect local variables referenced within a functio… (#104459)
…n/statement.

We don't need these for the same in-tree purposes as the other sets,
i.e. for making sure we model these Decls that are declared outside the
function, but we have an out-of-tree use for these sets that would
benefit from this simple addition and would avoid duplicating so much of
this code.
2024-08-19 13:25:49 -04:00
martinboehme
275196d866
[clang][nullability] Don't return null fields from getReferencedDecls(). (#94983)
The patch includes a repro for a case where we were returning a null
`FieldDecl`
when calling `getReferencedDecls()` on the `InitListExpr` for a union.

Also, I noticed while working on this that `RecordInitListHelper` has a
bug
where it doesn't work correctly for empty unions. This patch also
includes a
repro and fix for this bug.
2024-06-11 08:40:02 +02:00
martinboehme
5161a3f6e5
[clang][dataflow] Rewrite getReferencedDecls() with a RecursiveASTVisitor. (#93461)
We previously had a hand-rolled recursive traversal here that was
exactly what
`RecursiveASTVistor` does anyway. Using the visitor not only eliminates
the
explicit traversal logic but also allows us to introduce a common
visitor base
class for `getReferencedDecls()` and `ResultObjectVisitor`, ensuring
that the
two are consistent in terms of the nodes they visit. Inconsistency
between these
two has caused crashes in the past when `ResultObjectVisitor` tried to
propagate
result object locations to entities that weren't modeled becasue
`getReferencedDecls()` didn't visit them.
2024-06-03 08:59:09 +02:00
martinboehme
c70f058316
[clang][dataflow] Fix crash when ConstantExpr is used in conditional operator. (#90112)
`ConstantExpr` does not appear as a `CFGStmt` in the CFG, so
`StmtToEnvMap::getEnvironment()` was not finding an entry for it in the
map,
causing a crash when we tried to access the iterator resulting from the
map
lookup.

The fix is to make `ignoreCFGOmittedNodes()` ignore `ConstantExpr`, but
in
addition, I'm hardening `StmtToEnvMap::getEnvironment()` to make sure
release
builds don't crash in similar situations in the future.
2024-04-26 09:30:07 +02:00
Samira Bazuzi
d634b23364
[clang][dataflow] Expose getReferencedDecls for a Stmt. (#89444) 2024-04-19 16:23:43 -04:00
martinboehme
ca7d9442ba
[clang][dataflow] Support CXXParenListInitExpr in PropagateResultObject(). (#89235) 2024-04-19 09:06:13 +02:00
Timm Baeder
3d56ea05b6
[clang][NFC] Fix FieldDecl::isUnnamedBitfield() capitalization (#89048)
We always capitalize bitfield as "BitField".
2024-04-18 07:39:29 +02:00
Samira Bazuzi
9ec8c96166
[clang][dataflow] Expose getReferencedDecls and relocate free functions. (#88754)
Moves free functions from DataflowEnvironment.h/cc and
DataflowAnalysisContext.h/cc to RecordOps and a new ASTOps and exposes
them as needed for current use and to expose getReferencedDecls for
out-of-tree use.

Minimal change in functionality, only to modify the return type of
getReferenceDecls to return the collected decls instead of using output
params.

Tested with `ninja check-clang-tooling`.
2024-04-16 14:46:05 -04:00