<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/157383>157383</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang Apple Darwin target, __builtin_cpu_init() not supported, __built_cpu_supports() return wrong values
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          sparspare
      </td>
    </tr>
</table>

<pre>
    
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
}`
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0Vc1y4zYMfhr6grGGoizLPujgJPXk0D1tD715KBG22KVJlQStcZ--Q0rebDpNN5dmktgjAt8PCEAyBH2xiC2rn1j9spKRBufbMEqf_nDVOXVvGT-8ukCA9qa9s1e0xKoDvEg_aQtiU2wLzsQzGEkYCH7vnUIg50wAbQNJY1Clc_Ia1S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