[PATCH] D49838: [AST] Sink 'part of explicit cast' down into ImplicitCastExpr

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 26 14:32:41 PDT 2018


lebedev.ri added inline comments.


================
Comment at: include/clang/AST/Expr.h:2928
 
+  bool getIsPartOfExplicitCast() const {
+    return CastExprBits.PartOfExplicitCast;
----------------
rsmith wrote:
> Please also rename this to`isPartOfExplicitCast` as requested on IRC.
Right, sorry.


================
Comment at: lib/Sema/SemaCast.cpp:97
       while ((CE = dyn_cast<ImplicitCastExpr>(CE->getSubExpr())))
-        CE->setIsPartOfExplicitCast(true);
+        dyn_cast<ImplicitCastExpr>(CE)->setIsPartOfExplicitCast(true);
     }
----------------
rsmith wrote:
> lebedev.ri wrote:
> > lebedev.ri wrote:
> > > erichkeane wrote:
> > > > I think I'd prefer just using a different variable in the 'while' loop to avoid the cast.  something like while((auto ICE =....
> > > > 
> > > > That said, either way this isn't a dyn_cast, this would be just a cast (since we KNOW the type).
> > > I was trying to avoid having one extra variable, which may confuse things.
> > > Let's see maybe it's not that ugly..
> > Indeed, `cast<>` should be used.
> > But trying to avoid this cast at all results in uglier code, so let's not.
> > (I need to call `getSubExpr()` on this new `ImplicitCastExpr`, so i'd need to maintain two variables, etc...)
> Maybe something like:
> ```
> for (auto *Next = CE->getSubExpr(); auto *ICE = dyn_cast<ImplicitCastExpr>(Next); Next = ICE->getSubExpr())
>   ICE->setIsPartOfExplicitCast(true);
> ```
> or just
> ```
> for (; auto *ICE = dyn_cast<ImplicitCastExpr>(CE->getSubExpr()); CE = ICE)
>   ICE->setIsPartOfExplicitCast(true);
> ```
Oh wow, one can define variables not just in the "init-statement", how did i not notice this earlier?!
That changes the picture indeed.


Repository:
  rC Clang

https://reviews.llvm.org/D49838





More information about the cfe-commits mailing list