Skip to content

LIBINT2_OPT_AM=0 breaks the build: #cmakedefine drops zero-valued LIBINT_*_AM macros #445

Closed

Description

@evaleev

Symptom

Configuring with -DLIBINT2_OPT_AM=0 (scalar), or with a list whose maximum is 0 (e.g. -DLIBINT2_MAX_AM='2;1' -DLIBINT2_OPT_AM='0;0'), configures fine but the compiler fails to build:

src/bin/libint/build_libint.cc:601:34: error: use of undeclared identifier 'LIBINT_OPT_AM'

(line 601 on master, cparams->max_am_opt("default", LIBINT_OPT_AM);).

Cause

include/libint2/config.h.cmake.in declares the value with

#cmakedefine LIBINT_OPT_AM @LIBINT_OPT_AM@

#cmakedefine emits #define only when the CMake variable is true, and CMake treats 0 as false, so a zero value is written as /* #undef LIBINT_OPT_AM */. build_libint.cc then uses LIBINT_OPT_AM unconditionally (it is only #if defined-guarded for the _LIST variant).

The same #cmakedefine pattern is used for every LIBINT_<class>_MAX_AM and LIBINT_<class>_OPT_AM, so a user-specified 0 for any of them is silently dropped and the compiler falls back to the default (for MAX_AM this matters now that cmake/modules/int_am.cmake accepts 0, see #399). For OPT_AM, 0 is a legitimate request ("do not optimize/unroll anything") that currently cannot be expressed.

Reproduce

cmake -S . -B build -DLIBINT2_MAX_AM=1 -DLIBINT2_OPT_AM=0 -DLIBINT2_ENABLE_ERI=0
cmake --build build

Suggested fix

Emit the macros the way LIBINT_INCLUDE_<class> already is, so that 0 survives and only the unset sentinel is removed:

#define LIBINT_OPT_AM @LIBINT_OPT_AM@
#if @LIBINT_OPT_AM@ == -1
#undef LIBINT_OPT_AM
#endif

(with int_am.cmake setting the variable to -1 when it is not applicable), or guard the use in build_libint.cc with #if defined(LIBINT_OPT_AM). The first option also fixes the silent drop for the per-class _MAX_AM/_OPT_AM macros.

Found while verifying #399 with LIBINT2_ENABLE_GENERIC_CODE=ON (which needs a small opt AM to exercise the generic kernels).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions