|
848 | 848 | end |
849 | 849 | end |
850 | 850 |
|
| 851 | +@testset "static assertions" begin |
| 852 | + mod = @eval module $(gensym()) |
| 853 | + using ..GPUCompiler |
| 854 | + kernel() = (@static_assert true "this should disappear"; return) |
| 855 | + end |
| 856 | + |
| 857 | + llvm = sprint(io -> Native.code_llvm(io, mod.kernel, Tuple{}; dump_module=true)) |
| 858 | + @test !occursin(GPUCompiler.STATIC_ASSERT_MARKER, llvm) |
| 859 | + @test Native.code_execution(mod.kernel, Tuple{}) !== nothing |
| 860 | + |
| 861 | + mod = @eval module $(gensym()) |
| 862 | + using ..GPUCompiler |
| 863 | + kernel() = (@static_assert false "the target is too old"; return) |
| 864 | + end |
| 865 | + @test_throws_message(InvalidIRError, |
| 866 | + Native.code_execution(mod.kernel, Tuple{})) do msg |
| 867 | + occursin(GPUCompiler.STATIC_ASSERTION, msg) && |
| 868 | + occursin("the target is too old", msg) && |
| 869 | + occursin("kernel", msg) |
| 870 | + end |
| 871 | + |
| 872 | + mod = @eval module $(gensym()) |
| 873 | + using ..GPUCompiler |
| 874 | + function kernel(condition) |
| 875 | + @static_assert condition "condition was not proven" |
| 876 | + return |
| 877 | + end |
| 878 | + end |
| 879 | + @test_throws_message(InvalidIRError, |
| 880 | + Native.code_execution(mod.kernel, Tuple{Bool}; opt_level=0)) do msg |
| 881 | + occursin(GPUCompiler.STATIC_ASSERTION, msg) && |
| 882 | + occursin("condition was not proven", msg) |
| 883 | + end |
| 884 | + |
| 885 | + mod = @eval module $(gensym()) |
| 886 | + using ..GPUCompiler |
| 887 | + function kernel() |
| 888 | + if false |
| 889 | + @static_assert false "dead assertion" |
| 890 | + end |
| 891 | + return |
| 892 | + end |
| 893 | + end |
| 894 | + @test Native.code_execution(mod.kernel, Tuple{}; opt_level=0) !== nothing |
| 895 | + |
| 896 | + mod = @eval module $(gensym()) |
| 897 | + using ..GPUCompiler |
| 898 | + function kernel(condition) |
| 899 | + @static_assert condition "first failure" |
| 900 | + @static_assert condition "second failure" |
| 901 | + return |
| 902 | + end |
| 903 | + end |
| 904 | + @test_throws_message(InvalidIRError, |
| 905 | + Native.code_execution(mod.kernel, Tuple{Bool})) do msg |
| 906 | + occursin("first failure", msg) && occursin("second failure", msg) && |
| 907 | + !occursin("unknown function", msg) |
| 908 | + end |
| 909 | + |
| 910 | + mod = @eval module $(gensym()) |
| 911 | + using ..GPUCompiler |
| 912 | + @inline assertion() = @static_assert false "inlined failure" |
| 913 | + kernel() = (assertion(); return) |
| 914 | + end |
| 915 | + @test_throws_message(InvalidIRError, |
| 916 | + Native.code_execution(mod.kernel, Tuple{})) do msg |
| 917 | + occursin("inlined failure", msg) && |
| 918 | + occursin("assertion", msg) && occursin("kernel", msg) |
| 919 | + end |
| 920 | + |
| 921 | + @test_throws ArgumentError macroexpand(mod, :(@static_assert true string("message"))) |
| 922 | +end |
| 923 | + |
851 | 924 | @testset "invalid LLVM IR (ccall)" begin |
852 | 925 | mod = @eval module $(gensym()) |
853 | 926 | function foobar(p) |
|
0 commit comments