Issue 157383
Summary Clang Apple Darwin target, __builtin_cpu_init() not supported, __built_cpu_supports() return wrong values
Labels clang
Assignees
Reporter sparspare
    
Host environment: Darwin 24.6.0, latest Xcode tools installed, tried latest homebrew clang as well.
Built target is default Darwin MACH0 arm64.

First, using __built_cpu_supports("aes") returns 0 on this system, whereas is should return 1.
Second, __builtin_cpu_init() cause a compilation error "builtin is not supported on this target".

Looking at the generated binary, there was code present for "__init_cpu_features_resolver()", which indeed would initialize the cpu_supports to the proper values.  However, that routine does not appear to be invoked.

Manually calling __init_cpu_features_resolver() causes subsequent __built_cpu_supports() calls to provide the correct values.

Simple test program below. 



`
// clang test.c -o test
#include <stdio.h>

void __init_cpu_features_resolver(); // possibly wrong prototype

int main(void)
{
//      __builtin_cpu_init();   // error: builtin is not supported on this target :     __builtin_cpu_init();
 printf("aes=%u\n", __builtin_cpu_supports("aes")); // 0 -- should be 1

        __init_cpu_features_resolver();

 printf("aes=%u\n", __builtin_cpu_supports("aes")); // now 1

 return 0;
// tried with both:
// Homebrew clang version 21.1.0 Target: arm64-apple-darwin24.6.0
// Apple clang version 17.0.0 (clang-1700.0.13.5) Target: arm64-apple-darwin24.6.0
}`
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to