[PATCH] D42728: Add more warnings for implict conversions (e.g. double truncation to float).

Andrew V. Tischenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 2 00:25:22 PST 2018


avt77 added inline comments.


================
Comment at: lib/Sema/SemaChecking.cpp:9222
+  const BuiltinType *SourceBT = dyn_cast<BuiltinType>(
+      S.Context.getCanonicalType(E->getRHS()->getType()).getTypePtr());
+  const BuiltinType *TargetBT =
----------------
rjmccall wrote:
> avt77 wrote:
> > rjmccall wrote:
> > > `E->getComputationResultType()->getType()->getAs<BuiltinType>()`
> > Unfortunatelly, it does not work because getComputationResultType() returns 'double':
> > 
> > CompoundAssignOperator 0xd2db9a0 'float' '+=' ComputeLHSTy='double' ComputeResultTy='double'
> > |-UnaryOperator 0xd2db940 'float' lvalue prefix '*' cannot overflow
> > | `-ImplicitCastExpr 0xd2db928 'float *' <LValueToRValue>
> > |   `-DeclRefExpr 0xd2db900 'float *' lvalue ParmVar 0xd2db780 'b' 'float *'
> > `-ImplicitCastExpr 0xd2db988 'double' <LValueToRValue>
> >   `-DeclRefExpr 0xd2db960 'double' lvalue ParmVar 0xd2db6d8 'a' 'double'
> > 
> > (gdb) p CAOp->getComputationLHSType()->dump()
> > BuiltinType 0xd25a9b0 'double'
> > 
> > (gdb) p CAOp->getComputationResultType ()->dump()
> > BuiltinType 0xd25a9b0 'double'
> > 
> Sorry, I mean instead of E->getRHS()->getType().
OK, in this case we need clear comment about getComputationResultType: I was sure that ResultType is LHS type. Could you add such a comment in Expr.h?


https://reviews.llvm.org/D42728





More information about the llvm-commits mailing list