---
title: __builtin_prefetch语义检查错误
description: "```"
url: https://www.hikunpeng.com/document/detail/zh/kunpengdevps/compilation/ug-bisheng/kunpengbisheng_06_0048.html
sourcePath: /source/zh/kunpengdevps/compilation/ug-bisheng/kunpengbisheng_06_0048.html
indexId: 7f52c36dcbae7e728563c3113f3f553028c00cf113fb3b738a6fc44b2602d97674
---
# __builtin_prefetch语义检查错误

#### 错误信息

```
error: argument to '__builtin_prefetch' must be a constant integer 
    __builtin_prefetch(address, forWrite); 
    ^
```


#### 问题介绍

在这段代码中，因为__builtin_prefetch的第二个参数需要是常量，所以先用__builtin_constant_p检查forWrite是否是常量。但是，对于Clang而言，会出现语义检查错误。


#### 代码示例

```
static void prefetchAddress(const void *address, bool forWrite) { 
    if (__builtin_constant_p(forWrite)) { 
        __builtin_prefetch(address, forWrite); 
    } 
}
```


#### 解决方案

将函数转换为宏函数：

```
##define prefetchAddress(address,forWrite) do{\ 
  if (__builtin_constant_p(forWrite)) {      \ 
    __builtin_prefetch(address, forWrite);   \ 
  }                                          \ 
}while(0)
```
