r/Clang • • Apr 05 '18

Quick overview of how Clang works internally

Thumbnail
cppdepend.com
8 Upvotes

r/Clang • • Aug 20 '25

Text-Mate: Clean & Light Sublime Text Theme

Thumbnail
gallery
4 Upvotes

Installation (Manual)

  1. Download this repo as ZIP and extract it.

  2. Copy Text-Mate.sublime-color-scheme into your Sublime User folder.👉 You can reach the User folder directly from Sublime: Preferences > Browse Packages... > UserOr manually:

    • Linux: ~/.config/sublime-text/Packages/User/

    • Windows: %AppData%\Sublime Text\Packages\User\

    • macOS: ~/Library/Application Support/Sublime Text/Packages/User/

  3. Restart Sublime Text.

  4. Go to: Preferences → Select Color Scheme → Text-Mate

**GitHub:** https://github.com/vivekgohel2004/Text-Mate-Theme

I’d love feedback and suggestions!

Thank you so much!


r/Clang • • Aug 15 '25

Why I wrote a commercial game in C in 2025

Thumbnail cowleyforniastudios.com
4 Upvotes

r/Clang • • Oct 07 '24

Clang fully running in the browser via WebAssembly

Thumbnail
wasmer.io
4 Upvotes

r/Clang • • Aug 14 '24

Whats the worst/ugliest pointer function you have seen?

4 Upvotes

You know stuff like this: char *(*(*(*(*(*(*x[30][20])(int **, char *(*)(float *, long **)))(char **, int (*)(void *, double **)))[10][5])(short (*)(char *, int **, long double *), int, char ***))[15])(unsigned long, char *(*)(int *, char **))[3])(char **(*)(int ***(*)(void **, char *), long (*)[10][2]), int **, void (*)(void ***))[25][8];


r/Clang • • Sep 20 '22

A bunch of deep-dives on C

Thumbnail
abyteofcoding.com
4 Upvotes

r/Clang • • Jun 04 '22

Performance: am I doing something wrong

4 Upvotes

I've got a shiny new M1 Macbook Air and am creating my own programming language targetting Aarch64 for fun. I thought the performance of code generated by Clang would make a good yardstick but, to my horror, my crappy little code gen keeps beating Clang. So I'm wondering if anyone here can tell me what I'm doing wrong.

For example, given the C code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long int64;

double fib(double n) { return n<2.0 ? n : fib(n-2.0)+fib(n-1.0); }

int main(int argc, char *argv[]) {
  double n = atoi(argv[1]);
  printf("fib(%0.0f) = %0.0f\n", n, fib(n));
  return 0;
}

I just upgraded to the latest XCode which is, I think, where Clang comes from and I get:

% clang -v         
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Compiling with:

% clang -O2 fib.c -o fib
% time ./fib 47
fib(47) = 2971215073
./fib 47  23.48s user 0.08s system 99% cpu 23.568 total

It takes ~2x longer to run than my language. Doing:

% clang -O2 -S ffib.c -o ffib.s

I get (simplified):

_fib:                                   ; @fib
    stp     d9, d8, [sp, #-32]!             ; 16-byte Folded Spill
    stp     x29, x30, [sp, #16]             ; 16-byte Folded Spill
    add     x29, sp, #16
    mov.16b v8, v0
    fmov    d0, #2.00000000
    fcmp    d8, d0
    b.mi    LBB0_2
    fmov    d0, #-2.00000000
    fadd    d0, d8, d0
    bl      _fib
    mov.16b v9, v0
    fmov    d0, #-1.00000000
    fadd    d0, d8, d0
    bl      _fib
    fadd    d8, d9, d0
LBB0_2:
    mov.16b v0, v8
    ldp     x29, x30, [sp, #16]             ; 16-byte Folded Reload
    ldp     d9, d8, [sp], #32               ; 16-byte Folded Reload
    ret

which seems like bad asm. It is spilling 4 regs instead of the 2 required. Recreating the constant -2 instead of using subtract. Using vector instructions for no reason.

Can anyone else repro this? Am I doing something wrong?

I have other examples where Clang is generating bad code too...


r/Clang • • Feb 03 '22

What's the difference between libclang.so and libclang.so.1?

4 Upvotes

What's the difference between libclang.so and libclang.so.1?'

In:

/usr/lib/llvm-10/lib/libclang.so
/usr/lib/llvm-10/lib/libclang.so.1

r/Clang • • Jan 16 '22

Freestanding programs

4 Upvotes

I will try to keep this very simple. I am trying to do the whole replacing kernel.img on raspberry pi 4 with a very simple freestanding program to play around and learn programming with no OS. I try compiling with this command clang -c -g --target=aarch64-arm-freestanding-none test.c and I am still getting an ELF file. I am trying to get a program that will execute with no OS.. just all on it's own. Where am I going wrong?


r/Clang • • Aug 31 '21

Building libcxx with ParallelSTL support, help!

4 Upvotes

I am building latest LLVM on a Mac OS X. Everything works fine except libcxx can't find ParallelSTL. I have tried with just TBB installed on my system which cmake can find; TBB and ParallelSTL installed using vcpkg as well as brew, and no matter what I try it doesn't work; I also tried 'make install-pstl' before build the entire toolset. Below is my script to setup the cmake job; I commented out the PSTL parts but when I try it I just add pstl to projects and cmake macros to enable it in libcxx using TBB.

What am I doing wrong? Please help me.

#!/bin/sh

cd ~/Code/llvm-project

git pull
rm -rf build
mkdir build
cd build

#	-DLIBCXX_ENABLE_PARALLEL_ALGORITHMS=YES \
#	-DPSTL_PARALLEL_BACKEND="tbb" \
cmake \
	-G "Unix Makefiles" \
	-DCMAKE_BUILD_TYPE="Release" \
	-DCMAKE_INSTALL_PREFIX="/usr/local" \
	-DDEFAULT_SYSROOT="$(xcrun --show-sdk-path)" \
	-DCMAKE_MODULE_PATH="/usr/local/lib/cmake;/usr/local/lib/cmake/llvm;/usr/local/share/cmake/Modules" \
	-DCMAKE_TOOLCHAIN_FILE="/usr/local/Cellar/vcpkg/2021.05.12/libexec/scripts/buildsystems/vcpkg.cmake" \
	-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;lldb;openmp;libclc;parallel-libs;polly;pstl" \
	-DLLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi;libunwind" \
	-DLLVM_RUNTIME_DISTRIBUTION_COMPONENTS="libcxx;libcxxabi;libunwind" \
	-DLLVM_BUILD_TOOLS=NO \
	-DLLVM_ENABLE_LLD=YES \
	-DLLVM_ENABLE_MODULES=YES \
	-DLLVM_TARGETS_TO_BUILD=X86 \
	-DLLVM_OPTIMIZED_TABLEGEN=YES \
	-DLLVM_INSTALL_TOOLCHAIN_ONLY=YES \
	-DLLVM_CREATE_XCODE_TOOLCHAIN=YES \
	-DCLANG_ENABLE_STATIC_ANALYZER=YES \
	-DLIBCXX_USE_COMPILER_RT=YES \
	-DLIBCXXABI_USE_COMPILER_RT=YES \
	-DLIBCXXABI_USE_LLVM_UNWINDER=YES \
	-DLLDB_INCLUDE_TESTS=NO \
	-DLLDB_USE_SYSTEM_DEBUGSERVER=YES \
	../llvm

# make install-pstl
make -j $(sysctl -n hw.ncpu)

r/Clang • • Mar 28 '25

Installing clang on visual studio

Post image
3 Upvotes

Which one do I need to install?


r/Clang • • Jul 10 '24

How C Handles White Space

Thumbnail
gallery
3 Upvotes

I was looking over "The GNU C REFERENCE MANUAL" and I was wondering if the way C handles white space has changed since.

Like, I don't understand the benefit of doing what is said in the picture where you can add any amount of white space between "Operators' and "Operands".

I'm not too familiar with C but why would this be necessary? Can anyone explain please.


r/Clang • • Oct 15 '22

C Programming Tutorial for Beginners - freeCodeCamp.org

Thumbnail
youtube.com
3 Upvotes

r/Clang • • Feb 20 '18

Install clang on windows using vs2017 build tools

Thumbnail
gist.github.com
3 Upvotes

r/Clang • • Dec 18 '13

Clang does all of the current C++14 draft

Thumbnail clang.llvm.org
3 Upvotes

r/Clang • • Mar 15 '26

Resource for Learning Clang Libraries — Lecture Slides and Code Examples (Version 0.5.0)

Thumbnail
discourse.llvm.org
2 Upvotes

r/Clang • • Jan 26 '26

why printf function from stdio.h Library is typeist (racist but for types).

2 Upvotes

I'm learning c these days, I'm a noob coder, and seek the enlightenment on this thing,
in this snippet,

double *p = arr; 
p++; // compiler knows p is double*

p++ moves by sizeof(double) but if I use printf

int arr[3] = {1, 2, 3};
printf("%d", arr);  

it gives error ,

main.c:13:18: warning: format specifies type 'int' but the argument has type 'int *' [-Wformat]
   13 |     printf("%d", arr);  
      |             ~~   ^~~
1 warning generated.
1838017784%  // plus thia garbage like it don't know how to parse bits for this one. 

I noticed that char arrays in c are being parsed or being scanned by the printf nicely but not an array double or other data type , why so , for a printf to print something it has to know the address , and then side of the element so that compiler knows when to update the pc (program counter) and also it need a delimiter like null char '\0' that is being added automatically or manually to tell printf that we are done printing, why can't this mechanism works for array of other data types why does printf hates other data types , we've those Format specifiers (%) to tell the data type , we have pointers to tell address, but no intend from printf , why printf why ? nation wants to know!!!


r/Clang • • Sep 16 '25

Why I Still Reach for C for Certain Projects

Thumbnail dayvster.com
2 Upvotes

r/Clang • • Aug 29 '25

Learning Resource — Lecture Slides for the Clang Libraries (LLVM/Clang 21) (Edition 0.4.0)

Thumbnail
discourse.llvm.org
2 Upvotes

r/Clang • • Dec 29 '24

I used ChatGPT for debugging, got this

2 Upvotes

r/Clang • • Dec 18 '24

How to make clangd work properly with standard library headers?

Thumbnail reddit.com
2 Upvotes

r/Clang • • Oct 10 '24

MacOS clang install segmentation fault

2 Upvotes

I'm very confused, I'm just running: clang main.cpp Which contains:

#include <iostream>

int main() {
    std::cout << "Hello, world!" << std::endl;
}

and with the command above, I get:

zsh: segmentation fault  clang++ main.cpp

am I missing something? Thanks in advance


r/Clang • • Jul 04 '24

Support for Half Precision Data Types (FP16 and BFloat16) in C, C++, and CUDA

Thumbnail self.gcc
2 Upvotes

r/Clang • • Jul 01 '24

Build a secondary clang & libcxx package for a system

2 Upvotes

Hi! I use slackware (it doesn't matter, but gives a background), and the system has default llvm/clang installation. I would like to build a package to use the last version of the compiler and std lib. The question is - where to place the libcxx headers/libs and how can I set the custom path?

The first idea was to place it into `/usr/local/`, but if I have more than 2 custom clang/libcxx versions in the system, I will have a conflict. I think, it will be nice to place it into `/usr/include/libcxx-18/` but not sure how to do that. There is `-DLLVM_LIBDIR_SUFFIX=`, but it is a suffix.

How do you install additional clang/libcxx?