Questions tagged [clang]

For questions about the clang LLVM compiler front end. For general questions about C, use the C tag.

Usage

This tag should be used for questions specific to clang, an LLVM compiler front end for C-based languages. It should not be used for general questions about C; for those, use the tag.

About

Clang is the LLVM compiler front end for C/C++/Objective-C, which provides fast compiles, useful error and warning messages, an accommodating license and offers an extensible platform for building source level tools.

Why Clang?

The development of a new front-end was started out of a need -- a need for a compiler that allows better diagnostics, better integration with IDEs, a license that is compatible with commercial products, and a nimble compiler that is easy to develop and maintain. All of these were motivations for starting work on a new front-end that could meet these needs.

Current Status

Clang is still under development. Clang is considered to be a production quality C, Objective-C, C++ and Objective-C++ compiler when targeting X86-32, X86-64, and ARM (other targets may have caveats, but are usually easy to fix).

C++ Standards Support

  • C++11 is fully supported in Clang 3.3 and later
  • C++14 is fully supported in Clang 3.4 and later
  • C++17 proposed features are mostly supported in Clang 3.5 and later

Please see the C++ status page for more information.

Related Tags

10121 questions
7
votes
1 answer

Unneccessary pop instructions in functions with early if statement

while playing around with godbolt.org I noticed that gcc (6.2, 7.0 snapshot), clang (3.9) and icc (17) when compiling something close to int a(int* a, int* b) { if (b - a < 2) return *a = ~*a; // register intensive code here e.g. sorting…
Christoph Diegelmann
  • 2,004
  • 15
  • 26
7
votes
1 answer

Clang Build Errors

I am trying to build clang trunk on Ubuntu 16.04 and I am having build errors no matter what I try. First I built llvm/clang/libc++/libc++abi against gcc 5.4, this worked fine. Now I am trying to use the clang I just build to rebuild…
Max Ehrlich
  • 2,479
  • 1
  • 32
  • 44
7
votes
2 answers

How do I find all memory allocations in an llvm ir code file?

I tried to compile this snippet of C++ code: void FuncTest() { int* a = new int; int* b = new int[2]; } Using: clang test.cpp -S -emit-llvm -o - > test.llvm And obtained this: define void @_Z8FuncTestv() { entry: %a = alloca i32*, align…
thehan
  • 301
  • 1
  • 3
  • 9
7
votes
1 answer

clang-3.8 and compiler-rt vs libgcc

I have been using clang-3.5 to happily build bitcode versions of musl libc and use the result to produce nice stand alone executables. Recent attempts with clang-3.8 have not been so happy. It seems that the bitcode clang-3.8 generates uses…
Ian A. Mason
  • 207
  • 3
  • 8
7
votes
1 answer

How to find a Clang warning flag in Xcode that's not present in build logs

I've got a warning I wish to suppress in Xcode, but I cannot seem to find the name of the warning. I've enabled -fdiagnostics-show-category=name and the logs show that it's a semantic issue. Looking at Clang's source, I think I've located a test for…
Jason Renaldo
  • 2,802
  • 3
  • 37
  • 48
7
votes
1 answer

Swift @import of module '' in implementation of ; use #import

I'm trying to create a mixed ObjC-Swift framework. But I'm losing a lot of hairs trying to make a private module for my Swift files. I followed some steps in iOS mixed dynamic framework - bridge objc headers with private module combined with some…
Gerald Eersteling
  • 1,244
  • 14
  • 28
7
votes
2 answers

Pragma message in Clang?

What's Clang's equivalent to #pragma message as used in GCC and MSVC?
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
7
votes
2 answers

Inlining of virtual functions (Clang vs GCC)

Take this stupid example: class Base { public: virtual void ant() { i++; }; virtual void dec() { i--; }; int i; }; void function(Base * base) { base->ant(); base->dec(); } The way I imagined this to be implemented by the…
JCx
  • 2,689
  • 22
  • 32
7
votes
1 answer

What is PIC level in program compilation?

I'm taking a look at LLVM libraries and I figured out that Clang emits the LLVM IR modules adding this metadata: !llvm.module.flags = !{!0} !llvm.ident = !{!1} !0 = !{i32 1, !"PIC Level", i32 2} !1 = !{!"Apple LLVM version 7.3.0…
NoImaginationGuy
  • 1,795
  • 14
  • 24
7
votes
2 answers

Are my lambda parameters really shadowing my locals?

I'm dealing with some C code that takes some data, and forwards it to the function passed in: void foo(int* data, void (*fun)(int*)){ (*fun)(data); }; The following works without warning: void bar(int* data){}; int main(){ int data=0; …
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
7
votes
1 answer

how to create a virtual file in clang for codecompletion

Im trying to create virtual files for codecompletion in clang. Unfortunately, my application segfaults. I have the following setup: auto createVirtualFile = []( clang::CompilerInstance& ci, std::string name, llvm::StringRef input ) { …
Gaetano
  • 1,090
  • 1
  • 9
  • 25
7
votes
1 answer

Calling a constexpr method through a reference - is the result a constant expression?

The following code #include void foo(const std::array &a) { constexpr size_t S = a.size(); } int main() {} compiles fine in GCC, but fails to compile in clang with the following error message main.cpp:5:28: error: constexpr…
AnT stands with Russia
  • 312,472
  • 42
  • 525
  • 765
7
votes
2 answers

Lambdas, local types, and global namespace

This minimal program template void foo (X x) { bar (x); } template void bar (X x) { } int main () { foo ([]{}); } compiles with gcc (4.8.5 and 5.3) and fails to compile with clang (3.7) My analysis is as…
n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
7
votes
1 answer

libclang: add compiler system include path (Python in Windows)

Following this question and Andrew's suggestions, I am trying to have liblang add the compiler system include paths (in Windows) in order for my Python code import clang.cindex def parse_decl(node): reference_node = node.get_definition() if…
user6167676
7
votes
1 answer

Compiler error when using CRTP with static_assert

Consider the following code: template struct Base { static constexpr int x_base = Derived::x_derived; //static_assert(x_base > 1, "Oops"); }; struct Derived : public Base { static constexpr int x_derived = 5…
toth
  • 2,519
  • 1
  • 15
  • 23