Semantic Check Error __builtin_prefetch
Error Information
1 2 3 | error: argument to '__builtin_prefetch' must be a constant integer __builtin_prefetch(address, forWrite); ^ |
Problem
In the code, the second parameter of __builtin_prefetch must be a constant. Therefore, the __builtin_constant_p should be called to check whether the second parameter forWrite from the code example is a constant. However, this causes a semantic check error in Clang.
Code Example
1 2 3 4 5 | static void prefetchAddress(const void *address, bool forWrite) { if (__builtin_constant_p(forWrite)) { __builtin_prefetch(address, forWrite); } } |
Solution
Convert the function to a macro function as follows:
1 2 3 4 5 | ##define prefetchAddress(address,forWrite) do{\ if (__builtin_constant_p(forWrite)) { \ __builtin_prefetch(address, forWrite); \ } \ }while(0) |
Parent topic: Other Compatibility Problems