/r/LLVM

Photograph via snooOG

A place to discuss or ask questions relating to the LLVM Compiler Infrastructure.

To learn more about LLVM visit http://llvm.org/

/r/LLVM

3,631 Subscribers

1

LLVM 17 prebuilt binaries for Windows

Looking at the [LLVM 17.0.6 releases] I cannot find a Windows build other than LLVM-17.0.6-win64.exe and LLVM-17.0.6-win32.exe. These installers do not install the full LLVM toolchain, only the core tools like clang and lld. Do I need to build LLVM myself?

0 Comments
2024/11/03
23:04 UTC

1

Do I need to build libcxx too to develop clang?

I have built llvm and clang but when I want to use the built clang++ version it cannot find the headers. My system clang implementation is able to find them and it works fine. Using the same headers as my local (v.15) version with -I also doesn't work.

So is it normal to also have to build libc/libcxx for clang development or what else do I need?

2 Comments
2024/10/31
21:03 UTC

2

How can I display icu_xx::UnicodeString types in Visual Studio Code debugger variables menu

0 Comments
2024/10/28
11:37 UTC

2

weird behaviour in Libfuzzer

When I run the fuzze by default (The default memory should be 2048MB) , I get out-of-memory at rss:119MB.

But when I run it with -rss_limit_mb=10000. it works forever and the rss stops at 481MB.

I know there may be memory leaks but It's still a weird behaviour.

0 Comments
2024/10/24
17:01 UTC

3

Changing the calling convention of a function during clang frontend codegen

I want to change the calling convention of a function during clang frontend codegen (when LLVM IR is generated from AST). The files of interest are clang/lib/CodeGen/CodeGenModule.cpp. I see that EmitGlobal() is working with the Decls passed on, where I can change the calling convention in the FunctionType associated with the FunctionDecl, this change reflects in the function declaration and definition but not at the call site where this function is called.

The callsite calling convention is picked form the QualType obtained from CallExpr, and not the FunctionType of the callee. This can be seen in the function CodeGenFunction::EmitCallExpr() in clang/lib/CodeGen/CGExpr.cpp.

I wish to change the calling convention of a function at one place, and this should reflect at all callsites where given function is called.

What should be the best approach to do this?

3 Comments
2024/10/17
06:45 UTC

2

How to optimize coremark on RISC-V target?

Hi all, AFAIK, GCC performs better on coremark based on RISC-V than LLVM.

My question is: are there any options we can use to achieve same even better score on RISC-V coremark? If not, I would like to achieve this goal with optimizing LLVM compiler, can anyone guide how to proceed on it?

2 Comments
2024/10/15
02:10 UTC

1

No wasm as target in llvm windows

I am really sorry if this is the wrong place to as this question but I do not know where to ask.

The compilation targets available in my llvm binary for windows ( 18.1.8) does not have wasm as a target. Neither does any older versions or higher versions (19.1.0) of llvm binaries for windows.

this is the output received when I type clang --version :

clang version 18.1.8

Target: x86_64-pc-windows-msvc

Thread model: posix

Emscripten? - I need to do it in hard way to learn more stuff. I am not willing to use Emscripten to compile my c code to wasm but only use llvm

Is the only solution is to build from source all by myself? for which I need to get that huge visual studio stuff?

I am sorry if this question was already answered . But I dd not find a solution when searched through google.

Thank you for helping me

Have a good day :)

0 Comments
2024/10/14
19:01 UTC

1

How Do We Make LLVM Quantum? - Josh Izaac @ Quantum Village, DEF CON 32

0 Comments
2024/10/03
12:25 UTC

2

Can someone help to solve the debug info in generated LLVM IR?

1 Comment
2024/09/26
06:25 UTC

8

Where does LLVM shine?

I've written my own compiler for my own programming language. Across my own benchmark suite my language is ~2% faster than C compiled with clang -O2. People keep telling me that "LLVM is the #1 backend for optimization".

So can anyone recommend a benchmark task where there is a simple C/C++/Rust solution to a realistic problem that LLVM does an incredible job optimising so it will put my compiler to shame? I'd like to compare...

1 Comment
2024/09/15
13:03 UTC

4

Whats the difference between BasicBlock and MachineBasicBlock?

4 Comments
2024/09/13
12:56 UTC

9

Contributing to LLVM

( let me know if there are pinned posts or an FAQ section and if this question is repeated here alot)

TLDR; New to open source contribution and lost in the inner workings of C++ to IR code gen.

Hey everyone, I’m a hobbyist with an interest in compilers looking to contribute to LLVM.

I have quite a bit of experience with C++ , but relatively low experience with LLVM (I only built my own compiler with it for a pet language).

I’m currently struggling with understanding the inner workings of LLVM and which part is responsible for what. I know there are a lot of sub projects under the umbrella of LLVM , i’m mostly interested in the c++/C code generation to LLVM IR.

Please drop some tips for a beginner to open source contributions.

12 Comments
2024/09/09
20:31 UTC

4

Clang development environment

(Cross-post from https://discourse.llvm.org/t/clang-development-environment/81140)
Hi,
I’m a masters student, and I’m strating on my thesis now. I’ll write about safety within C++, and would like to develop on Clang.
Currently, I’ve not been able to create a good environment in Clion where I can use it’s debugger with clang (it simply skips over). I am placing breakpoints in the AST, CFG builders, non of which is hit (within Clion). I am currently building the ‘clang’ target in the llvm sub project, and when I modify Clang, the change is compiled, but not executed when I use Clang (a simple print when building the CFG). I’m experiencing this both when compiling C++ and C code.
I was wondering if anyone has experience with debugging Clang through Clion, or if I should use GDB instead? And generally if anyone has some good experiences/advice regarding developing on Clang.
I’m sorry if this has been asked before, I’ve not been able to find any posts or anything.

8 Comments
2024/09/09
11:24 UTC

4

I made a small 3body simulation in PURE llvmir

I cheated and used raylib for rendering and also looked at how clang links to it. but other than that this code is all hand written to be this terrible. so no blaming clang for this catastrophe
https://github.com/nevakrien/first_llvm

0 Comments
2024/08/16
20:54 UTC

2

are -fmemory-profile and -fprofile-instr-generate broken?

Or am I using them wrong?

clang++ --std=c++20 -O3 -Wall -Werror hashmap.cpp -o hashmap -fprofile-instr-generate=instr.profile -fmemory-profile=mp -fuse-ld=lld

ld.lld: error: cannot open /usr/local/lib/clang/20/lib/x86_64-unknown-linux-gnu/libclang_rt.memprof.a: No such file or directory
ld.lld: error: cannot open /usr/local/lib/clang/20/lib/x86_64-unknown-linux-gnu/libclang_rt.memprof_cxx.a: No such file or directory
ld.lld: error: cannot open /usr/local/lib/clang/20/lib/x86_64-unknown-linux-gnu/libclang_rt.profile.a: No such file or directory
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Those files indeed do not exist. Do I need another option to make or install them? llvm is compiled and installed locally with this build script I made (targetting /usr/local by default obviously).

cmake -S llvm-project/llvm -B /mnt/ramdisk/llvm-build -G 'Unix Makefiles' -DLLVM_ENABLE_LIBEDIT=true -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra;libclc;lld;lldb;polly;pstl' -DLLVM_ENABLE_RUNTIMES='all' -DLLDB_ENABLE_LIBEDIT=ON || exit 2
cd /mnt/ramdisk/llvm-build || exit 3
nice -n20 make -j48 || exit 4
nice -n20 make -j32 check-clang || exit 5
sudo make -j32 install || exit 6

e: fix formatting

e2: version info:

$ clang++ --version
clang version 20.0.0git (https://github.com/llvm/llvm-project.git 0c274d527ae36db420c4273f83fcb6c859b28f1b)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin

$ ld.lld --version
LLD 20.0.0 (https://github.com/llvm/llvm-project.git 0c274d527ae36db420c4273f83fcb6c859b28f1b) (compatible with GNU linkers)
0 Comments
2024/08/02
15:36 UTC

2

Llvm together with Libc by Mingw

0 Comments
2024/07/29
09:12 UTC

5

What are virtual registers and how are they implemented?

Links to sources are appreciated.

1 Comment
2024/07/27
14:47 UTC

1

Can someone help with implementing garbage collector for statepoint-example strategy?

Hi, I have posted this in the LLVM forums but so far, no one has been able to help me :(

Implementing garbage collector for statepoint-example strategy

0 Comments
2024/07/26
13:42 UTC

3

Standard library not detected with my custom Clang Tool

I have the following code (Want to Develop a CXX refactoring tool)

using namespace clang;

int main(int argc, const char **argv) {

    static llvm::cl::OptionCategory KsaiToolOptions("my_tool optoins");
    static llvm::cl::extrahelp CommonHelp(clang::tooling::CommonOptionsParser::HelpMessage);
    static llvm::cl::extrahelp MoreHelp("\nMore Help Text .. \n");

    std::string Error;
    auto CompilationDatabase = clang::tooling::JSONCompilationDatabase::loadFromFile(
         "compile_commands.json", Error, tooling::JSONCommandLineSyntax::AutoDetect);
    if (not Error.empty() and not CompilationDatabase) {
        llvm::outs() << "CompilationDatabase Error:" << Error << "\n";
    }

    auto Parser = clang::tooling::CommonOptionsParser::create(argc, argv, KsaiToolOptions);
    if (not Parser) {
        llvm::errs() << Parser.takeError();
        return 1;
    }
    auto Tool = clang::tooling::ClangTool(*CompilationDatabase, Parser->getSourcePathList());

    std::vector<std::unique_ptr<Refactor>> Refactors;
    Refactors.emplace_back(std::move(std::make_unique<KsaiRefactor::MoveDeclarationsToCppFile>()));
    for (auto &Refactor : Refactors) {
        if (Tool.run(tooling::newFrontendActionFactory(&Refactor->mFinder).get()) != 0) {
            llvm::outs() << "Failure Tooling\n";
        }
    }
    return 0;
}

But when I try to run it, it cannot find the CXX headers,

C:/Users/sansk/OneDrive/Desktop/ksai_shree/include\include.hxx:2:10: fatal error: 
      'cstdio' file not found
    2 | #include <cstdio>
      |          ^~~~~~~~
Scanner(const int inSource) {
}

It is super frustrating. I've tried to manually include the CXX headers on windows, but it will have an error at __pragma(pack(pop)), saying pop is not defined.

This is how I did that

``` std::string CXXStandardLibraryPath =

"-IC:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.40.33807\\include";

std::string CStandardLibraryPath = "-IC:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\ucrt";

std::string CStandardLibraryPathShared = "-IC:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\shared";

std::string CStandardLibraryPathUm = "-IC:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\um";

std::string CStandardLibraryPathWinRT = "-IC:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\winrt";

std::string DeclareWin32 = "-D_WIN32";

Tool.appendArgumentsAdjuster(tooling::getInsertArgumentAdjuster(CXXStandardLibraryPath.c_str()));

Tool.appendArgumentsAdjuster(tooling::getInsertArgumentAdjuster(CStandardLibraryPath.c_str()));

Tool.appendArgumentsAdjuster(tooling::getInsertArgumentAdjuster(CStandardLibraryPathShared.c_str()));

Tool.appendArgumentsAdjuster(tooling::getInsertArgumentAdjuster(CStandardLibraryPathUm.c_str()));

Tool.appendArgumentsAdjuster(tooling::getInsertArgumentAdjuster(CStandardLibraryPathWinRT.c_str()));

Tool.appendArgumentsAdjuster(tooling::getInsertArgumentAdjuster(DeclareWin32.c_str()));

```

2 Comments
2024/07/25
01:46 UTC

1

lldb arrow keys nor working

When typing text into a prompt, I expect the left and right arrow keys to change the cursor's position within the line. I also prefer up and down narrow keys navigate the history. Less critically, I've grown accustomed to using ctrl-R to search the history backwards. This does appear to be implemented, but is broken. If I search for something I know is in my history, I cannot see or edit the result, but pressing enter does run it. The arrow keys do not work at all, instead just inserting the usual escape sequence \^\[\[A - \^\[\[D. I am building llvm locally from a fairly recent commit in the main branch. I have read that libedit is needed but is disabled by default, but those sources are quite dated. Is there an option to enable normal cursor behavior?

cmake -S llvm-project/llvm -B /mnt/ramdisk/llvm-build -G 'Unix Makefiles' -DCMAKE\_BUILD\_TYPE=Release -DLLVM\_ENABLE\_PROJECTS='clang;clang-tools-extra;libclc;lld;lldb;polly;pstl' -DLLVM\_ENABLE\_RUNTIMES='all'

https://stackoverflow.com/questions/35882581/lldb-arrow-key-issue

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=874722

e: answered on llvm discord. Yes, arrow keys can work if libedit is used. Default build options are auto, which means only use it if it is installed on the build system. Apparently the build system that produces the ubuntu binaries doesn't have it. Compiling from source with libedit installed explicitly enabled via -DLLDB_ENABLE_LIBEDIT=ON fixed it.

0 Comments
2024/07/22
20:36 UTC

1

Confusion with Clang

Hi everyone, I am completely new to LLVM and Clang, i was using TCC all this time as my C compiler, and i wanted to switch to Clang because I've heard a lot of good things about LLVM and Clang, but I've encountered a problem, and I can as soon as I've seen the size of LLVM + Clang I was like: "WHAT THE FUCK HOW CAN A COMPILER WEIGH 15GB", so I've tried to find out if I can somehow decrease this size, but I didn't find anything useful, so I'm asking you if there is a standalone version of Clang without LLVM that just compiles my C files into windows executables?

1 Comment
2024/07/10
03:46 UTC

2

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

0 Comments
2024/07/04
08:04 UTC

6

I Created a Translator From LLVM-IR to Haskell (??)

Okay, wtf? Calm down, this is true for a restricted subset of the LLVM-IR.

Let's start from the beginning: LLVM-IR is based on SSA form, which has been proven to be equivalent to functional programming (Appel, 1998) and ANF (Chakravarty, Keller, Zadarnowski, 2003). But what about LLVM-IR being equivalent to functional programming? This was the question I explored in my final project for my Bachelor's degree in Computer Science.

The translation method I implemented was an adaptation of the method proposed by Chakravarty, Keller and Zadarnowski. It involves calculating a dominance tree over the control flow graph in SSA form and then translating the blocks into Haskell functions, with phi instructions becoming the arguments/parameters of these functions.

As I mentioned, this method can only translate a subset of LLVM-IR. This subset includes simple integer types but excludes arrays, pointers, and composite types. There's no support for system calls, I/O operations, or any other instructions that would require handling side effects in Haskell. Additionally, all registers and blocks must be named for the translation to work. Given these conditions, the project can translate code from LLVM-IR to functional code. More specific it generates executable Haskell code.

This project also generates the control flow graph and the dominance tree for a given LLVM-IR file that is in this subset I mentioned.

Check it out here and leave a star if you find it interesting!

0 Comments
2024/07/04
02:40 UTC

1

Tool to audit function signatures for msvc mangle collisions?

I am creating an application that includes extensive templates. It works fine on linux, but cross-compiling to windows, I get a very unhelpful error:

error: cannot mangle this template argument yet
1 error generated.

I am definitely guilty of using overloaded templates. I am quite sure the issue is MSVC's old broken mangler, producing the same mangled name for two of my different functions with the same name. It compiles fine for windows with itanium, but obviously it can't link to the system libs like that. I want to fix this by refactoring one of them to have a different function name, but I cannot tell which function(s) are causing the problem.

Seems this should be a fairly common problem. While I'm surprised clang isn't giving me a more useful error, I'm more surprised how hard it is to find a tool to scan a compilation unit or set of units for potential collisions. Is this really not a thing? It would seem to be right up llvm's ally: in the intersection of cross-compiling abstraction and code analysis.

https://quuxplusone.github.io/blog/2019/08/08/why-default-order-failed/

e: compiling cli (important part, -Is removed for clarity) clang-cl -DWIN32 --target=x86_64-pc-windows-msvc -fuse-ld=lld /winsdkdir ${WINSDK_PATH}/sdk /vctoolsdir ${WINSDK_PATH}/crt /MD /std:c++20 -Diswindows -g -Werror -c "${SRCFILE}" -o "${DSTFILE}"

U: I also discovered the issue is not a mangled name collision, but rather, a template argument edge case that the clang implementation of the msvc mangler does not support. The only time that string is emitted is in the fallback case of when a mangling function bails out (break in a switch statement where every successful mangle contains a return out of the function). Still trying to get clang to cough up enough information so I can tell which templated symbol it hates.

U2: This post was meant to be about the lack of a name collision detecting tool. Well, it turns out my problem this time was not related to name collisions as I thought. Still, I'd like to know if such a tool exists.

My actual problem is that clang's MicrosoftMangler does not know how to mangle a template instance where a pointer argument has a value of one-past-the-end. So I invented one arbitrarily, because consistency with MSVC is unimportant for template calls, as no program NEEDS to call a template instance belonging to another library across an ABI barrier. Compilation of my project is now successful (not linked yet though)/

U3: while only tangentially related to my quest for a msvc mangler collision analyzer, here's my pull request to fix the mangler issue I was having. https://github.com/llvm/llvm-project/pull/97792

U4: My fix has been merged into llvm main. It should appear in version 19.

2 Comments
2024/07/03
22:03 UTC

1

Build a secondary clang & libcxx package for a system

0 Comments
2024/07/01
20:54 UTC

Back To Top