clang

alignas specifier vs __attribute__(aligned), c++11

孤者浪人 提交于 2019-12-22 03:44:56
问题 I'm currently in the process of developing an OS kernel in C++11, and I've come across a question, I cannot seem to find the answer to myself. Currently I'm aligning my paging structures, using compiler specific attributes (eg. gcc's __attribute__(aligned) ), however I'm wanting to use the C++11 alignas specifier instead, on Clang++ this is no issue, as it gladly accepts 4096 alignment as parameter to alignas, however G++ does not! So first of all, what's the main difference between the

Xcode 5.1 enable C++14

怎甘沉沦 提交于 2019-12-22 03:36:12
问题 Xcode 5.1 using Clang 3.4. And Clang 3.4 supports C++14. However, I've been surfing though all of the Xcode options and don't see a way to enable C++14. I'm trying to enable the relaxed constexpr feature of C++14 回答1: To get this to work, you first set "C++ Language Dialect" to "compiler default". Then in "Other C++ flags" add "-std=c++1y". This will allow Clang++ to compile with c++14 from within Xcode. I tested this with Xcode 5.1.1 using the new user defined literal for basic_string: std:

(Optimization?) Bug regarding GCC std::thread

别来无恙 提交于 2019-12-22 01:53:04
问题 While testing some functionality with std::thread , a friend encountered a problem with GCC and we thought it's worth asking if this is a GCC bug or perhaps there's something wrong with this code (the code prints (for example) "7 8 9 10 1 2 3", but we expect every integer in [1,10] to be printed): #include <algorithm> #include <iostream> #include <iterator> #include <thread> int main() { int arr[10]; std::iota(std::begin(arr), std::end(arr), 1); using itr_t = decltype(std::begin(arr)); // the

Why compilers no longer optimize this UB with strict aliasing

我是研究僧i 提交于 2019-12-22 01:42:29
问题 One of the first results for strict aliasing on google is this article http://dbp-consulting.com/tutorials/StrictAliasing.html One interesting thing I noticed is this: http://goo.gl/lPtIa5 uint32_t swaphalves(uint32_t a) { uint32_t acopy = a; uint16_t* ptr = (uint16_t*)&acopy; uint16_t tmp = ptr[0]; ptr[0] = ptr[1]; ptr[1] = tmp; return acopy; } is compiled to swaphalves(unsigned int): mov eax, edi ret by GCC 4.4.7. Any compiler newer than that (4.4 is mentioned in the article so article is

Meaning of phrase “constructors do not have names” in the C++ Standard

放肆的年华 提交于 2019-12-22 01:25:08
问题 While trying to understand the phrase "constructors do not have names" in the C++ Standard, it seems like I found an error in clang. Could someone confirm this? VS2015 and gcc rejects this code, and I think they it are is correct. At least, this is the impression I get from §12.1[class.ctor]/2 in N4140: #include <iostream> class A { public: A() { std::cout << "A()" << '\n'; } }; int main() { A::A(); } §12.1[class.ctor]/2 in N4140: A constructor is used to initialize objects of its class type.

OpenCL LLVM IR generation from Clang

佐手、 提交于 2019-12-22 00:06:20
问题 I am using the following command line for clang: clang -Dcl_clang_storage_class_specifiers -isystem $LIBCLC/generic/include -include clc/clc.h -target nvptx--nvidiacl -x cl some_kernel.cl -emit-llvm -S -o some_kernel.ll the result is: ; ModuleID = 'kernel.cl' target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64" target triple = "nvptx--nvidiacl" ; Function Attrs: noinline nounwind define void

AST of a project by Clang

混江龙づ霸主 提交于 2019-12-21 23:17:15
问题 I use the Clang python binding to extract the AST of c/c++ files. It works perfectly for a simple program I wrote. The problem is when I want to employ it for a big project like openssl. I can run clang for any single file of the project, but clang seems to miss some headers of the project, and just gives me the AST of a few functions of the file, not all of the functions. I set the include folder by -I, but still getting part of the functions. This is my code: import clang.cindex as cl cl

“Invalid symbol redefinition” in inline ASM on LLVM

一曲冷凌霜 提交于 2019-12-21 21:55:52
问题 I've got a project in Xcode (4.5.2) that builds fine using the Debug configuration. However, now that I've switched to building the Release configuration, I'm getting an issue: one of my inline assembly functions is getting the error Invalid symbol redefinition . Googling that error message finds me a few people who have got that compiler error, but no information as to what it means. Here's the function, with the error lines annotated: inline int MulDivAdd(int nNumber, int nNumerator, int

How can I code generate unused declarations with Clang?

你。 提交于 2019-12-21 20:37:00
问题 I'm looking to code generate an llvm::Module from some C++ code. Specifically, I will be mixing code generated by Clang and code from another source. Unfortunately, Clang's CodeGenModule class appears to insist on only generating a declaration into the Module if there is a definition which uses it. How can I convince the CodeGenModule to generate these declarations anyway? 回答1: Apparently, -femit-all-decls does not actually emit all the decls, so I had to modify Clang's source code to

Is there an equivalent of GDB for GCC for debugging when compiling with CLANG?

こ雲淡風輕ζ 提交于 2019-12-21 18:29:35
问题 I have found that you can debug with GDB when compiling with GCC however at our university we are required to use CLANG for compiling and I can't find an equivalent of GDB for GCC for CLANG, is there one? 回答1: LLDB appears to be the equivalent debugger for CLANG. Here are some links I found on learning LLDB and the equivalent commands for LLDB from GDB. http://lldb.llvm.org/lldb-gdb.html http://meowni.ca/posts/unscary-lldb/ How to debug Clang plugin using lldb (or gdb) 回答2: You can use GDB or