[PATCH] D15120: Add support for __float128 type to be used by targets that support it

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 3 16:01:31 PST 2016


On Wed, Feb 3, 2016 at 3:52 PM, Hubert Tong <
hubert.reinterpretcast at gmail.com> wrote:

> hubert.reinterpretcast added inline comments.
>
> ================
> Comment at: lib/Sema/SemaExpr.cpp:1156-1159
> @@ +1155,6 @@
> +
> +  QualType LHSElemType = dyn_cast<ComplexType>(LHSType) ?
> +    cast<ComplexType>(LHSType)->getElementType() : LHSType;
> +  QualType RHSElemType = dyn_cast<ComplexType>(RHSType) ?
> +    cast<ComplexType>(RHSType)->getElementType() : RHSType;
> +
> ----------------
> rsmith wrote:
> > hubert.reinterpretcast wrote:
> > > The result of the `dyn_cast` can be saved instead of using `cast`
> after the `dyn_cast`.
> > Do not use `dyn_cast` / `cast` on types, use `LHSType->getAs<...>()` /
> `LHSType->castAs<...>()` instead. This will do the wrong thing on sugared
> types (eg, a typedef for a complex type).
> Are there contexts in Clang where sugared types don't occur? Is the
> general guidance to use `getAs` or `castAs` even if the types are known to
> be canonical (which I agree isn't the case here)?


If you're intentionally inspecting the immediate type sugar node, then
dyn_cast/cast are appropriate. If it's obvious from context that you have a
canonical type, then they're OK (and might be marginally faster), but it's
an immediate red flag to a reader of the code to see those operations, so
they should often be avoided for that reason even if they're correct.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160203/2e1bab1a/attachment.html>


More information about the cfe-commits mailing list