llvm-clang

LLVM OPT not giving optimised file as output.

有些话、适合烂在心里 提交于 2020-07-21 03:29:41
问题 The man page for opt says: "It takes LLVM source files as input, runs the specified optimizations or analyses on it, and then outputs the optimized file or the analysis results". My Goal: To use the inbuilt optimisation pass -dce available in opt . This pass does Dead Code Elimination My Source file foo.c : int foo(void) { int a = 24; int b = 25; /* Assignment to dead variable -- dead code */ int c; c = a * 4; return c; } Here is what I did: 1. clang-7.0 -S -emit-llvm foo.c -o foo.ll 2. opt

LLVM OPT not giving optimised file as output.

孤街浪徒 提交于 2020-07-21 03:28:28
问题 The man page for opt says: "It takes LLVM source files as input, runs the specified optimizations or analyses on it, and then outputs the optimized file or the analysis results". My Goal: To use the inbuilt optimisation pass -dce available in opt . This pass does Dead Code Elimination My Source file foo.c : int foo(void) { int a = 24; int b = 25; /* Assignment to dead variable -- dead code */ int c; c = a * 4; return c; } Here is what I did: 1. clang-7.0 -S -emit-llvm foo.c -o foo.ll 2. opt

How to represent clang AST in JSON format?

瘦欲@ 提交于 2020-06-16 06:34:31
问题 clang-check -ast-dump -ast-dump-filter=<function_name> main.c gives a AST (only a function declaration) of the particular code. How can we represent generated AST in JSON format? PS: I Want AST for function declaration only. 回答1: Call clang with the -ast-dump=json argument. This was implemented only recently (May 2019) so you need an up-to-date version of Clang. See https://reviews.llvm.org/D60910 for details. There's also a library to export more lower-level information available via

Non-modular headers of OpenSSL library when using modulemap for Swift framework

Deadly 提交于 2020-05-29 04:23:30
问题 I'm trying to link statically OpenSSL library to my Swift framework, using XCode. Most approaches mentioned online are not correct, because they suggest using Import path ( SWIFT_INCLUDE_PATHS ). As a result, the framework binary is locked to a specific location in the file system and the binary itself is not portable. While this is not end of the world, I'd still like to be able to distribute the binary via Carthage for example and following above-mentioned approach doesn't enable that. I

Clang 10 fails to link C++ application with CMake on macOS 10.12

戏子无情 提交于 2020-04-15 10:51:27
问题 I have a Jenkins build server running macOS 10.12. I am compiling a C++ application using the latest Clang 10 (not AppleClang) with CMake 3.17. The error I get is: The C++ compiler "/Users/XXX/llvm/bin/clang++" is not able to compile a simple test program. It fails with the following output: ld: unknown option: -platform_version clang-10: error: linker failed with exit code 1 This works fine with Clang 9 on the same server and Clang 10 works fine on macOS 10.15 with all other build tools and

Is it possible to compile & link Clang/LLVM using the gold linker?

半腔热情 提交于 2020-01-24 05:42:05
问题 I'm writing a custom pass for LLVM/Clang, and recompiling tends to take a while and use a lot of memory. I've heard that the gold linker (1) takes less time and (2) uses less memory than the standard ld linker. Is there a way to pass flags into the LLVM/Clang build process and change to the gold linker? As per this answer, I've been attempting to use an override file, but I don't seem to be having a lot of success. I'll also note that I'm compiling the latest Clang/LLVM build (4.0) using

Clang AST visitor, avoid traversing include files

本小妞迷上赌 提交于 2020-01-23 01:06:26
问题 Hello I am trying to implement an AST Clang visitor and this is my code. class ExampleVisitor : public RecursiveASTVisitor<ExampleVisitor> { private: ASTContext *astContext; // used for getting additional AST info public: virtual bool VisitVarDecl(VarDecl *var) { numVariables++; string varName = var->getQualifiedNameAsString(); string varType = var->getType().getAsString(); cout << "Found variable declaration: " << varName << " of type " << varType << "\n"; APIs << varType << ", "; return

LLVM IR: How to call a function in another .ll file

我是研究僧i 提交于 2020-01-17 06:09:26
问题 I am writing LLVM IR code, can I call a function in another .ll file? For example: In a.ll file, there is a function foo(); Can I use this function in b.ll, like just call foo? If so, how can I include a.ll Thanks 回答1: You need to add declaration of function foo in the ll file in which you are calling it, then as usual convert link ll files to generate executable llvm-link a.ll b.ll -o a.out example a.ll declare i32 @foo(i32) define i32 @main() { start: %0 = call i32 @foo(i32 0) ret i32 %0 }

Clang: How to get the macro name used for size of a constant size array declaration

邮差的信 提交于 2020-01-14 01:38:32
问题 TL;DR; How to get the macro name used for size of a constant size array declaration, from a callExpr -> arg_0 -> DeclRefExpr. Detailed Problem statement: Recently I started working on a challenge which requires source to source transformation tool for modifying specific function calls with an additional argument. Reasearching about the ways i can acheive introduced me to this amazing toolset Clang. I've been learning how to use different tools provided in libtooling to acheive my goal. But

Quirk with Core Data, protocols, and readwrite vs. readonly property declarations

非 Y 不嫁゛ 提交于 2020-01-13 16:24:53
问题 I'm running into an odd quirk involving Core Data, a declared protocol, and perhaps the LLVM 1.5 compiler. Here's the situation. I have a Core Data model that among others has two classes, IPContainer and IPEvent, with IPContainer being the parent entity of IPEvent. Each entity has a custom class in the project for it, created using mogenerator. mogenerator generates an additional subclass that just contains the modeled property declarations, so the class hierarchy is actually IPEvent >