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

ci: add meson build/tests with asan/ubsan/msan #101

Merged
merged 18 commits into from
Oct 17, 2024
Merged

Conversation

mochaaP
Copy link
Contributor

@mochaaP mochaaP commented Oct 11, 2024

Notes:

  • msan is not supported on gcc
  • msvc has limited support - namely on globals + ctest

Additional smoke tests that are not in this PR - let me know if you're interested in any of them:

  • doesn't cover tcc/chibicc - they require manual builds
  • doesn't cover clang static checks - out of scope & need clang tooling configuration
  • doesn't cover mingw native/cross builds
  • doesn't cover zig cc (clang + cross tuples) builds
  • code coverage integration

@mochaaP mochaaP force-pushed the v50dev branch 3 times, most recently from ed0b38a to 6c8739f Compare October 11, 2024 02:31
@mochaaP mochaaP changed the title ci: add meson build/tests with asan/ubsan/msan ci: add meson build/tests with asan/ubsan Oct 11, 2024
@mochaaP
Copy link
Contributor Author

mochaaP commented Oct 11, 2024

ubsan fails on my machine:

gcc:

stderr:
../include/stc/stack.h:72:13: runtime error: applying non-zero offset 18446744073709551615 to null pointer
    #0 0x402026 in stack_c_clear ../include/stc/stack.h:72
    #1 0x40211b in stack_c_drop ../include/stc/stack.h:78
    #2 0x402678 in main ../misc/examples/vectors/stack.c:29
    #3 0x7f4e558121c7 in __libc_start_call_main (/lib64/libc.so.6+0x41c7) (BuildId: 9c36f77df28d1669a4f90a66c6da3fe355a08add)
    #4 0x7f4e5581228a in __libc_start_main_impl (/lib64/libc.so.6+0x428a) (BuildId: 9c36f77df28d1669a4f90a66c6da3fe355a08add)
    #5 0x4011b4 in _start (/home/mochaa/ghq/github.com/stclib/STC/build/misc/examples/vectors/stack+0x4011b4) (BuildId: fe1e2b4122e0bb621ca77b791a0ea5a4ba221a03)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../include/stc/stack.h:72:13 in 

clang:

../include/stc/stack.h:71:30: runtime error: applying zero offset to null pointer
    #0 0x0000004e42da in stack_c_clear /home/mochaa/ghq/github.com/stclib/STC/build-clang/../include/stc/stack.h:71:30
    #1 0x0000004e3ac4 in stack_c_drop /home/mochaa/ghq/github.com/stclib/STC/build-clang/../include/stc/stack.h:78:5
    #2 0x0000004e2ee8 in main /home/mochaa/ghq/github.com/stclib/STC/build-clang/../misc/examples/vectors/stack.c:29:5
    #3 0x7ff5bc2881c7 in __libc_start_call_main (/lib64/libc.so.6+0x41c7) (BuildId: 9c36f77df28d1669a4f90a66c6da3fe355a08add)
    #4 0x7ff5bc28828a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x428a) (BuildId: 9c36f77df28d1669a4f90a66c6da3fe355a08add)
    #5 0x000000401374 in _start (/home/mochaa/ghq/github.com/stclib/STC/build-clang/misc/examples/vectors/stack+0x401374) (BuildId: fe8e4ae99b482c5e9e3ba6f8b245f1e875ca03bc)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../include/stc/stack.h:71:30 

@mochaaP
Copy link
Contributor Author

mochaaP commented Oct 11, 2024

clang detects more error:

../misc/examples/coroutines/cotasks2.c:97:5: runtime error: call to function consume_items through pointer to incorrect function type 'int (*)(struct cco_task *, struct cco_runtime *)'
/home/mochaa/ghq/github.com/stclib/STC/build-clang/../misc/examples/coroutines/cotasks2.c:71: note: consume_items defined here
    #0 0x0000004e573a in main /home/mochaa/ghq/github.com/stclib/STC/build-clang/../misc/examples/coroutines/cotasks2.c:97:5
    #1 0x7f65ed7db1c7 in __libc_start_call_main (/lib64/libc.so.6+0x41c7) (BuildId: 9c36f77df28d1669a4f90a66c6da3fe355a08add)
    #2 0x7f65ed7db28a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x428a) (BuildId: 9c36f77df28d1669a4f90a66c6da3fe355a08add)
    #3 0x0000004013a4 in _start (/home/mochaa/ghq/github.com/stclib/STC/build-clang/misc/examples/coroutines/cotasks2+0x4013a4) (BuildId: 493b0e9de2e42e26b2fa80fc3a2f72d7eea845d0)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../misc/examples/coroutines/cotasks2.c:97:5 
../misc/examples/coroutines/filetask.c:80:5: runtime error: call to function count_line through pointer to incorrect function type 'int (*)(struct cco_task *, struct cco_runtime *)'
/home/mochaa/ghq/github.com/stclib/STC/build-clang/../misc/examples/coroutines/filetask.c:49: note: count_line defined here
    #0 0x0000004e4a5d in main /home/mochaa/ghq/github.com/stclib/STC/build-clang/../misc/examples/coroutines/filetask.c:80:5
    #1 0x7fcd2a0851c7 in __libc_start_call_main (/lib64/libc.so.6+0x41c7) (BuildId: 9c36f77df28d1669a4f90a66c6da3fe355a08add)
    #2 0x7fcd2a08528a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x428a) (BuildId: 9c36f77df28d1669a4f90a66c6da3fe355a08add)
    #3 0x000000401384 in _start (/home/mochaa/ghq/github.com/stclib/STC/build-clang/misc/examples/coroutines/filetask+0x401384) (BuildId: c8adf8b2cbdca7d5937a082fa4cd76770bbb3cb9)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../misc/examples/coroutines/filetask.c:80:5 

@mochaaP mochaaP force-pushed the v50dev branch 2 times, most recently from 2aa946d to 2e6b01f Compare October 11, 2024 06:48
@mochaaP mochaaP changed the title ci: add meson build/tests with asan/ubsan ci: add meson build/tests with asan/ubsan/msan Oct 11, 2024
@mochaaP mochaaP force-pushed the v50dev branch 11 times, most recently from ce832c1 to f5bd0d1 Compare October 11, 2024 08:07
@mochaaP
Copy link
Contributor Author

mochaaP commented Oct 11, 2024

All test passed 🥳

@mochaaP
Copy link
Contributor Author

mochaaP commented Oct 15, 2024

cc @tylov - anytime to check on this?

@tylov
Copy link
Collaborator

tylov commented Oct 15, 2024

Thanks, will do tonight.

@mochaaP
Copy link
Contributor Author

mochaaP commented Oct 15, 2024

you shall also sort the additional tests and integrations by your interest, so I could implement this in a specific order. my personal priority:

  1. clang-format (need to discuss a sane config), clang-tidy, scan-build
  2. codecov
  3. mingw cross builds
  4. stcsingle & utf8_tab custom target
  5. zig cc builds
  6. tcc build script

Copy link
Collaborator

@tylov tylov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, but why include <stdio.h>?

Copy link
Collaborator

@tylov tylov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intention was to use size_t and not uint64_t for hashing because it should work optimally on 32-bit as well. The hash function is designed for that. You can include <stddef.h> to get size_t on all platforms.

@mochaaP
Copy link
Contributor Author

mochaaP commented Oct 16, 2024

Great, but why include <stdio.h>?

Seems clangd auto-included that and I didn't notice. Will fix it.

@mochaaP
Copy link
Contributor Author

mochaaP commented Oct 16, 2024

My intention was to use size_t and not uint64_t for hashing because it should work optimally on 32-bit as well. The hash function is designed for that. You can include <stddef.h> to get size_t on all platforms.

I see many inconsistencies in the repo:
uint32_t: https://github.com/stclib/STC/blob/v50dev/docs/hmap_api.md?plain=1#L288
size_t, uint64_t: aforementioned

there are also many APIs using uint64_t as the hash return type. if you'd like to refactor it, let's move it to another PR :)

@tylov tylov merged commit 00f46ca into stclib:v50dev Oct 17, 2024
21 checks passed
@tylov
Copy link
Collaborator

tylov commented Oct 17, 2024

Thanks for this contribution! I will test this out some more, but it's a very good start.

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

Successfully merging this pull request may close these issues.

2 participants