clang

Difference between clang and gcc [closed]

喜你入骨 提交于 2020-01-01 01:48:33
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . I used both of these compilers in different projects. How they are different in terms of code processing and output generations? For example both gcc and clang has -O2 options for optimization. Are they operating the same way (high level) in terms of optimizing code? I did a

Clang : What does AST (abstract syntax tree) look like?

点点圈 提交于 2019-12-31 22:24:14
问题 Hi I am new in Compiler development, and am wondering how AST look like. I have a small section of code, and I use Clang for generating the AST. I don't get much information out of it. From the looks of it, the Syntax tree is exactly the same as the source, except for one struct that is added to almost any sample I test with. Source: class A { public: int *a, *b, *c; int i; void sum() { a = new int[5]; b = new int[5]; c = new int[5]; for (i = 0; i < 5; i++) { a[i] = i; b[i] = i; } for (i = 0;

Clang : What does AST (abstract syntax tree) look like?

时光总嘲笑我的痴心妄想 提交于 2019-12-31 22:21:11
问题 Hi I am new in Compiler development, and am wondering how AST look like. I have a small section of code, and I use Clang for generating the AST. I don't get much information out of it. From the looks of it, the Syntax tree is exactly the same as the source, except for one struct that is added to almost any sample I test with. Source: class A { public: int *a, *b, *c; int i; void sum() { a = new int[5]; b = new int[5]; c = new int[5]; for (i = 0; i < 5; i++) { a[i] = i; b[i] = i; } for (i = 0;

Force a function to be inline in Clang/LLVM

丶灬走出姿态 提交于 2019-12-31 20:17:04
问题 Is there a way to force an inline function in Clang/LLVM? AFAIK, the following is just a hint to the compiler but it can ignore the request. __attribute__((always_inline)) I don’t mind that the compilation will fail if it can’t inline the function. 回答1: There is a good solution if compiling with C99 which is Clang's default. Its simply using inline attribute. inline void foo() {} It is well written in Clang's compatibility page: By default, Clang builds C code according to the C99 standard,

Set value for llvm::ConstantInt

主宰稳场 提交于 2019-12-31 16:50:00
问题 I'm playing around with LLVM. I thought about changing value of a constant in the intermediate code. However, for the class llvm::ConstantInt, I don't see a setvalue function. Any idea how can I modify value of a constant in the IR code? 回答1: ConstantInt is a factory, isn't it? Class has the get method to construct new constant: /* ... return a ConstantInt for the given value. */ 00069 static Constant *get(Type *Ty, uint64_t V, bool isSigned = false); So, I think, you can't modify existing

Set value for llvm::ConstantInt

北慕城南 提交于 2019-12-31 16:49:10
问题 I'm playing around with LLVM. I thought about changing value of a constant in the intermediate code. However, for the class llvm::ConstantInt, I don't see a setvalue function. Any idea how can I modify value of a constant in the IR code? 回答1: ConstantInt is a factory, isn't it? Class has the get method to construct new constant: /* ... return a ConstantInt for the given value. */ 00069 static Constant *get(Type *Ty, uint64_t V, bool isSigned = false); So, I think, you can't modify existing

Clang performance drop for specific C++ random number generation

别说谁变了你拦得住时间么 提交于 2019-12-31 13:14:41
问题 Using C++11's random module, I encountered an odd performance drop when using std::mt19937 (32 and 64bit versions) in combination with a uniform_real_distribution (float or double, doesn't matter). Compared to a g++ compile, it's more than an order of magnitude slower! The culprit isn't just the mt generator, as it's fast with a uniform_int_distribution . And it isn't a general flaw in the uniform_real_distribution since that's fast with other generators like default_random_engine . Just that

Clang performance drop for specific C++ random number generation

戏子无情 提交于 2019-12-31 13:14:15
问题 Using C++11's random module, I encountered an odd performance drop when using std::mt19937 (32 and 64bit versions) in combination with a uniform_real_distribution (float or double, doesn't matter). Compared to a g++ compile, it's more than an order of magnitude slower! The culprit isn't just the mt generator, as it's fast with a uniform_int_distribution . And it isn't a general flaw in the uniform_real_distribution since that's fast with other generators like default_random_engine . Just that

Why is memcmp(a, b, 4) only sometimes optimized to a uint32 comparison?

£可爱£侵袭症+ 提交于 2019-12-31 10:56:58
问题 Given this code: #include <string.h> int equal4(const char* a, const char* b) { return memcmp(a, b, 4) == 0; } int less4(const char* a, const char* b) { return memcmp(a, b, 4) < 0; } GCC 7 on x86_64 introduced an optimization for the first case (Clang has done it for a long time): mov eax, DWORD PTR [rsi] cmp DWORD PTR [rdi], eax sete al movzx eax, al But the second case still calls memcmp() : sub rsp, 8 mov edx, 4 call memcmp add rsp, 8 shr eax, 31 Could a similar optimization be applied to

Why doesn't clang show color output under Scons?

最后都变了- 提交于 2019-12-31 09:22:31
问题 When building with Scons, I can configure it to use clang like so: env["CXX"] = "clang++" However, it doesn't seem to preserve the color information that clang outputs. How can I make scons preserve the color? 回答1: According to the clang documentation, color is enabled only when a color-capable terminal is detected . SCons doesn't automatically pass on all environment variables to the process that runs the compiler, you have pass them explicitly. And TERM is not passed on to clang. Add the