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

compiler_rt testing #7798

Closed
jkthorne opened this issue May 19, 2019 · 12 comments
Closed

compiler_rt testing #7798

jkthorne opened this issue May 19, 2019 · 12 comments

Comments

@jkthorne
Copy link
Contributor

I have been trying to test the compiler_rt flag and am a bit confused. It seems like the file is being loaded and the functions are not being used.

I have put a raise "testing" inside the __mulodi4 rt function.
https://github.com/crystal-lang/crystal/blob/master/src/crystal/compiler_rt.cr#L4

After building crystal and running .build/crystal eval "puts 1_i64 * 1_i64" I would expect crystal to raise "testing" and it does not.

I have checked the build output and the "compiler_rt" flag is being passed.

$ make
Using /usr/local/opt/llvm@6/bin/llvm-config [version=6.0.1]
c++ -c  -o src/llvm/ext/llvm_ext.o src/llvm/ext/llvm_ext.cc -I/usr/local/Cellar/llvm@6/6.0.1_1/include  -stdlib=libc++ -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -DNDEBUG   -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
cc -fPIC    -c -o src/ext/sigfault.o src/ext/sigfault.c
ar -rcs src/ext/libcrystal.a src/ext/sigfault.o
CRYSTAL_CONFIG_PATH="/Users/jack/source_code/open_source/crystal/src" CRYSTAL_CONFIG_LIBRARY_PATH="/usr/local/Cellar/crystal/0.28.0/embedded/lib" CRYSTAL_CONFIG_BUILD_COMMIT="8e3075027" ./bin/crystal build -D preview_overflow -D compiler_rt  -o .build/crystal src/compiler/crystal.cr -D without_openssl -D without_zlib

also if I put a raise in the file itself after the compile check and it seems like the file is being loaded.

Am I missing something?

@asterite
Copy link
Member

You need to use bin/crystal

@asterite
Copy link
Member

instead of .build/crystal

@jkthorne
Copy link
Contributor Author

@asterite I just rebuilt on master and I am still not seeing a raise.

$ bin/crystal eval "puts 1_i64 * 1_i64"
Using compiled compiler at `.build/crystal'
1

@asterite
Copy link
Member

Because multiplying two int64 is just an llmv primitive (I think mul), I don't see why compiler rt would be involved.

@asterite
Copy link
Member

Oh, it's with overflow. Did you try with -D preview_overflow?

@jkthorne
Copy link
Contributor Author

When building the compiler -D preview_overflow is there.

I am pretty sure the file is being loaded.
When I cause an overflow I am kind of suprised by the results but that seems like another issue.

@asterite
Copy link
Member

You need to pass the flag when compiling any program, not just the compiler. I don't think bin crystal passes it.

@jkthorne
Copy link
Contributor Author

It seems like it still does not work how I would expect.

$ bin/crystal eval "puts 1_i64 * 1_i64" -D preview_overflow -D compiler_rt
Using compiled compiler at `.build/crystal'
1

@asterite
Copy link
Member

There could be many reasons:

  • LLVM notices the result is obvious and doesn't need to call that function
  • compiler_rt isn't used in all platforms

@jkthorne
Copy link
Contributor Author

I have tried compiling this on linux and I have been getting the same results.

I am curious I have not used fun on the top-level before.
Is that where it should go?

@ysbaddaden
Copy link
Contributor

AFAIK compiler_rt is only used on a few platforms that miss some features (i.e. Int128 on i386 arch). It's not used or linked for anything else or any other architecture.

I.e. it's just a convenience to implement some features that would be otherwise broken on some targets. It's not used unless it really has to.

@bcardiff
Copy link
Member

@ysbaddaden is right. The compiler_rt.cr is used in 32bits arch to multiply 64 bits integers.
In 64 bits the 64bits multiplication (ie: @llvm.smul.with.overflow.i64 do not use __mulodi4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants