小编Gae*_*ano的帖子

如何在llvm-ir中模拟thread_local?

以下代码目前在lli中不起作用:

//main.cpp 
extern thread_local int tls;
int main() {
    tls = 42;
    return 0;
}

//clang++ -S -emit-llvm main.cpp && lli main.ll
Run Code Online (Sandbox Code Playgroud)

LLVM-IR:

; ModuleID = 'main.cpp'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@tls = external thread_local global i32, align 4

; Function Attrs: norecurse uwtable
define i32 @main() #0 {
  %1 = alloca i32, align 4
  store i32 0, i32* %1, align 4
  %2 = call i32* @_ZTW3tls()
  store i32 42, i32* %2, align 4
  ret i32 …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading llvm llvm-ir lli

25
推荐指数
1
解决办法
761
查看次数

c ++替代成员定义

在C++中,您可以通过以下方式定义成员:

struct test {
    using memberType = int(int);
    /*virtual*/ memberType member;
};

int test::member(int x) { return x; }
Run Code Online (Sandbox Code Playgroud)

使用C++ 14有没有办法在类定义中定义成员,例如使用lambda?

c++ syntax class member c++14

15
推荐指数
1
解决办法
581
查看次数

如何在clang中选择特定的gcc-toolchain?

Clang自动选择具有最高版本的gcc版本:

$ clang++ -v main.cpp
clang version 3.8.1-12 
(tags/RELEASE_381/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9.4
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.1
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.2.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.0.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.2.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.0.1
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.0.1
Run Code Online (Sandbox Code Playgroud)

我怎么能强迫clang使用不同的gcc安装,比如说5.4.1?

我试图用--gcc-toolchain ="/ usr/lib/gcc/x86_64-linux-gnu/5.4.1"调用clang,但没有成功.

c++ linux gcc clang

13
推荐指数
2
解决办法
6280
查看次数

lli:LLVM错误:无法选择:X86ISD :: WrapperRIP TargetGlobalTLSAddress:i64

clang++ -S -emit-llvm main.cpp && lli main.ll在Linux上运行以下代码(Debian)

#include <future>

int main () {
  return std::async([]{return 1;}).get();
}
Run Code Online (Sandbox Code Playgroud)

由于以下错误,无法在lli上运行:

LLVM ERROR: Cannot select: 0xd012e0: 
     i64 = X86ISD::WrapperRIP TargetGlobalTLSAddress:i64<i8** @_ZSt15__once_callable> 0 [TF=10]

 0xd020c0: i64 = TargetGlobalTLSAddress<i8** @_ZSt15__once_callable> 0 [TF=10]
In function: _ZSt9call_onceIMNSt13__future_base13_State_baseV2EFvPSt8functionIFSt10unique_ptrINS0_12_Result_baseENS4_8_DeleterEEvEEPbEJPS1_S9_SA_EEvRSt9once_flagOT_DpOT0_
Run Code Online (Sandbox Code Playgroud)

问题:

这是什么意思?

是否有任何编译器标志可以解决此问题?

使用-stdlib=libc++编译并成功运行*; libstdc ++使用哪些特定功能会导致此问题?

编辑:

这个问题背后的动机是理解libc ++和libstdc ++之间的差异,这些差异导致llvm的orcjit中的这个特定错误消息(在Linux上).

在OSX上,gcc已被弃用,默认情况下使用clang libc++.要在OSX上重现此错误,您可能需要安装gcc和use -stdlib=libstdc++.

这是llvm-ir(遗憾的是直接将它嵌入到这里)

c++ g++ clang llvm-ir lli

10
推荐指数
1
解决办法
321
查看次数

如何在clang中为codecompletion创建一个虚拟文件

我试图在clang中为codecompletion创建虚拟文件.不幸的是,我的应用程序是segfaults.我有以下设置:

auto createVirtualFile = [](
  clang::CompilerInstance& ci,
  std::string name,
  llvm::StringRef input
) {
  std::unique_ptr<llvm::MemoryBuffer>
    MB(llvm::MemoryBuffer::getMemBuffer(input, name));
  return std::move(MB);
};
Run Code Online (Sandbox Code Playgroud)

创建文件后,我设置了CodeCompletConsumer:

auto setupCodeComplete = [](
  clang::CompilerInstance& ci,
  std::string File,
  int Line,
  int Column
) {
  auto& F = ci.getFrontendOpts();
  F.CodeCompletionAt.FileName = File;
  F.CodeCompletionAt.Line = Line;
  F.CodeCompletionAt.Column = Column;
  clang::FrontendInputFile FrontFile(File, clang::IK_CXX);
  //F.Inputs.push_back(FrontFile);
  ci.createCodeCompletionConsumer();
  return FrontFile;
};
Run Code Online (Sandbox Code Playgroud)

我通过以下方式调用这两个函数并执行仅语法操作:

auto runCodeCompleteAt = [] (
  clang::CompilerInstance& ci,
  std::string Filename,
  std::string Code,
  int Line,
  int Column
) {
  auto fid = createVirtualFile(ci, Filename, Code);
  auto …
Run Code Online (Sandbox Code Playgroud)

c++ autocomplete llvm clang code-completion

7
推荐指数
1
解决办法
386
查看次数

llvm错误:搬迁尚未实施!在orcjit或lli中运行RxCpp时

我想在llvm的IR解释器中运行RxCpp示例lli.

不幸的是,在lli中运行任何RxCpp示例都失败了:

git clone https://github.com/Reactive-Extensions/RxCpp.git --depth 1
cd RxCpp/Rx/v2/examples/pythogerian
clang++ -S -emit-llvm -fno-use-cxa-exit -I../../src main.cpp 
lli main.ll
Run Code Online (Sandbox Code Playgroud)

错误信息:

Relocation type not implemented yet!
UNREACHABLE executed at llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp:232!
Run Code Online (Sandbox Code Playgroud)

问题:

这个错误究竟意味着什么? - llvm的orc-jit中哪些假设不满足?

有解决方法吗? - 我可以应用任何LLVM-IR转换来实现这项工作(例如通过编译器标志)吗?

RxCpp使用哪些特殊功能会导致llvm的orcjit出现此问题?

测试:

clang version 5.0.0 (https://github.com/llvm-mirror/clang.git 6c9e299494de2a5b0425e46bc937f29a05128252) 
clang version 4.0.0-+rc1-1 (tags/RELEASE_400/rc1)
clang version 3.9.0-1 (tags/RELEASE_390/final)
clang version 3.8.1-12 (tags/RELEASE_381/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Run Code Online (Sandbox Code Playgroud)

c++ llvm clang rxcpp lli

7
推荐指数
1
解决办法
278
查看次数

具有多个参数的 kvm 超级调用

我目前正在尝试使用 kvm 构建一个小型虚拟机管理程序和内核,并且我努力使具有多个 args 的超级调用正常工作。

这是我尝试过的:

// guest.c

#define KVM_HYPERCALL vmcall
// #define KVM_HYPERCALL vmmcall
// #define KVM_HYPERCALL ".byte 0x0f,0x01,0xd9"
// #define KVM_HYPERCALL .byte 0x0f,0x01,0xc1"

static inline long kvm_hypercall4(int nr, unsigned long p1,
                  unsigned long p2, unsigned long p3,
                  unsigned long p4) {
    long ret;
    asm volatile(KVM_HYPERCALL
             : "=a"(ret)
             : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4)
             : "memory");
    return ret;
}
Run Code Online (Sandbox Code Playgroud)

这些超级调用中的任何一个都会导致vcpu->kvm_run->exit_reason等于 6,这让我感到惊讶KVM_EXIT_MMIO而不是KVM_EXIT_HYPERCALL

switch (vcpu->kvm_run->exit_reason) {
  case KVM_EXIT_MMIO:
    printf("syscall: %lld\n", vcpu->kvm_run->hypercall.nr); // prints 0
    printf("arg 1: …
Run Code Online (Sandbox Code Playgroud)

c virtualization kvm virtual-machine

7
推荐指数
1
解决办法
419
查看次数

如何使用clang :: TreeTransform?

我试图找出clang :: TreeTransform的集成点.

目标是在代码生成之前转换AST.

提前致谢.

c++ transformation llvm clang abstract-syntax-tree

5
推荐指数
1
解决办法
505
查看次数

C++ 编译器中有哪些不确定性的例子?

我正在寻找在 GCC 或 Clang 的编译过程中触发非确定性的代码示例。

一个突出的例子是__DATE__宏的使用。

GCC 和 Clang 有大量编译器标志来控制编译器中非确定性操作的结果,例如。-frandom-seed-fno-guess-branch-probability

有没有受这些标志影响的小例子?

更准确地说:

$ c++ main.cpp -o main && shasum main
aabbccddee

$ c++ main.cpp -o main && shasum main
eeddccbbaa
Run Code Online (Sandbox Code Playgroud)

我正在寻找无宏代码示例,其中多次运行编译器会导致不同的输出,但可以通过例如修复-frandom-seed

编辑:

相关:来自gcc文档:

-fno-guess-branch-probability:
Sometimes gcc will opt to use a randomized model to guess branch probabilities, 
when none are available from either profiling feedback (-fprofile-arcs) 
or __builtin_expect. 
This means that different runs of the compiler on the …
Run Code Online (Sandbox Code Playgroud)

c++ gcc deterministic clang

5
推荐指数
1
解决办法
780
查看次数