BLAKE3-team / BLAKE3

the official Rust and C implementations of the BLAKE3 cryptographic hash function
Apache License 2.0
4.71k stars 315 forks source link

silence -Wunused-function on MacOS-arm64 #382

Open divinity76 opened 5 months ago

divinity76 commented 5 months ago

the #endif was in the wrong place, on MacOS-arm64 causing the error /Users/runner/work/php-src/php-src/ext/hash/blake3/upstream_blake3/c/blake3_dispatch.c:112:5: error: unused function 'get_cpu_features' [-Werror,-Wunused-function]

full compiler log showcasing the issue https://github.com/php/php-src/actions/runs/7762643678/job/21173438425?pr=13194

oconnor663 commented 4 months ago

It looks like this move makes #if defined(IS_X86) on line 119 redundant. The intention was to eventually use get_cpu_features on other platforms, though we haven't done that yet. Is there any more direct way to mark the function "don't warn if this is unused"? Or is that all ugly compiler specific macros that we don't want to touch?

divinity76 commented 4 months ago

C23 has a solution: https://en.cppreference.com/w/c/language/attributes/maybe_unused but it's 9 years too early to require C23 compatibility.

Maybe make get_cpu_features() always static, and make a public non-static blake3_get_cpu_features() which is just a wrapper for get_cpu_features() ? that would get rid of the unused warning.

if you go that route, maybe some more thought should be put into exactly what the public function should return tho, idk

divinity76 commented 4 months ago

a possible alternative solution: https://github.com/BLAKE3-team/BLAKE3/pull/383

(it may solve the problem for ARM specifically, but probably not for other non-x86-non-arm architectures)