[PATCH] D114848: [Analysis] Ignore casts and unary ops for uninitialized values

Nick Desaulniers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 6 16:32:13 PST 2021


nickdesaulniers added inline comments.


================
Comment at: clang/lib/Analysis/UninitializedValues.cpp:819-820
+    // semantic analysis passes.
+    while (isa<UnaryOperator>(Ex))
+      Ex = stripCasts(C, dyn_cast<UnaryOperator>(Ex)->getSubExpr());
+
----------------
void wrote:
> nickdesaulniers wrote:
> > Q: are there any unary operators that are not casts? For example isn't something like `-x` a unary negation operator?  I worry that this could be an infinite loop as written.
> > 
> > If this fear is unfounded, then I think the code could be rewritten as:
> > 
> > ```
> > while (const auto *UO = dyn_cast<UnaryOperator>(Ex))
> >   Ex = stripCasts(C, UO->getSubExpr());
> > ```
> It's not just casts that I want to remove. In particular, the `&` and `*` operators need to be removed to get to the variable. It *should* eventually get to a variable or non-unary expression once it goes through all of the unary operators and casts.
> 
> Note there are other sema checks that determine if the expression is a proper l-value, so I can throw away the unary-ops.
Ok, my original concern seems fine.

I still think you should rewrite the loop as suggested. At the least, a `dyn_cast` shouldn't be necessary once we've already checked with `isa`; `cast` could simply be used.  Or even better just one `dyn_cast` as suggested.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114848/new/

https://reviews.llvm.org/D114848



More information about the cfe-commits mailing list