This post summarizes how to set up various plugins needed for C++/C codeediting, linting and formatting.
Just an easy and quick tutorial about how to debug C code using clang. I am using Mac OS X 10.11.1 “El Capitan” and Clang compiler is already installed. If you have OS X and Clang is not installed, you can get it using homebrew: brew install llvm -with-clang -with-asan Create C file. First we will create a small C program called test01.c. To begin, run the command: $ brew install llvm; After installing Clang using brew, the new binaries won’t be in the path automatically. Keep in mind the formula says: OS X already provides this software and installing another version in parallel can cause all kinds of trouble. The binaries are here: $(brew.
This post assumes that deoplete hasbeen installed and set up properly on your system. If that is not the case, youmay refer to this poston how to do it.
To enable C++/C code auto-completion, we need to install clang first.
Linux
On Linux, we can build the latest clang from source using the followingcommand:
The flag -DCMAKE_BUILD_TYPE=Release
will build a release version of clang,which is much smaller than the default one (Debug
type).
The build process will take about half of an hour on our 12-core server, andthe time may vary depending on your hardware.
After that, we need to add the clang binary path to the PATH
variable, andadd the directory containing libclang.so
to env variable LD_LIBRARY_PATH
.Edit ~/.bash_profile
and add following settings:
Under directory $HOME/tools/llvm-project/build/bin
, there are a lot ofexecutables, including clang
, clang++
, and clang-format
(which we willuse to format C++/C code later).
Do not forget to source the file to refresh the env variables.
macOS
For macOS, clang is shipped with it so we do not need to install clang. We needto install clang-format
though since clang-format
is not shipped with clangby default (source here).
The easiest way to install clang-format is via Homebrew:
On Mac, the name of the clang share library is libclang.dylib
, and we shouldadd its parent directory to env variable LD_LIBRARY_PATH
1:
To provide C++/C code autocompletion, we can usedeoplete-clang:
If you have set up the libclang path properly, then auto-completion should workwhen you start editing C++/C source files.
For code linting, we can use ale. Addthe following setting to Neovim config:
We can use the command line tool clang-format
shipped with clang for codeformatting, with the help of pluignNeoformat to format our code. Make surethat clang-format
is on your PATH
. Add the following settings to Neovimconfig:
Notice that the linter name for clang-format
is clangformat
, notclang-format
. I have wasted ten minutes trying to find why clang-format
does not with Neoformat until I found herethat we should use clangformat
as the linter name.
- Build and run clang – official guide.
- Build clang.
- ALE: supported tools.
- clang-format doc.
- clang-format style options.
you can find its path via command
mdfind -name libclang.dylib
. ↩︎
Development activity of OpenMP support in clang/llvm compiler has moved to www.llvm.org. Please get OpenMP-enabled clang (OpenMP 3.1 is fully supported in clang/llvm 3.7) and contribute to its further development there. This web-site is maintained for archival purposes only.
The OpenMP (Open Multi-Processing) specification is a standard for a set of compiler directives, library routines, and environment variables that can be used to specify shared memory parallelism in Fortran and C/C++ programs.
This project implements OpenMP support in the Clang C language family front-end for the LLVM compiler. The current scope of the project is to support the OpenMP 4.0 specification.
November 27, 2015 - Further development of OpenMP support in clang/llvm compiler moved to www.llvm.org. This site is maintained for archival purposes only. Thank you to everyone who contributed all these years!
September 9, 2014 - Upgrade to clang/LLVM 3.5, updated link to LLVM OpenMP library.
June 10, 2014 - Initial support of omp teams distribute [simd]
,omp target teams distribute [simd]
,omp teams distribute parallel for [simd]
and omp target teams distribute parallel for [simd]
directives (just parsing and semantic analysis).
June 9, 2014 - Initial support of omp target data
,omp target update
and omp target teams
directives (just parsing and semantic analysis).
May 6, 2014 - Initial support of omp target, teams, distribute, distribute simd, distribute for, distribute parallel for, distribute parallel for simd
and omp declare target
directives (no actual offloading, just parsing and semantic analysis).
April 11, 2014 - Added support of omp cancel
and omp cancellation point
directives.
March 14, 2014 - Added support of depend
clause in omp task
directive, support for omp parallel for simd
directive.
February 6, 2014 - Upgrade to clang/llvm 3.4.
December 6, 2013 - Added support of variable length arrays in OpenMP constructs.
November 25, 2013 - Added support of omp simd
, omp declare reduction
directives.
September 27, 2013 - Added support of proc_bind
clause.
August 23, 2013 - Initial release.
Getting the source code
The source code structure follows Clang/LLVM: http://llvm.org/docs/GettingStarted.html.
To run (rather than just compile) code you need to get and build an Intel® OpenMP* Runtime Library.
Also you can try to use trunk-based version of the compiler (supported by Hal Finkel)

Brew Clang 2
Building
To build clang with OpenMP support just follow the clang/LLVM compiler's standard build procedure (see Getting Started: Building and Running Clang).
Using
To use the newly installed compiler, add the following to your environment. On Mac OS X, replace LD_LIBRARY_PATH with DYLD_LIBRARY_PATH.
When you build a program that uses OpenMP directives, add the following options to enable OpenMP support and link to the runtime library.
Using clang-omp with Xcode
Instructions are provided by Sebastian Stenzel.- Install clang-omp using homebrew:
brew install llvm
. - Add llvm binaries to your path using :
echo 'export PATH='/usr/local/opt/llvm/bin:$PATH' >> ~/.bash_profile
. - Create a new Xcode project.
- Under Build Settings
- Add a new user-defined setting CC with the value
/usr/local/bin/clang-omp
- Add
-fopenmp
to Other C Flags - Add
/usr/local/include
to Header Search Paths - SetEnable Modules (C and Objective-C)to
No
.
- Add a new user-defined setting CC with the value
- Under Build Phases
- Add
/usr/local/lib/libiomp5.dylib
to Link Binary With Libraries
- Add
#include <libiomp/omp.h>
and start using #pragma omp ...
in your source code. A simple example
Confirm that the compiler is working correctly by saving the above code to a file.
Compilation should proceed with no errors or warnings.
Execute the output ./hello
. You should see more than one “Hello” line with different thread numbers. Note that the lines may be mixed together. If you see only one, try setting the environment variable OMP_NUM_THREADS to some number (say 4) and try again.
If you would like to see performance impact, you can try to compile and execute a more complex example Matrices Multiplication.
We welcome contributions of all kinds: patches, code reviews, testing and bug reports.
However, as any other open source project, we have to maintain some level of control to prevent complete chaos and keep a single architectural direction. You can send your patches here for review and commit; also, we are very open with granting commit access rights to recognized members of Clang/LLVM community.
We plan eventually to contribute this OpenMP implementation to the Clang trunk, where it will be governed by existing Clang/LLVM community development policies.
Full support for OpenMP 3.1 and most of OpenMP 4.0 features (except for offloading) are implemented. This implementation relies on the Intel OpenMP API, and should be used along with Intel® OpenMP* Runtime Library that supports that API (available from www.openmprtl.org).
The following openly available OpenMP test suites pass:
- OpenMP Validation Suite by OpenUH Research Compiler - passed 119 tests of 123.
Supported platforms
OS: Linux or Mac OS X
Architecture: x86, x86-64, PowerPC, Arm
Important Note
Please note that this is a preliminary version. While everything is carefully tested and works fine, there are known internal design quality issues. We plan to refactor some parts of the code before submitting them to Clang trunk. And yes, any help with this would be appreciated!
Brew Clang-tools-extra

Among known design issues are:
Brew Clang 2019
- Combined constructs (
#pragma omp parallel for
and#pragma omp parallel sections
). Currently these constructs are represented as a pair of#pragma omp parallel
and#pragma omp for/sections
constructs. This solution leads to ugly representation in AST because of the troubles with the variables capturing. - Calculation of iteration indices for
#pragma omp for
is not quite optimal. AST representation of this construct also is not very good and should be re-designed. - Analysis of atomic constructs and loops should be reworked for better diagnostics and readability.
Brew Clang 2020
Also, please note that this development is based on latest released clang (3.5), not what is currently under development in clang trunk. External projects based on OpenMP implementation hosted here. If you want your project to be listed, please let us know.- Experimental 'check' clause for 'parallel for' pragma by Luis Felipe Mattos and Juan Salamanca from UNICAMP (Brazil).
LLVM, Clang, and Compiler-rt are distributed under LLVM's the University of Illinois/NCSA Open Source License. In addition to the 'UIUC' BSD-Style license license, the runtime library component of LLVM (Compiler_rt) is also licensed under the MIT License. For details, including information about third-party components, see LICENSE.txt in the code repositories.
If you would like to report a bug, or make a feature request, you can submit an issue in Github here.
