标签: llvm

For 循环中奇怪的 LLVM 无符号到有符号转换

我不确定这是否只发生在Apple 的 LLVM Compiler 4.0 (XCode 4.4.1)上,但我注意到以下行为:

NSUInteger currentIndex = 0;
NSUInteger sideSize = 2;

// Method A
for (NSInteger i = currentIndex-sideSize; i < currentIndex+sideSize; i++)
{
    printf("In the loop\n"); // WON'T be executed
}

// Method B
for (NSInteger i = (NSInteger)(currentIndex-sideSize); i < currentIndex+sideSize; i++)
{
    printf("In the loop\n"); // WON'T be executed
}

// Method C
for (NSInteger i = (NSInteger)(currentIndex-sideSize); i < (NSInteger)(currentIndex+sideSize); i++)
{
    printf("In the loop\n"); // WILL be executed
} …
Run Code Online (Sandbox Code Playgroud)

c++ unsigned signed for-loop llvm

0
推荐指数
1
解决办法
484
查看次数

如何从llvm的getelementptr指令中提取数组索引值

array[5] = 20;
Run Code Online (Sandbox Code Playgroud)

等效 LLVM IR

%arrayidx = getelementptr inbounds i32, i32* %2, i64 5
store i32 20, i32* %arrayidx, align 4
Run Code Online (Sandbox Code Playgroud)

如何从 LLVM IR 中提取 5 ?

llvm

0
推荐指数
1
解决办法
2395
查看次数

如何在 LLVM 中从 phinode 及其相应的基本块获取标签?

假设 IR 代码如下所示:

define void @_Z1mbb(i1 zeroext %r, i1 zeroext %y) nounwind {
entry:
  %r.addr = alloca i8, align 1
  %y.addr = alloca i8, align 1
  %l = alloca i8, align 1
  %frombool = zext i1 %r to i8
  store i8 %frombool, i8* %r.addr, align 1
  %frombool1 = zext i1 %y to i8
  store i8 %frombool1, i8* %y.addr, align 1
  %0 = load i8* %y.addr, align 1
  %tobool = trunc i8 %0 to i1
  br i1 %tobool, label %lor.end, label …
Run Code Online (Sandbox Code Playgroud)

c++ llvm

0
推荐指数
1
解决办法
482
查看次数

哪些类型可以转换为 std::any?

在编写 clang 插件时,我注意到类型的对象llvm::cl::opt<T>不可转换为std::any,即以下代码段无法编译:

#include <any>
#include <string>

#include "llvm/Support/CommandLine.h"

int main()
{
  llvm::cl::opt<std::string> opt("o");
  std::any opt_any = opt; // doesn't work!
}
Run Code Online (Sandbox Code Playgroud)

我想知道为什么在这个特定实例中这是不可能的,以及类型必须满足什么标准才能转换为std::any.

c++ llvm c++17

0
推荐指数
1
解决办法
73
查看次数

LLVM STLExtras 中的错误:GCC11 的“const”之前预期有不合格的 id

我刚刚将编译器升级到 GCC 11.1.0,但在尝试编译使用 LLVM 的程序时遇到了麻烦。

\n

发生的错误如下:

\n
In file included from /usr/include/llvm/IR/DebugInfo.h:19,\n                 from /home/<redacted>/src/sword/format/llvm.hpp:12,\n                 from /home/<redacted>/src/main.cpp:9:\n/usr/include/llvm/ADT/STLExtras.h:1793:18: error: expected unqualified-id before \xe2\x80\x98const\xe2\x80\x99\n 1793 |   result_pair<R>(const result_pair<R> &Other)\n      |                  ^~~~~\n/usr/include/llvm/ADT/STLExtras.h:1793:18: error: expected \xe2\x80\x98)\xe2\x80\x99 before \xe2\x80\x98const\xe2\x80\x99\n 1793 |   result_pair<R>(const result_pair<R> &Other)\n      |                 ~^~~~~\n      |                  )\n/usr/include/llvm/ADT/STLExtras.h:1843:22: error: expected unqualified-id before \xe2\x80\x98const\xe2\x80\x99\n 1843 |   enumerator_iter<R>(const enumerator_iter<R> &Other) : Result(Other.Result) {}\n      |                      ^~~~~\n/usr/include/llvm/ADT/STLExtras.h:1843:22: error: expected \xe2\x80\x98)\xe2\x80\x99 before \xe2\x80\x98const\xe2\x80\x99\n 1843 |   enumerator_iter<R>(const enumerator_iter<R> &Other) : Result(Other.Result) {}\n      |                     ~^~~~~\n      |                      )\n\n
Run Code Online (Sandbox Code Playgroud)\n

我查看了源代码,但不确定 LLVM 的代码是否格式错误,或者是 GCC …

c++ gcc constructor class llvm

0
推荐指数
1
解决办法
913
查看次数

LLVM:#uses 在调用图中表示什么

所以我通过以下代码生成了调用图:

virtual bool runOnModule(Module &M) {
  
  CallGraph CG = CallGraph(M);
  CG.dump();
}
Run Code Online (Sandbox Code Playgroud)

输出是这样的(我简化了它):

Call graph node for function: 'function1'<<0x563f43b334e0>>  #uses=2
  CS<0x563f442ea418> calls function 'function2'
  CS<0x563f442ea888> calls function 'function3'
  CS<0x563f442eabf8> calls function 'function3'
  CS<0x563f442eb1e0> calls function 'function4'
  CS<0x563f442ebcf0> calls function 'function5'
  CS<0x563f442ebdb0> calls function 'function6'
  CS<0x563f442ec080> calls function 'function7'
  CS<0x563f442ec110> calls function 'function6'
  CS<0x563f442ecb10> calls function 'function4'
  CS<0x563f442ecbd0> calls function 'function6'
  CS<0x563f442ecde0> calls function 'function7'
  CS<0x563f442ece70> calls function 'function4'
Run Code Online (Sandbox Code Playgroud)

我不明白这个#uses 代表什么。我猜它代表的是这个节点直接调用的次数?

c++ llvm

0
推荐指数
1
解决办法
55
查看次数

riscv 组装需要帧指针吗?

我正在开发一个项目,需要我从 llvm ir 生成 asm 代码。

当我使用llc直接从.ll文件生成代码时,程序集没有框架指针fp。但是,当我使用 riscv-unknow-elf-gcc 编译.cpp文件时,它确实有一个帧指针。

网上查了一下,发现-fomit-frame-pointer编译时有参数。

我只是认为对于 riscv asm 来说帧指针是不必要的,因为我们实际上知道函数帧的开始和结束。并且使用帧指针来表示堆栈变量与使用堆栈指针没有区别sp

assembly llvm codegen riscv

0
推荐指数
1
解决办法
1097
查看次数

+(id)arrayWithObjects的最大元素数:

我对此声明self.arraySpec = [NSArray arrayWithObjects: @"ALZ", @"Area", @"BST", @"CSO", @"GLL", "GNO", "LGO", @"PAS", @"PLE", @"PTA", @"PZA", @"RIP", @"SDA", @"VIA", @"VLE", @"VLO", nil]; 有疑问:使用混合编译器,应用程序冻结,而纯llvm显示不良访问.有什么我需要知道的吗?

iphone xcode cocoa-touch objective-c llvm

-1
推荐指数
1
解决办法
124
查看次数

为什么gcc和llvm之间的行为有所不同?

我正在努力编译一些开源库,然后我遇到了这个:

GLfloat campos[3] = {0.0 + modelview[2], 0.0 + modelview[6], 0.0 + modelview[10]};
Run Code Online (Sandbox Code Playgroud)

这在CentOS上编译很好,使用gcc,我真的期望它.

但是,在Mac上,使用带有llvm的XCode,它将无法编译,我不得不将其更改为:

GLfloat campos[3] = static_cast<GLfloat>(0.0 + modelview[2]), static_cast<GLfloat>(0.0 + modelview[6]), static_cast<GLfloat>(0.0 + modelview[10]);
Run Code Online (Sandbox Code Playgroud)

然后它奏效了.作为参考,modelview是另一个GLFloat,如下所示:

GLfloat modelview[16];
Run Code Online (Sandbox Code Playgroud)

由于modelview是一个GLFloat,static_cast正在应用于带有GLfloat的float总和的结果,但我确实希望免费得到它.

为什么行为不同?

c++ opengl xcode gcc llvm

-1
推荐指数
1
解决办法
126
查看次数

这是LLVM中的错误吗?

我正在编译这段代码(使用clang 3.4.2):

#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>

typedef struct __entry {
    char *name;
    int value;
} entry;

int main(int argv, char **argc) {
            printf("Size of entry: %lu\n", sizeof(entry));
        entry *entry = malloc(sizeof(entry));
        printf("entry is at %lu\n", (uint64_t) entry);
}
Run Code Online (Sandbox Code Playgroud)

我收到这个bitcode:

define i32 @main(i32 %argv, i8** %argc) #0 {
entry:
  %argv.addr = alloca i32, align 4
  %argc.addr = alloca i8**, align 8
  %entry1 = alloca %struct.__entry*, align 8
  store i32 %argv, i32* %argv.addr, align 4
  store i8** %argc, i8*** %argc.addr, …
Run Code Online (Sandbox Code Playgroud)

c sizeof llvm clang

-1
推荐指数
1
解决办法
93
查看次数

标签 统计

llvm ×10

c++ ×6

gcc ×2

xcode ×2

assembly ×1

c ×1

c++17 ×1

clang ×1

class ×1

cocoa-touch ×1

codegen ×1

constructor ×1

for-loop ×1

iphone ×1

objective-c ×1

opengl ×1

riscv ×1

signed ×1

sizeof ×1

unsigned ×1