[libc-commits] [libc] [libc] Fix modular printf attributes (PR #194003)
Volodymyr Turanskyy via libc-commits
libc-commits at lists.llvm.org
Mon Apr 27 06:50:53 PDT 2026
voltur01 wrote:
This is an example of an error I am getting without explicit annotations:
```
FAILED: libunwind/src/CMakeFiles/unwind_static_objects.dir/libunwind.cpp.obj
/home/voltur01/work_lin/my_github_repos/arm-toolchain/build/llvm/bin/clang++ --target=aarch64-none-elf -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBUNWIND_IS_BAREMETAL -D_LIBUNWIND_LINK_DL_LIB -D_LIBUNWIND_LINK_PTHREAD_LIB -D_LIBUNWIND_REMEMBER_HEAP_ALLOC -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/voltur01/work_lin/my_github_repos/arm-toolchain/libunwind/include --target=aarch64-none-elf -march=armv8-a -mno-unaligned-access -fPIC -ffixed-x18 --sysroot /home/voltur01/work_lin/my_github_repos/arm-toolchain/build/multilib-llvmlibc-builds/runtimes/aarch64a_exn_rtti/build/tmp_install -I/home/voltur01/work_lin/my_github_repos/arm-toolchain/build/multilib-llvmlibc-builds/runtimes/aarch64a_exn_rtti/build/tmp_install/include -ffunction-sections -fdata-sections -fno-ident -Wno-error=atomic-alignment -D_LIBCPP_PRINT=1 -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wno-pass-failed -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -Xclang -fno-pch-timestamp -O3 -DNDEBUG -std=c++17 -Werror=return-type -funwind-tables -nostdinc++ -D_LIBUNWIND_IS_NATIVE_ONLY -D_LIBUNWIND_HAS_NO_THREADS -Wall -Wextra -Wnewline-eof -Wshadow -Wwrite-strings -Wno-unused-parameter -Wno-long-long -Werror=return-type -Wextra-semi -Wundef -Wunused-template -Wformat-nonliteral -Wzero-length-array -Wdeprecated-redundant-constexpr-static-def -Wno-nullability-completeness -Wmissing-prototypes -Wno-user-defined-literals -Wno-covered-switch-default -Wno-suggest-override -Wno-error -pedantic -fno-rtti -nostdlibinc -fstrict-aliasing -fno-exceptions -fno-rtti -MD -MT libunwind/src/CMakeFiles/unwind_static_objects.dir/libunwind.cpp.obj -MF libunwind/src/CMakeFiles/unwind_static_objects.dir/libunwind.cpp.obj.d -o libunwind/src/CMakeFiles/unwind_static_objects.dir/libunwind.cpp.obj -c /home/voltur01/work_lin/my_github_repos/arm-toolchain/libunwind/src/libunwind.cpp
In file included from /home/voltur01/work_lin/my_github_repos/arm-toolchain/libunwind/src/libunwind.cpp:14:
In file included from /home/voltur01/work_lin/my_github_repos/arm-toolchain/libunwind/src/config.h:17:
/home/voltur01/work_lin/my_github_repos/arm-toolchain/build/multilib-llvmlibc-builds/runtimes/aarch64a_exn_rtti/build/tmp_install/include/stdio.h:33:53: error: 'modular_format' attribute requires 'format' attribute
33 | _LIBC_MODULAR_FORMAT_PRINTF(__asprintf_modular) int asprintf(char **__restrict, const char *__restrict, ...) __NOEXCEPT;
| ^
/home/voltur01/work_lin/my_github_repos/arm-toolchain/build/multilib-llvmlibc-builds/runtimes/aarch64a_exn_rtti/build/tmp_install/include/stdio.h:103:51: error: 'modular_format' attribute requires 'format' attribute
103 | _LIBC_MODULAR_FORMAT_PRINTF(__printf_modular) int printf(const char *__restrict, ...) __NOEXCEPT;
| ^
/home/voltur01/work_lin/my_github_repos/arm-toolchain/build/multilib-llvmlibc-builds/runtimes/aarch64a_exn_rtti/build/tmp_install/include/stdio.h:123:53: error: 'modular_format' attribute requires 'format' attribute
123 | _LIBC_MODULAR_FORMAT_PRINTF(__snprintf_modular) int snprintf(char *__restrict, size_t, const char *__restrict, ...) __NOEXCEPT;
| ^
/home/voltur01/work_lin/my_github_repos/arm-toolchain/build/multilib-llvmlibc-builds/runtimes/aarch64a_exn_rtti/build/tmp_install/include/stdio.h:125:52: error: 'modular_format' attribute requires 'format' attribute
125 | _LIBC_MODULAR_FORMAT_PRINTF(__sprintf_modular) int sprintf(char *__restrict, const char *__restrict, ...) __NOEXCEPT;
| ^
/home/voltur01/work_lin/my_github_repos/arm-toolchain/build/multilib-llvmlibc-builds/runtimes/aarch64a_exn_rtti/build/tmp_install/include/stdio.h:131:54: error: 'modular_format' attribute requires 'format' attribute
131 | _LIBC_MODULAR_FORMAT_PRINTF(__vasprintf_modular) int vasprintf(char **__restrict, const char *__restrict, va_list) __NOEXCEPT;
| ^
/home/voltur01/work_lin/my_github_repos/arm-toolchain/build/multilib-llvmlibc-builds/runtimes/aarch64a_exn_rtti/build/tmp_install/include/stdio.h:137:52: error: 'modular_format' attribute requires 'format' attribute
137 | _LIBC_MODULAR_FORMAT_PRINTF(__vprintf_modular) int vprintf(const char *__restrict, va_list) __NOEXCEPT;
| ^
/home/voltur01/work_lin/my_github_repos/arm-toolchain/build/multilib-llvmlibc-builds/runtimes/aarch64a_exn_rtti/build/tmp_install/include/stdio.h:141:54: error: 'modular_format' attribute requires 'format' attribute
141 | _LIBC_MODULAR_FORMAT_PRINTF(__vsnprintf_modular) int vsnprintf(char *__restrict, size_t, const char *__restrict, va_list) __NOEXCEPT;
| ^
/home/voltur01/work_lin/my_github_repos/arm-toolchain/build/multilib-llvmlibc-builds/runtimes/aarch64a_exn_rtti/build/tmp_install/include/stdio.h:143:53: error: 'modular_format' attribute requires 'format' attribute
143 | _LIBC_MODULAR_FORMAT_PRINTF(__vsprintf_modular) int vsprintf(char *__restrict, const char *__restrict, va_list) __NOEXCEPT;
| ^
8 errors generated.
```
`asprintf` in this example led me to this pieces of code https://github.com/llvm/llvm-project/blob/cc2b2f548622805a883201bfd7732d863636ecac/clang/lib/Sema/SemaDecl.cpp#L17559 that apparently is there to add the attribute, but after other printf-like functions are handled and _validation_ happens earlier in this function: https://github.com/llvm/llvm-project/blob/cc2b2f548622805a883201bfd7732d863636ecac/clang/lib/Sema/SemaDecl.cpp#L17385
I was able to quickly put together a patch that combines this logic into one helper function to call it before the validation - this change resolved the build issue and I see the decrease in size of my example build.
Does this approach make sense to you? Should I try to polish the change for review?
https://github.com/llvm/llvm-project/pull/194003
More information about the libc-commits
mailing list