diff --git a/.codecov.yml b/.codecov.yml index bf0af362f5..8fe729a47c 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -2,8 +2,11 @@ codecov: branch: main fixes: - - "build/backends/::backends/" + - "build/interface/::interface/" - "build/gallery/::gallery/" + - "build/backends/::backends/" + - "build/t*/::tests/t*" + - "build/ex*/::examples/ceed/ex*" ignore: - "julia/LibCEED.jl/src/generated/*.jl" diff --git a/.github/workflows/c-fortan-test-ppc64le.yml b/.github/workflows/c-fortan-test-ppc64le.yml index f710c9ba12..b14f8928f6 100644 --- a/.github/workflows/c-fortan-test-ppc64le.yml +++ b/.github/workflows/c-fortan-test-ppc64le.yml @@ -19,7 +19,7 @@ jobs: steps: - name: Environment setup - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Hardware setup and test libCEED uses: uraimo/run-on-arch-action@v3 env: diff --git a/.github/workflows/c-fortran-test-arm64.yml b/.github/workflows/c-fortran-test-arm64.yml index 6927f37b68..ff1fa1288d 100644 --- a/.github/workflows/c-fortran-test-arm64.yml +++ b/.github/workflows/c-fortran-test-arm64.yml @@ -17,7 +17,7 @@ jobs: steps: - name: Environment setup - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Build and test libCEED env: CC: ${{ matrix.compiler }} diff --git a/.github/workflows/c-fortran-test-icc.yml b/.github/workflows/c-fortran-test-icc.yml index 4e854195b1..2689ffa130 100644 --- a/.github/workflows/c-fortran-test-icc.yml +++ b/.github/workflows/c-fortran-test-icc.yml @@ -19,7 +19,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - name: Install Intel compilers uses: rscohn2/setup-oneapi@v0 with: diff --git a/.github/workflows/c-fortran-test-linux-osx.yml b/.github/workflows/c-fortran-test-linux-osx.yml index 52df23c8d1..666feab68e 100644 --- a/.github/workflows/c-fortran-test-linux-osx.yml +++ b/.github/workflows/c-fortran-test-linux-osx.yml @@ -20,7 +20,7 @@ jobs: steps: - name: Environment setup - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Set compiler run: | case "${{ matrix.compiler }}" in diff --git a/.github/workflows/c-fortran-test-style.yml b/.github/workflows/c-fortran-test-style.yml index ff55101bde..4a8700ba10 100644 --- a/.github/workflows/c-fortran-test-style.yml +++ b/.github/workflows/c-fortran-test-style.yml @@ -17,7 +17,7 @@ jobs: steps: - name: Environment setup - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Install clang-format run: | wget -O- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - diff --git a/.github/workflows/julia-documentation.yml b/.github/workflows/julia-documentation.yml index b90bb1bb1e..5e118ab67a 100644 --- a/.github/workflows/julia-documentation.yml +++ b/.github/workflows/julia-documentation.yml @@ -11,7 +11,7 @@ jobs: build: runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - uses: julia-actions/setup-julia@latest - name: Install dependencies run: | diff --git a/.github/workflows/julia-test-with-style.yml b/.github/workflows/julia-test-with-style.yml index a292c9550b..abc9942c53 100644 --- a/.github/workflows/julia-test-with-style.yml +++ b/.github/workflows/julia-test-with-style.yml @@ -22,7 +22,7 @@ jobs: steps: - name: Environment setup - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Julia setup uses: julia-actions/setup-julia@latest with: diff --git a/.github/workflows/python-test-with-style.yml b/.github/workflows/python-test-with-style.yml index 4c2764b244..5cf592c7cf 100644 --- a/.github/workflows/python-test-with-style.yml +++ b/.github/workflows/python-test-with-style.yml @@ -18,9 +18,9 @@ jobs: steps: - name: Environment setup - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Python setup - uses: actions/setup-python@v5 + uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} - name: Python dependencies diff --git a/.github/workflows/python-wheels.yml b/.github/workflows/python-wheels.yml index dd4518087f..45e93f646a 100644 --- a/.github/workflows/python-wheels.yml +++ b/.github/workflows/python-wheels.yml @@ -23,13 +23,10 @@ jobs: matrix: # windows-2019, macos-11 os: [ubuntu-20.04] - steps: - - uses: actions/checkout@v4 - + - uses: actions/checkout@v5 - name: Build wheels uses: pypa/cibuildwheel@v2.11.3 - - uses: actions/upload-artifact@v4 with: path: ./wheelhouse/*.whl @@ -43,11 +40,9 @@ jobs: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - + - uses: actions/checkout@v5 - name: Build sdist run: pipx run build --sdist - - uses: actions/upload-artifact@v4 with: path: dist/*.tar.gz @@ -66,7 +61,6 @@ jobs: # if `name: artifact` is omitted, the action will create extra parent dir name: artifact path: dist - - uses: pypa/gh-action-pypi-publish@v1 with: user: __token__ diff --git a/.github/workflows/release-notes.yml b/.github/workflows/release-notes.yml index a4fa213618..d653d7fe7d 100644 --- a/.github/workflows/release-notes.yml +++ b/.github/workflows/release-notes.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Environment setup - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Check release notes run: | git fetch origin main diff --git a/.github/workflows/rust-documentation.yml b/.github/workflows/rust-documentation.yml index 4d6410548a..7170e2b2a1 100644 --- a/.github/workflows/rust-documentation.yml +++ b/.github/workflows/rust-documentation.yml @@ -17,7 +17,7 @@ jobs: steps: - name: Environment setup - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Rust setup uses: dtolnay/rust-toolchain@master with: diff --git a/.github/workflows/rust-test-with-style.yml b/.github/workflows/rust-test-with-style.yml index 63ce2d7b3c..ab890ba3d7 100644 --- a/.github/workflows/rust-test-with-style.yml +++ b/.github/workflows/rust-test-with-style.yml @@ -17,7 +17,7 @@ jobs: steps: - name: Environment setup - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Rust setup uses: dtolnay/rust-toolchain@master with: @@ -32,12 +32,16 @@ jobs: env: CC: ${{ matrix.compiler }} FC: gfortran - run: CARGO_CEED_OPT_FLAGS="-g -O0 -fno-inline" cargo llvm-cov test --doctests --lcov --output-path lcov.info + run: | + export CARGO_CEED_OPT_FLAGS="-g -O0 -fno-inline" + cargo llvm-cov test --doctests --lcov --output-path lcov.info - name: Codecov upload - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v5 + if: ${{ runner.os == 'Linux' }} with: files: lcov.info - token: ${{secrets.CODECOV_TOKEN}} + exclude: interface,gallery,backends,tests,examples + token: ${{ secrets.CODECOV_TOKEN }} style: strategy: @@ -49,7 +53,7 @@ jobs: steps: - name: Environment setup - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Rust setup uses: dtolnay/rust-toolchain@master with: diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d3188148a5..6b315b8097 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -89,7 +89,6 @@ noether-cpu: - echo "-------------- BACKENDS_CPU --------" && echo $BACKENDS_CPU - make clean - PEDANTIC=1 make -j$NPROC_CPU - - make -j$NPROC_CPU # -- libCEED only tests - echo "-------------- core tests ----------" - echo '[{"subject":"/","metrics":[{"name":"Transfer Size (KB)","value":"19.5","desiredSize":"smaller"},{"name":"Speed Index","value":0,"desiredSize":"smaller"},{"name":"Total Score","value":92,"desiredSize":"larger"},{"name":"Requests","value":4,"desiredSize":"smaller"}]}]' > performance.json @@ -121,7 +120,7 @@ noether-cpu: after_script: - | if [ -f .SUCCESS ]; then - lcov --directory . --capture --output-file coverage.info --ignore-errors source,mismatch,unused --substitute 's#(t*-f.h)#test/(t*.-f.h)#g'; + lcov --directory . --capture --output-file coverage.info --ignore-errors source,mismatch; bash <(curl -s https://codecov.io/bash) -f coverage.info -t ${CODECOV_ACCESS_TOKEN} -F interface; bash <(curl -s https://codecov.io/bash) -f coverage.info -t ${CODECOV_ACCESS_TOKEN} -F gallery; bash <(curl -s https://codecov.io/bash) -f coverage.info -t ${CODECOV_ACCESS_TOKEN} -F backends; @@ -209,12 +208,10 @@ noether-rust-qfunctions: after_script: - | if [ -f .SUCCESS ]; then - lcov --directory . --capture --output-file coverage.info --ignore-errors source,mismatch,unused --substitute 's#(t*-f.h)#test/(t*.-f.h)#g'; + lcov --directory . --capture --output-file coverage.info --ignore-errors source,mismatch; bash <(curl -s https://codecov.io/bash) -f coverage.info -t ${CODECOV_ACCESS_TOKEN} -F interface; bash <(curl -s https://codecov.io/bash) -f coverage.info -t ${CODECOV_ACCESS_TOKEN} -F gallery; bash <(curl -s https://codecov.io/bash) -f coverage.info -t ${CODECOV_ACCESS_TOKEN} -F backends; - bash <(curl -s https://codecov.io/bash) -f coverage.info -t ${CODECOV_ACCESS_TOKEN} -F tests; - bash <(curl -s https://codecov.io/bash) -f coverage.info -t ${CODECOV_ACCESS_TOKEN} -F examples; fi artifacts: paths: @@ -258,11 +255,14 @@ noether-cuda: - echo "-------------- core tests ----------" # Note: PETSC_DIR is set by default in GitLab runner env, unsetting to isolate core tests - export PETSC_DIR= PETSC_ARCH= - - make -k -j$((NPROC_GPU / NPROC_POOL)) BACKENDS="$BACKENDS_GPU" JUNIT_BATCH="cuda" junit realsearch=% + # Run only operator tests for ASAN + - make -k -j$((NPROC_GPU / NPROC_POOL)) BACKENDS="$BACKENDS_GPU" JUNIT_BATCH="cuda" junit search=t5 # Rebuild without ASAN - unset ASAN AFLAGS ASAN_OPTIONS + # Need to clean and run full test suite so gcda files match - make clean - PEDANTIC=1 make -k -j$NPROC_CPU -l$NPROC_CPU + - make -k -j$((NPROC_GPU / NPROC_POOL)) BACKENDS="$BACKENDS_GPU" JUNIT_BATCH="cuda" junit realsearch=% # Libraries for examples # -- PETSc with CUDA (minimal) - export PETSC_DIR=/projects/petsc PETSC_ARCH=mpich-cuda-O PETSC_OPTIONS='-use_gpu_aware_mpi 0' && git -C $PETSC_DIR -c safe.directory=$PETSC_DIR describe @@ -290,7 +290,7 @@ noether-cuda: after_script: - | if [ -f .SUCCESS ]; then - lcov --directory . --capture --output-file coverage.info --ignore-errors source,mismatch,unused --substitute 's#(t*-f.h)#test/(t*.-f.h)#g'; + lcov --directory . --capture --output-file coverage.info --ignore-errors source,mismatch; bash <(curl -s https://codecov.io/bash) -f coverage.info -t ${CODECOV_ACCESS_TOKEN} -F interface; bash <(curl -s https://codecov.io/bash) -f coverage.info -t ${CODECOV_ACCESS_TOKEN} -F gallery; bash <(curl -s https://codecov.io/bash) -f coverage.info -t ${CODECOV_ACCESS_TOKEN} -F backends; @@ -357,7 +357,7 @@ noether-cuda: # after_script: # - | # if [ -f .SUCCESS ]; then -# lcov --directory . --capture --output-file coverage.info --ignore-errors source,mismatch,unused --substitute 's#(t*-f.h)#test/(t*.-f.h)#g'; +# lcov --directory . --capture --output-file coverage.info --ignore-errors source,mismatch; # bash <(curl -s https://codecov.io/bash) -f coverage.info -t ${CODECOV_ACCESS_TOKEN} -F interface; # bash <(curl -s https://codecov.io/bash) -f coverage.info -t ${CODECOV_ACCESS_TOKEN} -F gallery; # bash <(curl -s https://codecov.io/bash) -f coverage.info -t ${CODECOV_ACCESS_TOKEN} -F backends; @@ -402,7 +402,6 @@ noether-rocm: - make -j$NPROC_CPU # Clang-tidy - echo "-------------- clang-tidy ----------" && clang-tidy --version - - make clean - TIDY_OPTS="-fix-errors" make -j$NPROC_CPU tidy && git diff --color=always --exit-code # Report status - touch .SUCCESS @@ -460,7 +459,7 @@ noether-float: after_script: - | if [ $(cat .job_status) == "SUCCESS" ]; then - lcov --directory . --capture --output-file coverage.info --ignore-errors source,mismatch,unused --substitute 's#(t*-f.h)#test/(t*.-f.h)#g'; + lcov --directory . --capture --output-file coverage.info --ignore-errors source,mismatch; bash <(curl -s https://codecov.io/bash) -f coverage.info -t ${CODECOV_ACCESS_TOKEN} -F interface; bash <(curl -s https://codecov.io/bash) -f coverage.info -t ${CODECOV_ACCESS_TOKEN} -F gallery; bash <(curl -s https://codecov.io/bash) -f coverage.info -t ${CODECOV_ACCESS_TOKEN} -F backends; diff --git a/backends/cuda/ceed-cuda-compile.cpp b/backends/cuda/ceed-cuda-compile.cpp index d1593dd800..cb5ab11195 100644 --- a/backends/cuda/ceed-cuda-compile.cpp +++ b/backends/cuda/ceed-cuda-compile.cpp @@ -187,6 +187,7 @@ static int CeedCompileCore_Cuda(Ceed ceed, const char *source, const bool throw_ CeedCallBackend(CeedFree(&opts)); *is_compile_good = result == NVRTC_SUCCESS; if (!*is_compile_good) { + // LCOV_EXCL_START char *log; size_t log_size; @@ -196,15 +197,14 @@ static int CeedCompileCore_Cuda(Ceed ceed, const char *source, const bool throw_ if (throw_error) { return CeedError(ceed, CEED_ERROR_BACKEND, "%s\n%s", nvrtcGetErrorString(result), log); } else { - // LCOV_EXCL_START CeedDebug256(ceed, CEED_DEBUG_COLOR_ERROR, "---------- COMPILE ERROR DETECTED ----------\n"); CeedDebug(ceed, "Error: %s\nCompile log:\n%s\n", nvrtcGetErrorString(result), log); CeedDebug256(ceed, CEED_DEBUG_COLOR_ERROR, "---------- BACKEND MAY FALLBACK ----------\n"); CeedCallBackend(CeedFree(&log)); CeedCallNvrtc(ceed, nvrtcDestroyProgram(&prog)); return CEED_ERROR_SUCCESS; - // LCOV_EXCL_STOP } + // LCOV_EXCL_STOP } #if CUDA_VERSION >= 11010 @@ -389,16 +389,16 @@ static int CeedCompileCore_Cuda(Ceed ceed, const char *source, const bool throw_ *is_compile_good = result == 0; if (!*is_compile_good) { + // LCOV_EXCL_START if (throw_error) { return CeedError(ceed, CEED_ERROR_BACKEND, "Failed to load module data"); } else { - // LCOV_EXCL_START CeedDebug256(ceed, CEED_DEBUG_COLOR_ERROR, "---------- COMPILE ERROR DETECTED ----------\n"); CeedDebug(ceed, "Error: Failed to load module data"); CeedDebug256(ceed, CEED_DEBUG_COLOR_ERROR, "---------- BACKEND MAY FALLBACK ----------\n"); return CEED_ERROR_SUCCESS; - // LCOV_EXCL_STOP } + // LCOV_EXCL_STOP } } return CEED_ERROR_SUCCESS; @@ -477,6 +477,7 @@ static int CeedRunKernelDimSharedCore_Cuda(Ceed ceed, CUfunction kernel, CUstrea CUresult result = cuLaunchKernel(kernel, grid_size, 1, 1, block_size_x, block_size_y, block_size_z, shared_mem_size, stream, args, NULL); if (result == CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES) { + // LCOV_EXCL_START int max_threads_per_block, shared_size_bytes, num_regs; cuFuncGetAttribute(&max_threads_per_block, CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK, kernel); @@ -487,13 +488,12 @@ static int CeedRunKernelDimSharedCore_Cuda(Ceed ceed, CUfunction kernel, CUstrea "CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES: max_threads_per_block %d on block size (%d,%d,%d), shared_size %d, num_regs %d", max_threads_per_block, block_size_x, block_size_y, block_size_z, shared_size_bytes, num_regs); } else { - // LCOV_EXCL_START CeedDebug256(ceed, CEED_DEBUG_COLOR_ERROR, "---------- LAUNCH ERROR DETECTED ----------\n"); CeedDebug(ceed, "CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES: max_threads_per_block %d on block size (%d,%d,%d), shared_size %d, num_regs %d\n", max_threads_per_block, block_size_x, block_size_y, block_size_z, shared_size_bytes, num_regs); CeedDebug256(ceed, CEED_DEBUG_COLOR_WARNING, "---------- BACKEND MAY FALLBACK ----------\n"); - // LCOV_EXCL_STOP } + // LCOV_EXCL_STOP *is_good_run = false; } else CeedChk_Cu(ceed, result); return CEED_ERROR_SUCCESS; diff --git a/backends/hip/ceed-hip-compile.cpp b/backends/hip/ceed-hip-compile.cpp index e30bc07a02..ed4efaca34 100644 --- a/backends/hip/ceed-hip-compile.cpp +++ b/backends/hip/ceed-hip-compile.cpp @@ -145,6 +145,7 @@ static int CeedCompileCore_Hip(Ceed ceed, const char *source, const bool throw_e CeedCallBackend(CeedFree(&opts)); *is_compile_good = result == HIPRTC_SUCCESS; if (!*is_compile_good) { + // LCOV_EXCL_START size_t log_size; char *log; @@ -154,15 +155,14 @@ static int CeedCompileCore_Hip(Ceed ceed, const char *source, const bool throw_e if (throw_error) { return CeedError(ceed, CEED_ERROR_BACKEND, "%s\n%s", hiprtcGetErrorString(result), log); } else { - // LCOV_EXCL_START CeedDebug256(ceed, CEED_DEBUG_COLOR_ERROR, "---------- COMPILE ERROR DETECTED ----------\n"); CeedDebug(ceed, "Error: %s\nCompile log:\n%s\n", hiprtcGetErrorString(result), log); CeedDebug256(ceed, CEED_DEBUG_COLOR_WARNING, "---------- BACKEND MAY FALLBACK ----------\n"); CeedCallBackend(CeedFree(&log)); CeedCallHiprtc(ceed, hiprtcDestroyProgram(&prog)); return CEED_ERROR_SUCCESS; - // LCOV_EXCL_STOP } + // LCOV_EXCL_STOP } CeedCallHiprtc(ceed, hiprtcGetCodeSize(prog, &ptx_size)); @@ -234,17 +234,17 @@ static int CeedRunKernelDimSharedCore_Hip(Ceed ceed, hipFunction_t kernel, hipSt if (result == hipSuccess) { *is_good_run = true; } else { + // LCOV_EXCL_START if (throw_error) { CeedCallHip(ceed, result); } else { - // LCOV_EXCL_START const char *message = hipGetErrorName(result); CeedDebug256(ceed, CEED_DEBUG_COLOR_ERROR, "---------- LAUNCH ERROR DETECTED ----------\n"); CeedDebug(ceed, "%s\n", message); CeedDebug256(ceed, CEED_DEBUG_COLOR_WARNING, "---------- BACKEND MAY FALLBACK ----------\n"); - // LCOV_EXCL_STOP } + // LCOV_EXCL_STOP *is_good_run = false; } return CEED_ERROR_SUCCESS; diff --git a/interface/ceed-basis.c b/interface/ceed-basis.c index 23bf05c419..55aa1e0e36 100644 --- a/interface/ceed-basis.c +++ b/interface/ceed-basis.c @@ -595,9 +595,11 @@ static int CeedBasisApplyAtPoints_Core(CeedBasis basis, bool apply_add, CeedInt } break; } + // LCOV_EXCL_START default: // Nothing to do, excluded above break; + // LCOV_EXCL_STOP } CeedCall(CeedVectorRestoreArrayRead(basis->vec_chebyshev, &chebyshev_coeffs)); CeedCall(CeedVectorRestoreArrayRead(x_ref, &x_array_read)); @@ -659,9 +661,11 @@ static int CeedBasisApplyAtPoints_Core(CeedBasis basis, bool apply_add, CeedInt } break; } + // LCOV_EXCL_START default: // Nothing to do, excluded above break; + // LCOV_EXCL_STOP } CeedCall(CeedVectorRestoreArray(basis->vec_chebyshev, &chebyshev_coeffs)); CeedCall(CeedVectorRestoreArrayRead(x_ref, &x_array_read)); diff --git a/interface/ceed-elemrestriction.c b/interface/ceed-elemrestriction.c index 476daab0c2..59b2484af1 100644 --- a/interface/ceed-elemrestriction.c +++ b/interface/ceed-elemrestriction.c @@ -1586,11 +1586,9 @@ int CeedElemRestrictionGetMinMaxPointsInElement(CeedElemRestriction rstr, CeedIn CeedCall(CeedElemRestrictionGetNumElements(rstr, &num_elem)); // Exit early if there are no elements - if (num_elem == 0) { - if (min_points) *min_points = 0; - if (max_points) *max_points = 0; - return CEED_ERROR_SUCCESS; - } + if (min_points) *min_points = 0; + if (max_points) *max_points = 0; + if (num_elem == 0) return CEED_ERROR_SUCCESS; // Initialize to the number of points in the first element CeedCall(CeedElemRestrictionGetNumPointsInElement(rstr, 0, &num_points)); diff --git a/interface/ceed-jit-tools.c b/interface/ceed-jit-tools.c index c50e683f9a..3db81c5f7c 100644 --- a/interface/ceed-jit-tools.c +++ b/interface/ceed-jit-tools.c @@ -180,13 +180,13 @@ int CeedLoadSourceToInitializedBuffer(Ceed ceed, const char *source_file_path, C bool is_pragma_once = next_o && (next_new_line - next_o > 0) && !strncmp(next_o, "once", 4); // -- Copy into buffer, omitting last line if #pragma once - long current_size = strlen(*buffer); - long copy_size = first_hash - &temp_buffer[file_offset] + (is_pragma_once ? 0 : (next_new_line - first_hash + 1)); + const long current_size = strlen(*buffer); + const long copy_size = first_hash - &temp_buffer[file_offset] + (is_pragma_once ? 0 : (next_new_line - first_hash + 1)); - CeedCall(CeedRealloc(current_size + copy_size + 2, buffer)); + CeedCall(CeedRealloc(current_size + copy_size + 1, buffer)); memcpy(&(*buffer)[current_size], "\n", 2); memcpy(&(*buffer)[current_size + 1], &temp_buffer[file_offset], copy_size); - memcpy(&(*buffer)[current_size + copy_size], "", 1); + memcpy(&(*buffer)[current_size + copy_size], "\0", 1); // NOLINT file_offset = strchr(first_hash, '\n') - temp_buffer + 1; } @@ -205,13 +205,13 @@ int CeedLoadSourceToInitializedBuffer(Ceed ceed, const char *source_file_path, C } if (is_hash_include) { // -- Copy into buffer all preceding # - long current_size = strlen(*buffer); - long copy_size = first_hash - &temp_buffer[file_offset]; + const long current_size = strlen(*buffer); + const long copy_size = first_hash - &temp_buffer[file_offset]; - CeedCall(CeedRealloc(current_size + copy_size + 2, buffer)); + CeedCall(CeedRealloc(current_size + copy_size + 1, buffer)); memcpy(&(*buffer)[current_size], "\n", 2); memcpy(&(*buffer)[current_size + 1], &temp_buffer[file_offset], copy_size); - memcpy(&(*buffer)[current_size + copy_size], "", 1); + memcpy(&(*buffer)[current_size + copy_size], "\0", 1); // NOLINT // -- Load local "header.h" char *next_quote = strchr(first_hash, '"'); char *next_new_line = strchr(first_hash, '\n'); @@ -262,12 +262,12 @@ int CeedLoadSourceToInitializedBuffer(Ceed ceed, const char *source_file_path, C CeedCall(CeedFree(&include_source_path)); CeedCall(CeedFree(&normalized_include_source_path)); } else if (!is_std_header) { - long header_copy_size = next_new_line - first_hash + 1; + const long header_copy_size = next_new_line - first_hash + 1; CeedCall(CeedRealloc(current_size + copy_size + header_copy_size + 2, buffer)); memcpy(&(*buffer)[current_size + copy_size], "\n", 2); memcpy(&(*buffer)[current_size + copy_size + 1], first_hash, header_copy_size); - memcpy(&(*buffer)[current_size + copy_size + header_copy_size], "", 1); + memcpy(&(*buffer)[current_size + copy_size + header_copy_size], "\0", 1); } file_offset = strchr(first_hash, '\n') - temp_buffer + 1; } @@ -275,13 +275,13 @@ int CeedLoadSourceToInitializedBuffer(Ceed ceed, const char *source_file_path, C first_hash = strchr(&first_hash[1], '#'); } // Copy rest of source file into buffer - long current_size = strlen(*buffer); - long copy_size = strlen(&temp_buffer[file_offset]); + const long current_size = strlen(*buffer); + const long copy_size = strlen(&temp_buffer[file_offset]); CeedCall(CeedRealloc(current_size + copy_size + 2, buffer)); memcpy(&(*buffer)[current_size], "\n", 2); memcpy(&(*buffer)[current_size + 1], &temp_buffer[file_offset], copy_size); - memcpy(&(*buffer)[current_size + copy_size + 1], "", 1); + memcpy(&(*buffer)[current_size + copy_size + 1], "\0", 1); // Cleanup CeedCall(CeedFree(&temp_buffer)); diff --git a/interface/ceed.c b/interface/ceed.c index 6c94ec8db8..4adfdad887 100644 --- a/interface/ceed.c +++ b/interface/ceed.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -912,6 +913,8 @@ int CeedGetWorkVector(Ceed ceed, CeedSize len, CeedVector *vec) { } } // Long enough vector was not found + // Note: assert fixing bad clang-tidy assumption that num_vecs > max_vecs is ever possible + assert(ceed->work_vectors->num_vecs <= ceed->work_vectors->max_vecs); if (i == ceed->work_vectors->num_vecs) { if (ceed->work_vectors->max_vecs == 0) { ceed->work_vectors->max_vecs = 1; @@ -1178,6 +1181,7 @@ int CeedInit(const char *resource, Ceed *ceed) { // Check for help request const char *help_prefix = "help"; size_t match_help = 0; + while (match_help < 4 && resource[match_help] == help_prefix[match_help]) match_help++; if (match_help == 4) { fprintf(stderr, "libCEED version: %d.%d%d%s\n", CEED_VERSION_MAJOR, CEED_VERSION_MINOR, CEED_VERSION_PATCH, @@ -1195,10 +1199,12 @@ int CeedInit(const char *resource, Ceed *ceed) { // Find best match, computed as number of matching characters from requested resource stem size_t stem_length = 0; + while (resource[stem_length + match_help] && resource[stem_length + match_help] != ':') stem_length++; for (size_t i = 0; i < num_backends; i++) { size_t n = 0; const char *prefix = backends[i].prefix; + while (prefix[n] && prefix[n] == resource[n + match_help]) n++; priority = backends[i].priority; if (n > match_len || (n == match_len && match_priority > priority)) { @@ -1211,12 +1217,14 @@ int CeedInit(const char *resource, Ceed *ceed) { if (match_len <= 1 || match_len != stem_length) { // LCOV_EXCL_START size_t lev_dis = UINT_MAX; - size_t lev_index = UINT_MAX, lev_priority = CEED_MAX_BACKEND_PRIORITY; + size_t lev_index = num_backends, lev_priority = CEED_MAX_BACKEND_PRIORITY; + for (size_t i = 0; i < num_backends; i++) { const char *prefix = backends[i].prefix; size_t prefix_length = strlen(backends[i].prefix); size_t min_len = (prefix_length < stem_length) ? prefix_length : stem_length; size_t column[min_len + 1]; + for (size_t j = 0; j <= min_len; j++) column[j] = j; for (size_t j = 1; j <= min_len; j++) { column[0] = j; @@ -1224,11 +1232,13 @@ int CeedInit(const char *resource, Ceed *ceed) { size_t old_diag = column[k]; size_t min_1 = (column[k] < column[k - 1]) ? column[k] + 1 : column[k - 1] + 1; size_t min_2 = last_diag + (resource[k - 1] == prefix[j - 1] ? 0 : 1); - column[k] = (min_1 < min_2) ? min_1 : min_2; - last_diag = old_diag; + + column[k] = (min_1 < min_2) ? min_1 : min_2; + last_diag = old_diag; } } size_t n = column[min_len]; + priority = backends[i].priority; if (n < lev_dis || (n == lev_dis && lev_priority > priority)) { lev_dis = n; @@ -1238,8 +1248,10 @@ int CeedInit(const char *resource, Ceed *ceed) { } const char *prefix_lev = backends[lev_index].prefix; size_t lev_length = 0; + while (prefix_lev[lev_length] && prefix_lev[lev_length] != '\0') lev_length++; size_t m = (lev_length < stem_length) ? lev_length : stem_length; + if (lev_dis + 1 >= m) return CeedError(NULL, CEED_ERROR_MAJOR, "No suitable backend: %s", resource); else return CeedError(NULL, CEED_ERROR_MAJOR, "No suitable backend: %s\nClosest match: %s", resource, backends[lev_index].prefix); // LCOV_EXCL_STOP