From 50680d68931104036f0fdcd60a3f4da50a33bc80 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 25 Feb 2025 15:36:06 +0100 Subject: [PATCH] Fix bug casting bool to int to other int #1995. Use test_suite7 in CI. --- .github/workflows/main.yml | 14 +++++++------- releasenotes.md | 1 + src/compiler/sema_casts.c | 5 ++--- test/test_suite7/expressions/casts/cast_widened.c3 | 11 +++++++++++ 4 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 test/test_suite7/expressions/casts/cast_widened.c3 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a9e3754a7..30abc6c81 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -95,7 +95,7 @@ jobs: - name: run compiler tests run: | cd test - ..\build\${{ matrix.build_type }}\c3c.exe compile-run -O1 src/test_suite_runner.c3 --stdlib ..\lib7 --enable-new-generics -- ..\build\${{ matrix.build_type }}\c3c.exe test_suite/ + ..\build\${{ matrix.build_type }}\c3c.exe compile-run -O1 src/test_suite_runner.c3 --stdlib ..\lib7 --enable-new-generics -- ..\build\${{ matrix.build_type }}\c3c.exe test_suite7/ --stdlib ../lib7 - name: Test python script run: | @@ -169,7 +169,7 @@ jobs: run: | cd test ../build/c3c.exe compile --target windows-x64 -O1 src/test_suite_runner.c3 --stdlib ../lib7 --enable-new-generics - ./test_suite_runner.exe ../build/c3c.exe test_suite/ + ./test_suite_runner.exe ../build/c3c.exe test_suite7/ --stdlib ../lib7 build-msys2-clang: runs-on: windows-latest @@ -220,7 +220,7 @@ jobs: - name: run compiler tests run: | cd test - ../build/c3c.exe compile-run -O1 --stdlib ../lib7 src/test_suite_runner.c3 --enable-new-generics + ../build/c3c.exe compile-run -O1 --stdlib ../lib7 src/test_suite_runner.c3 --enable-new-generics test_suite7/ --stdlib ../lib7 build-linux: runs-on: ubuntu-22.04 @@ -381,7 +381,7 @@ jobs: - name: run compiler tests run: | cd test - ../build/c3c compile-run -O1 src/test_suite_runner.c3 --stdlib ../lib7 --enable-new-generics -- ../build/c3c test_suite/ + ../build/c3c compile-run -O1 src/test_suite_runner.c3 --stdlib ../lib7 --enable-new-generics -- ../build/c3c test_suite7/ --stdlib ../lib7 - name: bundle_output if: matrix.llvm_version == env.LLVM_RELEASE_VERSION_LINUX @@ -502,7 +502,7 @@ jobs: - name: run compiler tests run: | cd test - ../build/c3c compile-run -O1 src/test_suite_runner.c3 --stdlib ../lib7 --enable-new-generics -- ../build/c3c test_suite/ + ../build/c3c compile-run -O1 src/test_suite_runner.c3 --stdlib ../lib7 --enable-new-generics -- ../build/c3c test_suite7/ --stdlib ../lib7 - name: bundle_output if: matrix.llvm_version == env.LLVM_RELEASE_VERSION_UBUNTU20 @@ -606,7 +606,7 @@ jobs: - name: run compiler tests run: | cd test - ../build/c3c compile-run -O1 src/test_suite_runner.c3 --stdlib ../lib7 --enable-new-generics -- ../build/c3c test_suite/ + ../build/c3c compile-run -O1 src/test_suite_runner.c3 --stdlib ../lib7 --enable-new-generics -- ../build/c3c test_suite7/ --stdlib ../lib7 build-mac: runs-on: macos-latest @@ -687,7 +687,7 @@ jobs: run: | cd test ../build/c3c compile -O1 src/test_suite_runner.c3 --stdlib ../lib7 --enable-new-generics - ./test_suite_runner ../build/c3c test_suite/ + ./test_suite_runner ../build/c3c test_suite7/ --stdlib ../lib7 - name: run build test suite runner run: | diff --git a/releasenotes.md b/releasenotes.md index 02668a84a..1a3bcca56 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -25,6 +25,7 @@ - Don't delete .o files not produced by the compiler. - Fix optional jumps in expression lists, #1942. - Several fixes for .o files and -o output, improving handling and naming. +- Fix bug casting bool to int to other int #1995. ### Stdlib changes diff --git a/src/compiler/sema_casts.c b/src/compiler/sema_casts.c index ea6efb167..0241828c1 100644 --- a/src/compiler/sema_casts.c +++ b/src/compiler/sema_casts.c @@ -382,8 +382,7 @@ RETRY: case BINARYOP_LE: case BINARYOP_NE: case BINARYOP_EQ: - // This type is bool, so check should never happen. - UNREACHABLE + return NULL; case BINARYOP_CT_OR: case BINARYOP_CT_AND: case BINARYOP_CT_CONCAT: @@ -396,7 +395,7 @@ RETRY: case BINARYOP_VEC_NE: case BINARYOP_VEC_EQ: // Functions - return false; + return NULL; } UNREACHABLE diff --git a/test/test_suite7/expressions/casts/cast_widened.c3 b/test/test_suite7/expressions/casts/cast_widened.c3 new file mode 100644 index 000000000..f9b669e27 --- /dev/null +++ b/test/test_suite7/expressions/casts/cast_widened.c3 @@ -0,0 +1,11 @@ +module test; + +fn void main() +{ + uint i; + ulong* haystack; + ulong* needle; + uint is_found = 0; + is_found += (ulong)(haystack[0] == needle[0]); + is_found += (ulong)(haystack[1] == needle[1]); +} \ No newline at end of file