[PATCH] D79775: [AsmPrinter] Handle foldable FP constant exprs in initializers.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 12 13:27:55 PDT 2020


fhahn added a comment.

To provide some context,  in the Clang crash that surfaced this, the constant actually comes from `aarch64-promote-const`. I guess in most cases, it's not an issue in practice, as ConstantExpr will do simple folds at construction time, but not the bit cast one in the example.

In D79775#2032079 <https://reviews.llvm.org/D79775#2032079>, @efriedma wrote:

> If the frontend is generating constants that require calling ConstantFoldConstant to put them into an emittable form, I think something has gone wrong else.  I mean, I guess there's no real harm in trying to perform this fold as a last-ditch effort, but I'm not convinced there's a bug in the backend.


Hm, IIUC `AsmPrinter::lowerConstant` tries to traverse complex constant expressions and constructs MCExprs for them, to lower them in multiple steps, if required, also involving ConstantFoldConstant. The problem is that MCConstantExpr does not support ConstantFP values and once a a floating point constant like 0.0 is hit while traversing a constant expression, the AsmPrinter crashes.

I am not sure, is there a reason I am missing why complex integer constant expressions can be emitted, but not floating point ones? Maybe an alternative fix would be to support ConstantFP in MCConstantExpr?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79775





More information about the llvm-commits mailing list