Questions tagged [clang]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
12 views

Single-pass run of Clang tools (clang-tidy, iwyu, etc.) along with compilation?

Is there a feasible way to run Clang's various code-checking tools (like clang-tidy and include-what-you-use) together with compilation, so that the source code is only parsed and processed once (...
0
votes
1answer
49 views

clang not found after building llvm

So,This is how I did build LLVM 1. Download LLVM from https://github.com/llvm/llvm-project as zip and extract. D:/llvm-project/ |__clang-tools-extra |__clang ...
-1
votes
0answers
30 views

Using clang as a library in C++ project

I am trying to use clang as a library, but I am not sure how to link the files in the Makefile. Trying out the ASTVisitor code from: https://clang.llvm.org/docs/RAVFrontendAction.html Here is my ...
0
votes
0answers
3 views

Showing multiple ranges in Clang DiagnosticBuilder

In a clang-tidy check I am writing, I want to show multiple ranges. And there is inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, ...
0
votes
0answers
12 views

Compiler doesn't find boost library libboost_serialization with gcc or clang (with clang error) on Mac Sierra

I downloaded boost with the accepted answer here on my Mac running Sierra. It was saved under /opt/local/include/. Just to make sure that the library functions correctly, I tried to run this program ...
0
votes
1answer
75 views

constexpr: gcc is trying harder to eval constexpr than clang

I'm using godbolt to see generated code with gcc and clang. I tried to implement to djb2 hash. gcc always trying is best to eval constexpr function. clang is evaluating constexpr only if the ...
0
votes
0answers
17 views

Clang it can't find OpenMP library in windows 10 with msys2 sell

Hi guys i am new to compilers all this years i use gcc and now i wont to change to clang. I wont to run a parallel code with OpenMp library and compile with clang. I can't compile because it cant find ...
0
votes
0answers
36 views

Running Boost library but getting clang error when using gcc on Mac

I am trying to run this example (from: https://theboostcpplibraries.com/boost.serialization-archive#ex.serialization_01): #include <boost/archive/text_oarchive.hpp> #include <iostream> ...
0
votes
0answers
8 views

Installing cryptlib using python fails

Im trying to install cryptlib3.4.5 on docker container i.e running ubuntu:18.04. The clang version is 6.0.0. I was able to install the cryptlib on ubuntu docker using make and make install. make ...
0
votes
0answers
9 views

Getting incompatible pointer type error when trying to compile android kernel

Getting this error when trying to compile aosp kernel: arch/x86/kernel/cpu/perf_event_intel_pt.c: In function ‘pt_init’: arch/x86/kernel/cpu/perf_event_intel_pt.c:1175:27: error: assignment to ‘...
0
votes
1answer
32 views

unsupported symbol modifier in branch relocation: “call [email protected]” [duplicate]

I'm following a C compiler writing journey to generate assembly code for evaluating a binary expression value. Here's the out assembly codes (saved in file "out.s"): .text LC0: .string "%d\n"...
0
votes
0answers
21 views

Undefined symbols for architecture x86_64 in linking libopencv_core.dylib during opencv 3.4.9 installation under osx

I am trying to compile and install opencv 3.4.9 with CUDA support under osx 10.13.6 and after have dealt with some various errors (changed XCode, CUDA, etc) I fall on this error I have no idea how to ...
0
votes
0answers
121 views

Compile AVD kernel for memory forensics with LiME

Hello this is my first time posting on stackoverflow so please forgive my naivety. I'm currently trying to compile a custom kernel with LKM enabled. The main problem is that all guides and tutorials ...
-1
votes
1answer
28 views

Clang Tool that extracts the lambda body given the lambda type

I'm currently trying to implement a Clang Tool based on RecursiveASTVisitors (based on this tutorial) that applies code transformations based on lambdas given to a function. E.g. generate something ...
3
votes
3answers
168 views

Why two identical pointers do not compare equal with -O1? [duplicate]

#include <stdio.h> int main(void) { int a, b; int *p = &a; #ifdef __clang__ int *q = &b + 1; #elif __GNUC__ int *q = &b - 1; #endif printf("%p %p %d\n", (void *...
3
votes
1answer
77 views

clang sanitizers incorrectly catching integer overflow

Say my size_type is uint64_t, and I have the following loop (where sz is of size_type too) for ( size_type i= 0; i < sz; ++i ) { //something if ( i+1 == sz ) { //<-- here /// ...
0
votes
0answers
24 views

OMP reduction with Eigen array runs in GCC but not in Clang

I am using OpenMP to parallelize a loop summing Eigen arrays. Compiling the code with GCC and Clang works, but Clang gives me a SIGSEGV with the error: double free or corruption (!prev) Segmentation ...
0
votes
0answers
27 views

Clang compiler flag `-Wshadow-field-in-constructor` does not enable the warning

Edit: Nevermind, it is a known bug. In the following code (from this question) the constructor parameter shadows a field of the struct. #include <iostream> struct A { A(int n) { std::cout ...
1
vote
1answer
25 views

Ninja doesn't use CC and CXX?

I'm compiling Tesseract with Ninja. Clang has some linking problem, and gcc works. I exports CC and CXX to gcc and make -j8 runs fine. However, Ninja (using the given script in /build folder) still ...
0
votes
0answers
15 views

Can we build a CFG from clang frontend plugin with CFG::buildCFG(Decl*, Stmt*, ASTContext*, BuildOptions&)?

I am trying to build a CFG from Clang frontend plugin with CFG::buildCFG(Decl*, Stmt*, ASTContext*, BuildOptions&) for FunctionDecl object. But I observed that the created CFG object has empty ...
0
votes
0answers
25 views

clang9(or trunk) vs gcc9: member array size as non-type template parameter [duplicate]

I have the following mock code #include <array> template<int N> struct S { std::array<int, N> m{}; }; template<int N> auto copy (S<N> const& i) { return S&...
0
votes
1answer
30 views

LLDB Breakpoints performance - what should I expect?

I've wrote a script that adds a lot of breakpoints to my iOS project. Each breakpoint has a command that calls some logging code and continues without stopping. During my project execution, those ...
2
votes
0answers
51 views

Find NULL pointer dereferences for function parameters using clang static analyzer

I want to automatically find bugs where a potential NULL pointer is dereferenced. In particular, I want to check that all function in my project correctly handle NULL as value for pointers. Here is a ...
0
votes
0answers
16 views

Can not figure out what option in clang-format breaks a particular c++ code

clang-format breaks a line like this log_error(log_, "from" << "asdf"); into this log_error(log_, "from" << "asdf"); (we have some code written which makes it ...
0
votes
0answers
10 views

Modifying clang AST using a plugin

I would like to modify the clang AST using a plugin. I have following the suggestions of using Clang Rewriter object. I use compiler.createDefaultOutputFile() to obtain the output stream to write the ...
0
votes
1answer
11 views

How can I ignore all warnings from included headers in clang/gcc?

I want to use #pragma clang diagnostic push to ignore warnings from some included header files. So I write this: #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wall" #include "...
0
votes
1answer
52 views

C++ program compiled with Clang crashes when new operator is overloaded and outputs to std::cout

I am using Clang version 10.0.0 on Windows 10. This program #include <iostream> // without this operator the program works just fine void* operator new(std::size_t nrOfBytes) { std::cout &...
1
vote
0answers
33 views

What are the differences between attributes and pragmas in C++? [duplicate]

I am interested in the context of C++ code, using compilers such as Clang or GCC. We saw attributes such as __attribute__((always_inline)) and also pragmas such as #pragma inline. Since both of them ...
1
vote
1answer
43 views

Expression size in AST is incorrect for member access

Suppose that I have the following code: struct S { int abcd = 0; }; int main() { S s; return s.abcd; } The corresponding AST part: -FunctionDecl 0x563ddd3a3e20 <line:5:1, line:8:1> line:5:5 ...
0
votes
0answers
29 views

Wasm-LLVM wierd export/import names

I am working on a project that uses a pointerized version of HTML5 Canvas from C++/Wasm. I have currently an import, void drawImageFromURL(const char *, int, int, int, int, float) and an export, void ...
2
votes
1answer
33 views

How do you use Clang-format on Emacs, Ubuntu?

I'm new to Ubuntu and Linux, so I'm sorry if this question seems to be too stupid. I hoped to have a function that can automatically format my C++ codes, so I installed clang-format by the following ...
-1
votes
1answer
58 views

GCC will compile but clang wont

So in my finals there was an exercise asking what will the program print. This is the code: #include <stdio.h> int main (){ int x=5, y=4; if (x>y); printf("A"); if(x=4) ...
0
votes
0answers
34 views

Cannot compile R packages under Conda

OK, this is driving me crazy. I'm attempting to use Conda as a quasi-package manager for R on my Mac (OS 10.15) as I have done (successfully) on other Unix installations. Repeatedly, the error I ...
5
votes
0answers
55 views

If GCC accepts C11 atomic_int casts and clang rejects them, which is correct?

Suppose I have the following C11 program: #include <stdatomic.h> int main() { int x = 0; // same behaviour if `atomic_int x`, surprisingly atomic_int y = (atomic_int) x; } If ...
0
votes
1answer
28 views

Enabling warnings when a noexcept function attempts to call non-noexcept function in gcc or clang

Is there a flag in either GCC or Clang that will throw compile time errors (or warnings) when a function marked as noexcept attempts to call a function not marked as noexcept ? If no, then how are ...
0
votes
0answers
30 views

What does “ld: mach-o string pool extends beyond end of file” mean?

I am currently trying to make and install a specialist suite of software (https://github.com/scottransom/presto), and am encountering this error: gfortran -g -fPIC -o /path-to/presto/bin/psrorbit ...
0
votes
0answers
28 views

clang interpreter failed to materialize symbols

I am new to LLVM suite of tools and what I am trying to do is to get a very simple “hello-world” C++ program to compile to LLVM IR and then to run it using lli tool. So here is the program code (...
3
votes
0answers
40 views

Why do gcc and clang place custom-sectioned const-funcptr symbols into writable sections when compiling with -fpic?

The program below demonstrates the issue: void f(void){} __attribute((section("mysect"),used)) void (* const fp)(void)=&f; //const fn ptr placed in a WR segment iff compiled with -fpic AND a ...
0
votes
2answers
53 views

Fixing circular dependencies c++17 headers

I am using a clang C++17 compiler and I am getting the warning: declaration of 'struct Xchart' will not be visible outside of this function. This warning is pointing to a function declaration that ...
1
vote
1answer
46 views

error: constexpr variable 'struct2Var' must be initialized by a constant expression

The following program is failing when compiling with Clang with error: constexpr variable 'struct2Var' must be initialized by a constant expression {var, 2100433} . If I remove __attribute__((weak)) ...
0
votes
0answers
16 views

How to make sure same number of reset header files are always included?

I have five header files pshpack1.h, pshpack2.h, pshpack4.h, pshpack8.h and poppack.h. First four headers set packing to 1, 2, 4 and 8 respectively using #pragma pack push. The poppack header file ...
3
votes
0answers
82 views

Loop unrolling and SSE — clang vs gcc

Disclaimer: full code can be found here. 16 byte alignment Given a fairly simple type to support proper SSE alignment struct alignas(16) simd_pack { std::int32_t data[4]; }; and a function ...
3
votes
1answer
65 views

What is the difference between “minimum alignment” and “preferred alignment”?

Recently I observed that on Clang 9.0 alignof and __alignof are returning different values for unsigned long long and the same has been discussed at https://reviews.llvm.org/D54814: Starting in ...
1
vote
0answers
23 views

How to get information about call to destructors in Clang LibTooling?

In C++, the compiler should implicitly insert calls to destructors at places such as delete keyword/end of scope, etc. In C++ the call to destructors should be fixed at compilation time (though the ...
1
vote
1answer
24 views

How to let RecursiveASTVisitor abort current subtree

While using Clang LibTooling's RecursiveASTVisitor, how to tell the library to abort the scan of the subtree under the currently visited AST node? RecursiveASTVisitor uses depth-first traversal on ...
-4
votes
0answers
28 views

Use clang to create ast tree for cpp

I want to use clang's api (libclang)to write a c++ program which can create ast trees for cpp files, how can I get ast trees without the include in the cpp, such as a "hello,world" program, when I ...
1
vote
0answers
24 views

Clang-Format: Open brace on newline after multiline statement

I'm looking for a way to conditionally set the opening brace on a newline only after the statement that preceded it spanned multiple lines. For example void foo() { // single line } void bar(int ...
1
vote
0answers
15 views

How to use Clang LibTooling multiple times

Minimul source that use Clang LibTooling which is a very common way: #include "pch.h" #include "clang/Frontend/FrontendActions.h" #include "clang/Tooling/CommonOptionsParser.h" #include "clang/...
0
votes
0answers
15 views

How to integrate CLAG static analyzer with eclipse C/C++ (CDT) IDE?

I planning to do static analysis using clang but I am facing a problem while running a clang from command line and also from while integrating it with eclipse IDE. I here attached error when i am ...
0
votes
0answers
29 views

Mac Catalina Clang not able to find header files in /usr/local/include

Currently I am trying to compile a llvm C++ file including the following header file: #include <clang-c/Index.h> and I have made sure that clang-c/Index.h does exist in /usr/local/include/...