llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[MLIR] "ConstantOp::getAsmResultNames" crashes with 128bits integers (-emit-fir fails)

Open tarunprabhu opened this issue 4 years ago • 5 comments

Minimum reproducer

subroutine s(n)
  integer(kind = 16) :: n

  n = 9223372036854775808_16
end subroutine s

This results in the following output

$ flang-new -fc1 -emit-mlir -o - i128.f90 
flang-new: /work/projects/flang/llvm-project/llvm/include/llvm/ADT/APInt.h:1481: int64_t llvm::APInt::getSExtValue() const: Assertion `getSignificantBits() <= 64 && "Too many bits for int64_t"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: ../local/bin/flang-new -fc1 -emit-mlir -o - i128.f90
 #0 0x0000563dbc21eaa4 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x0000563dbc21c00b SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f124d7eb8e0 (/usr/lib/libc.so.6+0x3e8e0)
 #3 0x00007f124d83b36c (/usr/lib/libc.so.6+0x8e36c)
 #4 0x00007f124d7eb838 gsignal (/usr/lib/libc.so.6+0x3e838)
 #5 0x00007f124d7d5535 abort (/usr/lib/libc.so.6+0x28535)
 #6 0x00007f124d7d545c (/usr/lib/libc.so.6+0x2845c)
 #7 0x00007f124d7e4366 (/usr/lib/libc.so.6+0x37366)
 #8 0x0000563dbfe25c6f (../local/bin/flang-new+0x4c40c6f)
 #9 0x0000563dbe5c23c7 mlir::arith::ConstantOp::getAsmResultNames(llvm::function_ref<void (mlir::Value, llvm::StringRef)>) (../local/bin/flang-new+0x33dd3c7)
#10 0x0000563dbe5c611f mlir::detail::OpAsmOpInterfaceInterfaceTraits::Model<mlir::arith::ConstantOp>::getAsmResultNames(mlir::detail::OpAsmOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*, llvm::function_ref<void (mlir::Value, llvm::StringRef)>) (../local/bin/flang-new+0x33e111f)
#11 0x0000563dbfe03c90 (anonymous namespace)::SSANameState::numberValuesInOp(mlir::Operation&) AsmPrinter.cpp:0:0
#12 0x0000563dbfe06c95 (anonymous namespace)::SSANameState::SSANameState(mlir::Operation*, mlir::OpPrintingFlags const&) AsmPrinter.cpp:0:0
#13 0x0000563dbfe07a9e mlir::AsmState::AsmState(mlir::Operation*, mlir::OpPrintingFlags const&, llvm::DenseMap<mlir::Operation*, std::pair<unsigned int, unsigned int>, llvm::DenseMapInfo<mlir::Operation*, void>, llvm::detail::DenseMapPair<mlir::Operation*, std::pair<unsigned int, unsigned int>>>*) (../local/bin/flang-new+0x4c22a9e)
#14 0x0000563dbfe14f98 mlir::Operation::print(llvm::raw_ostream&, mlir::OpPrintingFlags const&) (../local/bin/flang-new+0x4c2ff98)
#15 0x0000563dbc912657 Fortran::frontend::CodeGenAction::executeAction() (../local/bin/flang-new+0x172d657)
#16 0x0000563dbc2406fc Fortran::frontend::FrontendAction::execute() (../local/bin/flang-new+0x105b6fc)
#17 0x0000563dbc2331d3 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (../local/bin/flang-new+0x104e1d3)
#18 0x0000563dbc2462ac Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (../local/bin/flang-new+0x10612ac)
#19 0x0000563dbbdb4ad8 fc1_main(llvm::ArrayRef<char const*>, char const*) (../local/bin/flang-new+0xbcfad8)
#20 0x0000563dbbd2ea4f main (../local/bin/flang-new+0xb49a4f)
#21 0x00007f124d7d6290 (/usr/lib/libc.so.6+0x29290)
#22 0x00007f124d7d634a __libc_start_main (/usr/lib/libc.so.6+0x2934a)
#23 0x0000563dbbdb3a55 _start /build/glibc/src/glibc/csu/../sysdeps/x86_64/start.S:117:0
zsh: IOT instruction (core dumped)  flang-new -fc1 -emit-mlir -o - i128.f90

9223372036854775808_16 is the smallest number that triggers this bug. 9223372036854775807_16 works. In either case, -emit-llvm works.

[Edit: fixed formatting]

tarunprabhu avatar Jul 08 '22 15:07 tarunprabhu

@llvm/issue-subscribers-flang-ir

llvmbot avatar Jul 08 '22 15:07 llvmbot

mlir-opt shows a similar crash for i128.

func.func @ori() -> i128 {
    %large = arith.constant 170141183460469231731687303715884105727 : i128
    return %large : i128
}

kiranchandramohan avatar Jul 08 '22 16:07 kiranchandramohan

@llvm/issue-subscribers-mlir

llvmbot avatar Jul 08 '22 16:07 llvmbot

@llvm/issue-subscribers-bug

llvmbot avatar Jun 07 '23 17:06 llvmbot

It looks like this has been fixed. The example from https://github.com/llvm/llvm-project/issues/56446#issuecomment-1179152381 as well as a more complex example such as:

func.func @ori() -> i128 {
    %large = arith.constant 170141183460469231731687303715884105727 : i128
    %one = arith.constant 1 : i128
    %plusone = arith.addi %large, %one : i128
    return %plusone : i128
}

Can be passed into mlir-opt without problems.

@kiranchandramohan I'll close this issue but feel free to reopen if you disagree

rikhuijzer avatar Oct 15 '23 13:10 rikhuijzer