Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ab4fe38
Update loc_history.py
tobiashienzsch Sep 20, 2025
ef53b56
Rename AVR cmake toolchain file
tobiashienzsch Sep 21, 2025
2320bca
Rename ARM & RISCV cmake toolchain files
tobiashienzsch Sep 21, 2025
e4d1553
[chrono] Fix conversion warnings on avr clang builds
tobiashienzsch Sep 21, 2025
8bd9ec1
[cmath] Disable builtins for erf & log2 on clang AVR builds.
tobiashienzsch Sep 21, 2025
1373775
Upgrade clang-format to v21.1.2
tobiashienzsch Sep 26, 2025
d7721d9
Add clang ARM Toolchain for Embedded (ATfE) cmake toolchain
tobiashienzsch Sep 29, 2025
32b195a
[algorithm] Use merge_sort as default stable_sort
tobiashienzsch Sep 29, 2025
a1f4f39
[algorithm] Add quick_sort
tobiashienzsch Sep 29, 2025
dfc0290
[random] Use lerp in uniform_real_distribution
tobiashienzsch Sep 30, 2025
51038bd
[bit] Fix conversion warning in bit_ceil
tobiashienzsch Sep 30, 2025
3369259
[fuzzing] Use CMake for fuzz builds
tobiashienzsch Sep 30, 2025
e47e85c
[algorithm] Fix exchange_sort for empty ranges
tobiashienzsch Sep 30, 2025
19f22cd
[fuzzing] More tests
tobiashienzsch Sep 30, 2025
6275b58
[fuzzing] More algorithm & string_view tests
tobiashienzsch Oct 2, 2025
1353e7a
[string_view] Fix find_last_of for empty strings
tobiashienzsch Oct 2, 2025
80630fa
[fuzzing] Fix copy-paste error in string_view.ends_with
tobiashienzsch Oct 2, 2025
42eccf5
[algorithm] Reenable temporary gcc shift_right fix
tobiashienzsch Oct 2, 2025
7594e39
[string_view] Fix find_last_not_of for empty strings
tobiashienzsch Oct 2, 2025
3898854
[fuzzing] More string_view fuzzing
tobiashienzsch Oct 2, 2025
a258c8a
Fix build-atfe.sh compile step
tobiashienzsch Oct 2, 2025
2e65514
[algorithm] Fix naming in quick_sort
tobiashienzsch Oct 2, 2025
f2f3b33
[algorithm] Implement nth_element
tobiashienzsch Oct 2, 2025
e77ca76
[scripts] Add utility to compare sort algorithms
tobiashienzsch Oct 2, 2025
74d3ddf
[algorithm] Fix naming in nth_element
tobiashienzsch Oct 2, 2025
9721a41
[algorithm] Fix clang-tidy warnings in nth_element
tobiashienzsch Oct 2, 2025
4071836
[fuzzing] Add nth_element test
tobiashienzsch Oct 2, 2025
d2a9eb1
[algorithm] Cleanup nth_element
tobiashienzsch Oct 2, 2025
489ad5c
[cctype] Remove redundant casts
tobiashienzsch Oct 3, 2025
61fd80b
[fuzzing] More algorithm tests
tobiashienzsch Oct 3, 2025
70a47e3
[fuzzing] Apply clang-tidy auto fixes
tobiashienzsch Oct 3, 2025
6098992
[fuzzing] Add chrono tests
tobiashienzsch Oct 3, 2025
3e132d1
[fuzzing] Cleanup uniform_int_distribution
tobiashienzsch Oct 3, 2025
96698dd
[fuzzing] Cleanup LLVMFuzzerTestOneInput entry point
tobiashienzsch Oct 3, 2025
2338172
[fuzzing] Add cstring tests
tobiashienzsch Oct 3, 2025
a7c3663
[fuzzing] Increase input lengths
tobiashienzsch Oct 4, 2025
a9fa73a
[fuzzing] Always print output to stderr
tobiashienzsch Oct 5, 2025
77703e4
Upgrade reuse-tool to v6.1.0
tobiashienzsch Oct 7, 2025
97ba500
Remove unused clang-format directives
tobiashienzsch Oct 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Checks:

- modernize-*
- -modernize-deprecated-headers
- -modernize-use-ranges
- -modernize-use-std-numbers
- -modernize-use-std-print

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/freestanding-arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
-S .
-B cmake-build-gcc
-G "Ninja Multi-Config"
-D CMAKE_TOOLCHAIN_FILE=cmake/toolchain/gcc-arm-none-eabi.cmake
-D CMAKE_TOOLCHAIN_FILE=cmake/toolchain/arm-none-eabi-gcc.cmake
-D CMAKE_CXX_STANDARD=${{ matrix.cxx }}
-D CMAKE_COMPILE_WARNING_AS_ERROR=ON
-D TETL_BUILD_CONTRACT_CHECKS=OFF
Expand All @@ -63,7 +63,7 @@ jobs:
-S .
-B cmake-build-clang
-G "Ninja Multi-Config"
-D CMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang-arm-none-eabi.cmake
-D CMAKE_TOOLCHAIN_FILE=cmake/toolchain/arm-none-eabi-clang.cmake
-D CMAKE_CXX_STANDARD=${{ matrix.cxx }}
-D CMAKE_COMPILE_WARNING_AS_ERROR=ON
-D TETL_BUILD_CONTRACT_CHECKS=OFF
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/freestanding-avr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
cmake -S .
-B build
-G "Ninja Multi-Config"
-D CMAKE_TOOLCHAIN_FILE=cmake/toolchain/atmega2560.cmake
-D CMAKE_TOOLCHAIN_FILE=cmake/toolchain/avr-gcc.cmake
-D CMAKE_CXX_STANDARD=${{ matrix.cxx }}
-D CMAKE_COMPILE_WARNING_AS_ERROR=ON
-D TETL_BUILD_CONTRACT_CHECKS=OFF
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/freestanding-riscv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
-S .
-B build
-G "Ninja Multi-Config"
-D CMAKE_TOOLCHAIN_FILE=cmake/toolchain/gcc-riscv-none-elf.cmake
-D CMAKE_TOOLCHAIN_FILE=cmake/toolchain/riscv-none-elf-gcc.cmake
-D CMAKE_CXX_STANDARD=${{ matrix.cxx }}
-D CMAKE_COMPILE_WARNING_AS_ERROR=ON
-D TETL_BUILD_CONTRACT_CHECKS=OFF
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v21.1.1
rev: v21.1.2
hooks:
- id: clang-format
types_or: [c++, c]

- repo: https://github.com/fsfe/reuse-tool
rev: v5.1.1
rev: v6.1.0
hooks:
- id: reuse
6 changes: 3 additions & 3 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{
"name": "avr-gcc",
"description": "Configure with avr-gcc toolchain",
"toolchainFile": "${sourceDir}/cmake/toolchain/atmega2560.cmake",
"toolchainFile": "${sourceDir}/cmake/toolchain/avr-gcc.cmake",
"inherits": ["_root-config"],
"cacheVariables": {
"TETL_BUILD_CONTRACT_CHECKS": false
Expand All @@ -39,7 +39,7 @@
{
"name": "arm-gcc",
"description": "Configure with arm-gcc toolchain",
"toolchainFile": "${sourceDir}/cmake/toolchain/gcc-arm-none-eabi.cmake",
"toolchainFile": "${sourceDir}/cmake/toolchain/arm-none-eabi-gcc.cmake",
"inherits": ["_root-config"],
"cacheVariables": {
"TETL_BUILD_CONTRACT_CHECKS": false
Expand All @@ -48,7 +48,7 @@
{
"name": "arm-clang",
"description": "Configure with arm-clang toolchain",
"toolchainFile": "${sourceDir}/cmake/toolchain/clang-arm-none-eabi.cmake",
"toolchainFile": "${sourceDir}/cmake/toolchain/arm-none-eabi-clang.cmake",
"inherits": ["_root-config"],
"cacheVariables": {
"TETL_BUILD_CONTRACT_CHECKS": false
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ctest --test-dir cmake-build-emscripten -C Debug --output-on-failure

```sh
# AVR
cmake -S . -B cmake-build-avr-gcc -G "Ninja Multi-Config" -D CMAKE_TOOLCHAIN_FILE="cmake/toolchain/atmega2560.cmake"
cmake -S . -B cmake-build-avr-gcc -G "Ninja Multi-Config" -D CMAKE_TOOLCHAIN_FILE="cmake/toolchain/avr-gcc.cmake"
cmake --build cmake-build-avr-gcc --config Debug
```

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ For examples look at the [examples](./examples) subdirectory or the test files i

### Freestanding

| **Platform** | **Status** | **Notes** |
| :----------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------: |
| **ARM** | [![ARM](https://github.com/tobanteEmbedded/tetl/actions/workflows/freestanding-arm.yml/badge.svg)](https://github.com/tobanteEmbedded/tetl/actions/workflows/freestanding-arm.yml) | GCC 15 |
| **AVR** | [![AVR](https://github.com/tobanteEmbedded/tetl/actions/workflows/freestanding-avr.yml/badge.svg)](https://github.com/tobanteEmbedded/tetl/actions/workflows/freestanding-avr.yml) | GCC 15 |
| **MSP430** | [![MSP430](https://github.com/tobanteEmbedded/tetl/actions/workflows/freestanding-msp430.yml/badge.svg)](https://github.com/tobanteEmbedded/tetl/actions/workflows/freestanding-msp430.yml) | GCC 14 |
| **RISCV** | [![RISCV](https://github.com/tobanteEmbedded/tetl/actions/workflows/freestanding-riscv.yml/badge.svg)](https://github.com/tobanteEmbedded/tetl/actions/workflows/freestanding-riscv.yml) | GCC 15 |
| **Platform** | **Status** | **Notes** |
| :----------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------: |
| **ARM** | [![ARM](https://github.com/tobanteEmbedded/tetl/actions/workflows/freestanding-arm.yml/badge.svg)](https://github.com/tobanteEmbedded/tetl/actions/workflows/freestanding-arm.yml) | GCC 15 & Clang 20 |
| **AVR** | [![AVR](https://github.com/tobanteEmbedded/tetl/actions/workflows/freestanding-avr.yml/badge.svg)](https://github.com/tobanteEmbedded/tetl/actions/workflows/freestanding-avr.yml) | GCC 15 |
| **MSP430** | [![MSP430](https://github.com/tobanteEmbedded/tetl/actions/workflows/freestanding-msp430.yml/badge.svg)](https://github.com/tobanteEmbedded/tetl/actions/workflows/freestanding-msp430.yml) | GCC 14 |
| **RISCV** | [![RISCV](https://github.com/tobanteEmbedded/tetl/actions/workflows/freestanding-riscv.yml/badge.svg)](https://github.com/tobanteEmbedded/tetl/actions/workflows/freestanding-riscv.yml) | GCC 15 |

### Analysis

Expand Down
49 changes: 49 additions & 0 deletions cmake/toolchain/arm-atfe.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# SPDX-License-Identifier: BSL-1.0
# SPDX-FileCopyrightText: Copyright (C) 2025 Tobias Hienzsch

include_guard(GLOBAL)

set(ATFE_TOOLCHAIN "" CACHE STRING "Path to ARM toolchain for Embedded")

if(NOT DEFINED ATFE_TOOLCHAIN)
message(FATAL_ERROR "Could not find ATfE. Use CMake variable ATFE_TOOLCHAIN")
else()
if(NOT EXISTS "${ATFE_TOOLCHAIN}/bin/clang")
message(FATAL_ERROR "ATFE_TOOLCHAIN does not point to a valid ATfE installation")
endif()
endif()

set(CMAKE_SYSTEM_NAME Generic-ELF)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

set(CMAKE_C_COMPILER "${ATFE_TOOLCHAIN}/bin/clang")
set(CMAKE_CXX_COMPILER "${ATFE_TOOLCHAIN}/bin/clang++")

set(ARCH_FLAGS "--target=armv6m-none-eabi -march=armv6m -mfpu=none -mfloat-abi=soft -flto")
set(CPP_FLAGS "-fno-exceptions -fno-rtti")

set(CMAKE_C_FLAGS_DEBUG "${ARCH_FLAGS} -O0 -g3")
set(CMAKE_CXX_FLAGS_DEBUG "${ARCH_FLAGS} ${CPP_FLAGS} -O0 -g3")

set(CMAKE_C_FLAGS_RELWITHDEBINFO "${ARCH_FLAGS} -O3 -g3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${ARCH_FLAGS} ${CPP_FLAGS} -O3 -g3 -DNDEBUG")

set(CMAKE_C_FLAGS_RELEASE "${ARCH_FLAGS} -O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${ARCH_FLAGS} ${CPP_FLAGS} -O3 -DNDEBUG")

set(CMAKE_C_FLAGS_MINSIZEREL "${ARCH_FLAGS} -Oz -g3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${ARCH_FLAGS} ${CPP_FLAGS} -Oz -g3 -DNDEBUG")

add_link_options(
-nostartfiles
-lcrt0-semihost
-lsemihost
-Wl,--gc-sections
-Wl,-T "${ATFE_TOOLCHAIN}/samples/ldscripts/microbit.ld"
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include_guard(GLOBAL)

list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}")
include(stm32)
include(arm-none-eabi)

execute_process(
COMMAND arm-none-eabi-gcc ${MCU} -print-sysroot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include_guard(GLOBAL)

list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}")
include(stm32)
include(arm-none-eabi)

set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_SYSTEM_NAME Generic-ELF)
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 0 additions & 10 deletions fuzzing/.gitignore

This file was deleted.

108 changes: 108 additions & 0 deletions fuzzing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# SPDX-License-Identifier: BSL-1.0
# SPDX-FileCopyrightText: Copyright (C) 2025 Tobias Hienzsch
cmake_minimum_required(VERSION 3.28)
project(tetl-fuzzing LANGUAGES CXX)

if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
message(FATAL_ERROR "tetl-fuzzing needs to build with clang & libFuzzer")
endif()

find_program(CCACHE ccache)
if(CCACHE)
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer,address,undefined -ftest-coverage -fcoverage-mapping -fprofile-arcs -fprofile-instr-generate")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

enable_testing()

function(tetl_add_fuzz_test _target)
set(target_name "${_target}.fuzz")

add_executable(${target_name} "src/${target_name}.cpp")
target_include_directories(${target_name} PRIVATE "./include" "../include")
target_compile_options(${target_name} PRIVATE
"-Werror"
"-Weverything"
"-Wno-c++98-compat-pedantic"
"-Wno-c++98-compat"
"-Wno-ctad-maybe-unsupported"
"-Wno-exit-time-destructors"
"-Wno-float-equal"
"-Wno-implicit-int-conversion"
"-Wno-missing-prototypes"
"-Wno-nrvo"
"-Wno-padded"
"-Wno-unsafe-buffer-usage"
)

add_test(NAME "${target_name}" COMMAND ${target_name} -max_total_time=60)
set_tests_properties("${target_name}" PROPERTIES ENVIRONMENT "LLVM_PROFILE_FILE=raw/%p-%m.profraw")
set_tests_properties("${target_name}" PROPERTIES WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
endfunction()

tetl_add_fuzz_test("algorithm.adjacent_find")
tetl_add_fuzz_test("algorithm.binary_search")
tetl_add_fuzz_test("algorithm.bubble_sort")
tetl_add_fuzz_test("algorithm.equal_range")
tetl_add_fuzz_test("algorithm.equal")
tetl_add_fuzz_test("algorithm.exchange_sort")
tetl_add_fuzz_test("algorithm.gnome_sort")
tetl_add_fuzz_test("algorithm.insertion_sort")
tetl_add_fuzz_test("algorithm.is_partitioned")
tetl_add_fuzz_test("algorithm.is_permutation")
tetl_add_fuzz_test("algorithm.lexicographical_compare")
tetl_add_fuzz_test("algorithm.max_element")
tetl_add_fuzz_test("algorithm.merge_sort")
tetl_add_fuzz_test("algorithm.min_element")
tetl_add_fuzz_test("algorithm.minmax_element")
tetl_add_fuzz_test("algorithm.mismatch")
# tetl_add_fuzz_test("algorithm.nth_element")
tetl_add_fuzz_test("algorithm.partition")
tetl_add_fuzz_test("algorithm.quick_sort")
tetl_add_fuzz_test("algorithm.reverse")
tetl_add_fuzz_test("algorithm.search")
tetl_add_fuzz_test("algorithm.set_difference")
tetl_add_fuzz_test("algorithm.set_intersection")
tetl_add_fuzz_test("algorithm.set_symmetric_difference")
tetl_add_fuzz_test("algorithm.set_union")
tetl_add_fuzz_test("algorithm.shift_left")
# tetl_add_fuzz_test("algorithm.shift_right")
tetl_add_fuzz_test("bit.bit_ceil")
tetl_add_fuzz_test("bit.bit_floor")
tetl_add_fuzz_test("bit.bit_width")
tetl_add_fuzz_test("bit.byteswap")
tetl_add_fuzz_test("bit.countl_one")
tetl_add_fuzz_test("bit.countl_zero")
tetl_add_fuzz_test("bit.countr_one")
tetl_add_fuzz_test("bit.countr_zero")
tetl_add_fuzz_test("bit.has_single_bit")
tetl_add_fuzz_test("bit.popcount")
tetl_add_fuzz_test("bitset")
tetl_add_fuzz_test("cctype")
tetl_add_fuzz_test("charconv.from_chars")
tetl_add_fuzz_test("charconv.to_chars")
tetl_add_fuzz_test("chrono.duration")
tetl_add_fuzz_test("chrono.rounding")
tetl_add_fuzz_test("chrono.year_month_day")
tetl_add_fuzz_test("cmath.lerp")
tetl_add_fuzz_test("cstring.strcmp")
tetl_add_fuzz_test("cstring.strlen")
tetl_add_fuzz_test("cstring.strncmp")
tetl_add_fuzz_test("cstring.strstr")
tetl_add_fuzz_test("numeric.midpoint")
tetl_add_fuzz_test("random.uniform_int_distribution")
tetl_add_fuzz_test("random.uniform_real_distribution")
tetl_add_fuzz_test("string_view.contains")
tetl_add_fuzz_test("string_view.ends_with")
tetl_add_fuzz_test("string_view.find_first_not_of")
tetl_add_fuzz_test("string_view.find_first_of")
tetl_add_fuzz_test("string_view.find_last_not_of")
tetl_add_fuzz_test("string_view.find_last_of")
tetl_add_fuzz_test("string_view.find")
tetl_add_fuzz_test("string_view.rfind")
tetl_add_fuzz_test("string_view.starts_with")
tetl_add_fuzz_test("string")
41 changes: 0 additions & 41 deletions fuzzing/Makefile

This file was deleted.

11 changes: 6 additions & 5 deletions fuzzing/src/fuzzing.hpp → fuzzing/include/fuzzing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <etl/system_error.hpp>

#include <charconv>
#include <format>
#include <map>
#include <print>
#include <stdexcept>
Expand All @@ -18,13 +19,13 @@
#define RUN(func) \
do { \
if (auto rc = func; rc != 0) { \
throw rc; \
throw std::runtime_error{std::format("fuzz failure: {}", rc)}; \
} \
} while (false)

namespace etl::fuzzing {

auto to_string(std::errc ec) -> std::string
inline auto to_string(std::errc ec) -> std::string
{
static auto map = std::map<std::errc, std::string>{
{ std::errc{}, "errc{}"},
Expand All @@ -36,7 +37,7 @@ auto to_string(std::errc ec) -> std::string
return map.at(ec);
}

auto to_std(etl::errc ec) -> std::errc
inline auto to_std(etl::errc ec) -> std::errc
{
static auto map = std::map<etl::errc, std::errc>{
{ etl::errc{}, std::errc{}},
Expand All @@ -47,11 +48,11 @@ auto to_std(etl::errc ec) -> std::errc

return map.at(ec);
}
auto to_std(etl::from_chars_result r) -> std::from_chars_result
inline auto to_std(etl::from_chars_result r) -> std::from_chars_result
{
return {.ptr = r.ptr, .ec = to_std(r.ec)};
}
auto to_std(etl::to_chars_result r) -> std::to_chars_result
inline auto to_std(etl::to_chars_result r) -> std::to_chars_result
{
return {.ptr = r.ptr, .ec = to_std(r.ec)};
}
Expand Down
Loading