我收到此錯誤LLVM:無法選擇:內在%llvm.spu.si.sf
> clang -std=c99 -c derivative.c -o derivative.a
fatal error: error in backend: Cannot select: intrinsic %llvm.spu.si.sf
,當我嘗試編譯這個簡單的C程序鏗鏘
#include <stdio.h>
#include <math.h>
int N = 100;
double H = 0.001;
double PI = 3.14159265;
void derive(double* input, long elements, double* output) {
for (int i = 1; i < elements - 1; i++) {
output[i - 1] = (input[i + 1] - input[i - 1])/ (2 * H);
}
}
int main() {
double f[N];
double f_prime[N - 2];
for (int i = 0; i < N; i++) {
f[i] = sin(i * 2 * PI/(double)N);
}
derive(f, N, f_prime);
for (int i = 0; i < N - 2; i++) {
printf("%f %f\n", i * 2 * PI/(double)N, f_prime[i]);
}
}
我已經搜查互聯網,但還沒有找到解決方案。
當我編譯爲Bitcode時,它編譯但執行轉儲核心。
> clang -emit-llvm -c derivative.c -o derivative.bc
> lli derivative.bc
lli: BitcodeReader.cpp:283: llvm::Value* llvm::BitcodeReaderValueList::getValueFwdRef(unsigned int, llvm::Type*): Assertion `(Ty == 0 || Ty == V->getType()) && "Type mismatch in value table!"' failed.
0 lli 0x0000000000c6fb02
1 lli 0x0000000000c6ff93
2 libpthread.so.0 0x00007f304d7dbbd0
3 libc.so.6 0x00007f304ca19037 gsignal + 55
4 libc.so.6 0x00007f304ca1c698 abort + 328
5 libc.so.6 0x00007f304ca11e03
6 libc.so.6 0x00007f304ca11eb2
7 lli 0x000000000052eeb0 llvm::BitcodeReaderValueList::getConstantFwdRef(unsigned int, llvm::Type*) + 0
8 lli 0x0000000000538943 llvm::BitcodeReader::ParseFunctionBody(llvm::Function*) + 10275
9 lli 0x000000000053acb1 llvm::BitcodeReader::Materialize(llvm::GlobalValue*, std::string*) + 241
10 lli 0x0000000000535195 llvm::BitcodeReader::MaterializeModule(llvm::Module*, std::string*) + 85
11 lli 0x0000000000c0a82f llvm::Module::MaterializeAllPermanently(std::string*) + 31
12 lli 0x00000000005360fc llvm::ParseBitcodeFile(llvm::MemoryBuffer*, llvm::LLVMContext&, std::string*) + 44
13 lli 0x00000000004f70b7
14 lli 0x00000000004e74f3 main + 339
15 libc.so.6 0x00007f304ca03ea5 __libc_start_main + 245
16 lli 0x00000000004f0f41
Stack dump:
0. Program arguments: lli derivative.bc
Aborted (core dumped)
在bc文件上嘗試llvm-dis
會產生幾乎相同的核心轉儲。
編輯: 我試圖找到最小失敗的例子,看來,問題是通過常量定義數組大小。
失敗:
int main() {
int N = 100;
double f[N];
}
這個工程:
int main() {
double f[100];
}
EDIT2:
更改int N = 100
到const int N = 100
使得程序鏗鏘編譯。 它是有道理的,該變量應該是const
,但另一方面,gcc -std=c99 -Wall derivative.c -lm
不抱怨,如果它不是const
。
哪個架構的哪個鏗鏘版本?無法重複使用XCode 4.6 clang(基於LLVM3.1) – 2013-02-22 11:55:55
來自'clang -v': Ubuntu鏗鏘聲版本3.2-1〜exp5ubuntu2(tags/RELEASE_32/final)(基於LLVM 3.2) 目標:x86_64-pc -linux-gnu 主題模型:posix – 2013-02-22 11:59:28
我的第一個猜測是,我需要明確地鏈接數學庫。例如。對'gcc'我會使用'-lm'。但在搜索'math.h'問題和Clang時,我找不到任何提示。 – 2013-02-22 12:03:53