[cfe-commits] Patch for evaluating FP constant expressions

Chris Lattner clattner at apple.com
Fri Nov 30 21:01:33 PST 2007


On Nov 30, 2007, at 7:40 PM, Christopher Lamb wrote:

>> +    case BinaryOperator::Div:
>> +      if (llvm::APFloat::opOK !=
>> +          Result.divide(RHS, llvm::APFloat::rmNearestTiesToEven)) {
>> +        if (!isEvaluated) break;
>> +        if (Loc) *Loc = getLocStart();
>> +        return false;
>> +      }
>>
>> It would be "nice" if this reported diagnostics for overflow etc as  
>> warnings.
>
>
> This is in Expr.cpp and it's called from CodeGen, how can I get the  
> diagnostics object here?

Ah, we don't want to emit a diagnostic from CodeGen.  However, the  
same routine should be called by sema, to verify that the initializer  
for a global is constant.  We want sema to be able to emit a warning/ 
error and codegen to not, but both to get the result value.

The best way to do this is probably something like what  
isIntegerConstantExpr does.  If "Loc" is specified, it is filled in  
with the location of the diagnostic.  The missing piece is that we  
want a diagid to report as well.  For example something like this:

   SourceLocation Loc;
   diag::kind ConstDiag = 0;
   bool isConst = Init->isRealFloatingConstantExpr(Result,Ctx, &Loc,  
&ConstDiag);

   if (ConstDiag)
      Diag(Loc, ConstDiag, Init->getSourceRange());

or something like that.  Codegen would just not pass in, or would  
ignore, the diagnostic info.

Does that seem reasonable?

-Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20071130/57c79adc/attachment.html>


More information about the cfe-commits mailing list