clang

What is g++'s -pthread equiv in clang?

青春壹個敷衍的年華 提交于 2019-12-29 07:25:08
问题 I'm switching over from g++ to clang however, in g++, I have the -pthread flag, which clang does not seem to recognize. What is the equiv in clang? EDIT: My clang build is pulling from svn on March 5 2010. 回答1: Clang supports -pthread . May be in the latest builds, so update it and try again. 回答2: clang requires -pthread when compiling but not when linking. This is annoying, but it is observed behavior: $ clang -c x.cpp $ clang -pthread -c x.cpp $ clang -o x x.o $ clang -pthread -o x x.o

c++ thread-local storage clang-503.0.40 (Mac OSX)

落花浮王杯 提交于 2019-12-29 06:39:09
问题 After I declared a variable in this way: #include <thread> namespace thread_space { thread_local int s; } //etc. i tried to compile my code using 'g++ -std=c++0x -pthread [sourcefile]'. I get the following error: example.C:6:8: error: thread-local storage is unsupported for the current target static thread_local int s; ^ 1 error generated. If i try to compile the same code on Linux with GCC 4.8.1 whit the same flags, i get a functioning executable file. I'm using clang-503.0.40 (the one which

A Tour to LLVM IR

百般思念 提交于 2019-12-28 17:12:28
https://zhuanlan.zhihu.com/p/66793637 https://zhuanlan.zhihu.com/p/66909226 内容概要 什么是LLVM IR?如何得到IR? LLVM编译的流程,IR文件之间的链接简介 C++ name mangling的用途,“extern C"作用的极简介绍 IR文件的布局 IR中函数定义的结构,什么是BB,什么是CFG IR是一个强类型语言,如何用工具检查IR的合法性 如何理解 Language reference 常见的terminator instruction介绍 如何利用工具得到函数的CFG 什么是SSA?SSA的好处和问题,以及如何解决这个问题 参考文献 what is tail reursion make clang compile to ll -cc1的含义 clang和clang++的区别 what is a linkage unit? LLVM LanguageRef extern "C"的作用 what is name mangling what is static single assignment? what is reaching definition? 1. 什么是LLVM IR? LLVM IR 是 LLVM Intermediate Representation,它是一种 low

clang: how to list supported target architectures?

非 Y 不嫁゛ 提交于 2019-12-28 07:35:12
问题 Currently I am interested in ARM in general and specifically iphone/android targets. But I just want to know more about clang, since it feels to play important role in the years to come. I tried clang -cc1 --help|grep -i list clang -cc1 --help|grep arch|grep -v search clang -cc1 --help|grep target -triple <value> Specify target triple (e.g. i686-apple-darwin9) I know clang has -triplet parameter, but how can I list all possible values for it? I found that clang is very different to gcc in

How I'm supposed to use the sanitizer in clang?

最后都变了- 提交于 2019-12-28 06:28:29
问题 I'm sorry if this is a uber-easy concept, but I find hard to acquire the right mindset in order to correctly use the sanitizer provided by clang . float foo(float f) { return (f / 0); } I compile this small snippet with clang++ -fsanitize=float-divide-by-zero -std=c++11 -stdlib=libc++ -c source.cpp -o osan and I also compile a "normal" version of my object without using the sanitizer clang++ -std=c++11 -stdlib=libc++ -c source.cpp -o onorm I was expecting some verbose output, or some error

In CMake, how can I test if the compiler is Clang?

自古美人都是妖i 提交于 2019-12-28 04:39:05
问题 We have a set of cross-platform CMake build scripts, and we support building with Visual C++ and GCC. We're trying out Clang, but I can't figure out how to test whether or not the compiler is Clang with our CMake script. What should I test to see if the compiler is Clang or not? We're currently using MSVC and CMAKE_COMPILER_IS_GNU<LANG> to test for Visual C++ and GCC, respectively. 回答1: A reliable check is to use the CMAKE_<LANG>_COMPILER_ID variables. E.g., to check the C++ compiler: if

clang vs gcc - optimization including operator new

落爺英雄遲暮 提交于 2019-12-28 04:25:06
问题 I have this simple example I was testing against and I noticed that gcc optimizations (-O3) seems not be as good as clang ones when operator new is involved. I was wondering what might be the issue and if it possible to force gcc to produce more optimized code somehow? template<typename T> T* create() { return new T(); } int main() { auto result = 0; for (auto i = 0; i < 1000000; ++i) { result += (create<int>() != nullptr); } return result; } #clang3.6++ -O3 -s --std=c++11 test.cpp #size a

What is the meaning of clang's -Wweak-vtables?

半世苍凉 提交于 2019-12-27 17:01:55
问题 I basically do not understand clang's -Wweak-vtables . Here is what I observed so far: Case one: (triggers the warning) class A { public: virtual ~A(){} }; class B : public A { public: virtual ~B(){} }; int main(){} Case two: (Does not trigger warning) class A { public: virtual ~A(){} }; int main(){} Case three: (Does not trigger warning) class A { public: virtual ~A(); }; A::~A(){} class B : public A { public: virtual ~B(){} }; int main(){} Case four: (Triggers warning) class A { public:

How to make clang compile to llvm IR

杀马特。学长 韩版系。学妹 提交于 2019-12-27 12:38:42
问题 I want clang to compile my C/C++ code to LLVM bytecode rather than binary executable. How can I achieve that? And if I get the LLVM bytecode, how can I take it to further compile it to binary executable. Basically I want to add some of my own code to the LLVM bytecode before compiling to binary executable. 回答1: Given some C/C++ file foo.c : > clang -S -emit-llvm foo.c Produces foo.ll which is an LLVM IR file. The -emit-llvm option can also be passed to the compiler front-end directly, and not

How to make clang compile to llvm IR

落爺英雄遲暮 提交于 2019-12-27 12:37:26
问题 I want clang to compile my C/C++ code to LLVM bytecode rather than binary executable. How can I achieve that? And if I get the LLVM bytecode, how can I take it to further compile it to binary executable. Basically I want to add some of my own code to the LLVM bytecode before compiling to binary executable. 回答1: Given some C/C++ file foo.c : > clang -S -emit-llvm foo.c Produces foo.ll which is an LLVM IR file. The -emit-llvm option can also be passed to the compiler front-end directly, and not