---
title: __builtin_prefetch语义检查错误
description: "```"
url: https://www.hikunpeng.com/document/detail/zh/kunpengdevkithistory/bisheng/hist-bisheng/kunpengbisheng_06_0048_1.html
sourcePath: /source/zh/kunpengdevkithistory/bisheng/hist-bisheng/kunpengbisheng_06_0048_1.html
indexId: 76ab67919bf071e95590cbd8f6af797a97d6d31f6187326e9981509f9623517882
---
# __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)
```
