Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gollvm/gofrontend: llvm-goc crashes when importing complex(0) #52862

Closed
tianxiaogu opened this issue May 12, 2022 · 3 comments
Closed

gollvm/gofrontend: llvm-goc crashes when importing complex(0) #52862

tianxiaogu opened this issue May 12, 2022 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@tianxiaogu
Copy link

There is a trivial bug of Integer_expression::do_import. When the imported number is complex(0), there is no plus or minus in the input string. So the real will be set to zero by mpfr_set_ui(real, 0, MPFR_RNDN). But later real will be freed anyway by mpfr_clear(real). To fix the issue, we can either do not clear real when the input is zero (i.e., no plus or minus) or use mpfr_init_set_ui instead of mpfr_set_ui.

  1. https://github.com/golang/gofrontend/blob/master/go/expressions.cc#L2701-L2751
# github.com/apaxa-go/helper/goh/constanth
 #0 0x000056218aa8797f PrintStackTraceSignalHandler(void*) (bin/llvm-goc+0x20fc97f)
 #1 0x000056218aa85b4c SignalHandler(int) (bin/llvm-goc+0x20fab4c)
 #2 0x00007fb3eecb50e0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x110e0)
 #3 0x00007fb3ed84afff raise /build/glibc-77giwP/glibc-2.24/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #4 0x00007fb3ed84c42a abort /build/glibc-77giwP/glibc-2.24/stdlib/abort.c:91:0
 #5 0x00007fb3ed888c00 __libc_message /build/glibc-77giwP/glibc-2.24/libio/../sysdeps/posix/libc_fatal.c:108:0
 #6 0x00007fb3ed88efc6 malloc_printerr /build/glibc-77giwP/glibc-2.24/malloc/malloc.c:5054:0
 #7 0x00007fb3ed88f80e _int_free /build/glibc-77giwP/glibc-2.24/malloc/malloc.c:4143:0
 #8 0x000056218ab56595 __gmp_default_free (bin/llvm-goc+0x21cb595)
 #9 0x000056218ab147f4 mpfr_free_func (bin/llvm-goc+0x21897f4)
#10 0x000056218aafaf12 mpfr_clear (bin/llvm-goc+0x216ff12)
#11 0x000056218919c1da Integer_expression::do_import(Import_expression*, Location) (.localalias.147) (bin/llvm-goc+0x8111da)
#12 0x00005621891b0369 Expression::import_expression(Import_expression*, Location) (.localalias.33) (bin/llvm-goc+0x825369)
#13 0x00005621891b0c02 Type_conversion_expression::do_import(Import_expression*, Location) (.localalias.134) (bin/llvm-goc+0x825c02)
#14 0x00005621891b0369 Expression::import_expression(Import_expression*, Location) (.localalias.33) (bin/llvm-goc+0x825369)
#15 0x00005621891b0c02 Type_conversion_expression::do_import(Import_expression*, Location) (.localalias.134) (bin/llvm-goc+0x825c02)
#16 0x00005621891b0369 Expression::import_expression(Import_expression*, Location) (.localalias.33) (bin/llvm-goc+0x825369)
#17 0x00005621891b0447 Expression::import_expression(Import_expression*, Location) (.localalias.33) (bin/llvm-goc+0x825447)
#18 0x00005621891223a9 Statement::import_statement(Import_function_body*, Location) (bin/llvm-goc+0x7973a9)
#19 0x00005621890cecc6 Block::import_block(Block*, Import_function_body*, Location) (.localalias.85) (bin/llvm-goc+0x743cc6)
#20 0x0000562189121d01 Block_statement::do_import(Import_function_body*, Location, bool*) (.localalias.87) (bin/llvm-goc+0x796d01)
#21 0x000056218912240c Statement::import_statement(Import_function_body*, Location) (bin/llvm-goc+0x79740c)
#22 0x00005621890cecc6 Block::import_block(Block*, Import_function_body*, Location) (.localalias.85) (bin/llvm-goc+0x743cc6)
#23 0x00005621890daac2 Function_declaration::import_function_body(Gogo*, Named_object*) (.localalias.76) (bin/llvm-goc+0x74fac2)
#24 0x00005621890dacf1 Gogo::lower_parse_tree() (bin/llvm-goc+0x74fcf1)
#25 0x00005621890ba8f0 go_parse_input_files(char const**, unsigned int, bool, bool) (bin/llvm-goc+0x72f8f0)
#26 0x00005621890a2c1a gollvm::driver::CompileGoImpl::invokeFrontEnd() (.localalias.4) (bin/llvm-goc+0x717c1a)
#27 0x00005621890aaeb8 gollvm::driver::CompileGo::performAction(gollvm::driver::Compilation&, gollvm::driver::Action const&, llvm::SmallVector<gollvm::driver::Artifact*, 3u> const&, gollvm::driver::Artifact const&) (.localalias.13) (bin/llvm-goc+0x71feb8)
#28 0x000056218909c2f5 gollvm::driver::Driver::processAction(gollvm::driver::Action*, gollvm::driver::Compilation&, bool) (.localalias.0) (bin/llvm-goc+0x7112f5)
#29 0x000056218909c3ff gollvm::driver::Driver::processActions(gollvm::driver::Compilation&) (bin/llvm-goc+0x7113ff)
#30 0x0000562188fc3fd1 main (bin/llvm-goc+0x638fd1)
#31 0x00007fb3ed8382e1 __libc_start_main /build/glibc-77giwP/glibc-2.24/csu/../csu/libc-start.c:325:0
#32 0x00005621890939aa _start (bin/llvm-goc+0x7089aa)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.

We can use the following C program to show that mpfr_set_ui cannot work with mpfr_clear.

#include <stdio.h>
#include <mpfr.h>
int main (void)
{

  mpfr_t s;
  mpfr_set_ui(s, 0, MPFR_RNDN);
  // mpfr_init_set_ui(s, 0, MPFR_RNDN); <-- can fix the issue
  mpfr_out_str (stdout, 10, 0, s, MPFR_RNDD);
  putchar('\n');
  mpfr_clear(s);
  return 0;
}
@tianxiaogu tianxiaogu changed the title gollvm/frontend: llvm-goc crashes when importing complex(0) gollvm/gofrontend: llvm-goc crashes when importing complex(0) May 12, 2022
@heschi
Copy link
Contributor

heschi commented May 12, 2022

cc @thanm

@heschi heschi added the NeedsFix The path to resolution is known, but the work has not been done. label May 12, 2022
@heschi heschi added this to the Backlog milestone May 12, 2022
@gopherbot
Copy link

Change https://go.dev/cl/413980 mentions this issue: test: add test that caused gofrontend crash

@gopherbot
Copy link

Change https://go.dev/cl/413981 mentions this issue: compiler: always initialize mpfr in integer import

gopherbot pushed a commit that referenced this issue Jun 27, 2022
The gofrontend crashed importing a complex 0 constant.

For #52862

Change-Id: Ia87d8eadb9c5ddf51e1cd65c1a626f05f0d068d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/413980
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
realqhc pushed a commit to realqhc/gofrontend that referenced this issue Aug 4, 2022
Test case is https://go.dev/cl/413980.

Fixes golang/go#52862

Change-Id: I2233878df0ee075a5cc60e32151cc9802e9b7075
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/413981
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
jproberts pushed a commit to jproberts/go that referenced this issue Aug 10, 2022
The gofrontend crashed importing a complex 0 constant.

For golang#52862

Change-Id: Ia87d8eadb9c5ddf51e1cd65c1a626f05f0d068d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/413980
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
@golang golang locked and limited conversation to collaborators Jun 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants