Questions tagged [clang]
For questions about the clang LLVM compiler front end. For general questions about C, use the C tag.
9,513
questions
0
votes
1answer
35 views
How does this vectorized code not overwrite memory?
Take this code.
#include <stdlib.h>
int main(int argc , char **argv) {
int *x = malloc(argc*sizeof(int));
for (int i = 0; i < argc; ++i) {
x[i] = argc;
}
int t =...
0
votes
0answers
13 views
Does Clang provide intrinsics for WebAssembly's memory.fill and memory.copy?
I'm working on developing a WebAssembly module in C and have been attempting to utilize the memory.fill and memory.copy instructions defined in the WebAssembly spec.
I know that Clang (v11.1.0) ...
0
votes
0answers
21 views
Code is not compiling with cmake on MacOS?
I am new to CMake and my code isn't compiling when I run make after cmake. I think the problem is that it's somehow using the wrong version of c++. I need it to be C++11 and it doesn't seem to be that....
1
vote
0answers
19 views
Clang indexing doesn't detect C++20 ConceptDecls
I'm having trouble getting Clang's IndexingAction to detect
clang::ConceptDecls.
I have a minimum working example that initializes
an IndexingAction and runs it over some test code that contains two
...
0
votes
1answer
20 views
how do I configure VS code to build in Release mode (clang + macOS)
I am new to VS code. I have configured it using Clang on macOS using the provided [VS code documentation] (https://code.visualstudio.com/docs/cpp/config-clang-mac)
It works, I can build and debug. ...
3
votes
2answers
73 views
Why clang-tidy suggests to add [[nodiscard]] everywhere?
I have a C++ project where clang-tidy is suggesting to add [[nodiscard]] everywhere. Is this a good practice ? The understanding I have is that [[nodiscard]] should be used only when ignoring the ...
0
votes
0answers
11 views
How to convert llvm profraw to cobertura
I need to switch a cmake based project from g++ to clang for some reasons. I've made the switch to llvm-11 on Ubuntu 20.04. I got the project itself compile, unit tests work as well. Though, getting ...
0
votes
1answer
52 views
The largest n-bit integer
I thought that computing the largest n-bit integer would be trivial by using bit-shifts. Specifically, my idea was to set all of the bits to 1, and then shift them to the right:
template <typename ...
0
votes
0answers
10 views
Error:Undefined symbols for architecture x86_64 [duplicate]
The error message is following.
Although I have found some data in Internet.
I still have no idea about this error.
Hope someone help me.
Does this problem come from building systems?
Undefined ...
0
votes
1answer
21 views
how to remove “incompatible function pointer types” warning when using the c-lib function qsort [duplicate]
I'm trying to use the c-lib function qsort() to sort an array of longs. I do it as follows:
int
compar(long *e1, long *e2) // for decreasing order
{
if (*e1 > *e2) return -1;
if (*e1 < *...
0
votes
1answer
12 views
Can the Clang version of OpenCL be specified?
An OpenCL program I originally wrote for an AMD GPU (RX 570) fails the runtime compilation on the Nvidia card (RTX 3060, latest drivers) with the message <kernel>:28:5: error: use of unknown ...
2
votes
1answer
77 views
Invalid operands to binary expression error (missing const) in std::sort: Why does specifying the compare operator solve it?
Considering:
#include <algorithm>
#include <vector>
struct A {
double dummy;
bool operator<(const A& a) { ///Here I am missing a `const`
return dummy < a....
0
votes
0answers
7 views
LLVMIRGen: libjit.bc: error: Unknown attribute kind (61) (Producer: 'LLVM10.0.0' Reader: 'LLVM 8.0.1')
Ubuntu 20.04 LTS
LLVM VERSION: 10.0.0
clang --version = 8.0.1
I get this error when I try to load the JIT library
LLVMIRGen: libjit.bc: error: Unknown attribute kind (61) (Producer: 'LLVM10.0.0' ...
1
vote
1answer
43 views
Why is there this compilation error for OCaml code?
I am currently testing out Facebook's Infer (open source) v0.17.0 and trying to build it from source code using the bash file by the command
$> ./build-infer.sh clang
However, I am getting an error ...
2
votes
0answers
50 views
What according to does Clang emit “expression result unused” warning
#include <iostream>
struct A{
operator int(){
return 0;
}
};
int main(){
A a;
a; //#1
(int)a; //#2
(A)a; //#3
}
In the above example, #1 and #2 can both trigger ...
1
vote
2answers
34 views
How to display the full error messages in VScode?
I've got a problem that's bothering me for a long time. I use VScode on macOS with standart clang compiller. Almost all error messages produced by the "gcc" are cut, and don't help me at all....
0
votes
0answers
15 views
Visual Studio Code: clang: error: no input files
I ran a line of code in C++ on Visual Studio Code, however this message appeared on my screen.
clang: error: no input files
How do I fix this issue?
0
votes
0answers
21 views
Clang: How can I tell whether size of constant size array declaration is a macro expansion
I'm working on a clang-tidy checker to spot some problematic idioms in a large codebase. I need to look at constant-size arrays declared in structs, and determine whether the size was given as an ...
1
vote
0answers
14 views
clang-tooling: How to check if a field is an incomplete type on construction?
I want to write a matcher, which excludes classes containing incomplete types like:
std::unique_ptr<ForwardDeclared>, but it is not identified as one, because it is a template type (I think so). ...
0
votes
0answers
10 views
Where in clang/llvm do a struct's bit fields in a struct get combined?
I've got a struct with two bit fields in it, and clang/llvm is combining them into a single type, and I want to know how to make it translate exactly what I've given it.
I start with the following ...
2
votes
1answer
74 views
modulo size_t yields “The result of expression ' ' is undefined”
On a 64-bit system, when using the modulo operator along with size_t types, i get the following warning from the clang analyzer:
htable.c:38:62: warning: The result of the ' ' expression is undefined [...
2
votes
1answer
23 views
Clang 10 link error with boost-thread on Ubuntu 20.04
After upgrading from Ubuntu 18.04 with clang/lld 7 and boost 1.65 to 20.04 with clang/lld 10 and boost 1.71, I have encountered a linker errors that I don't know how to address. Is clang & boost ...
0
votes
0answers
5 views
Autovectorization of Character Predicates
Here's a simple C function to check whether or not all of the characters
in a string are in the regex character class [A-Za-z_-]:
int checker(char* restrict src, int len) {
int res = 1;
for(...
0
votes
0answers
25 views
How to configure clangd to find missing external header file?
I am a novice user of clang tools and I am learning c/c++.
I have some code that is based on a framework that uses its data structure and build system ( OpenFOAM). I compiled the framework's ...
0
votes
0answers
31 views
How to link Microsoft Windows resource (.res) files using LLVM/clang++ toolchain
Does anyone know how to link Microsoft Windows resource files (.res files) into a Windows application built using the LLVM/clang++ toolchain?
I've created a simple test case, consisting of one .cpp (...
-2
votes
0answers
25 views
clang: error: linker command failed with exit code 1 / update c++
I downloaded VS Code on my mac following the next instructions:
https://code.visualstudio.com/docs/cpp/config-clang-mac
In almost the middle of it, you have to run the next .json:
"version"...
0
votes
0answers
49 views
cpp type generation by the help of gcc/clang
I am looking for some helper method or compiler plugin to generate new types and extend current ones by checking existing code like below;
input;
struct MyType {
int _integer;
char _char;
}
...
0
votes
0answers
13 views
linker error while trying to build clang with PGO — using “collect_and_build_with_pgo.py” within the repo for build
While trying to build clang with PGO, I am seeing following linker error.
Signals.cpp:(.text._ZL13SignalHandleri+0x1cc): undefined reference to __llvm_profile_instrument_target' Signals.cpp:(.text....
0
votes
1answer
14 views
Query on clang Code Coverage and gcov version
I am doing gcov processing of code compiled using clang. But my report is getting generated using gcov4.6. And the developer told me GNU on FreeBSD stopped around 2012 when they upgraded their license ...
1
vote
1answer
39 views
Why Clang running on Windows has no C conformance (__STDC__ is not defined to 1)?
Sample code (t127.c):
#include <stdio.h>
int main(void)
{
int ret;
#if __STDC__ == 1
printf("Has C conformance to version ");
#if __STDC_VERSION__
printf("%ld", ...
0
votes
0answers
14 views
How can I get details of QualType in Clang?
Follow this interesting question on StackOverflow, I always check whether a type is canonical, and get its canonical Type. But how can I get the detail of the struct type? For example, the fields in ...
1
vote
0answers
29 views
Python - Most portable way to check TypeKinds match for pointers
What I want
Given an AST, I want to identify all cursors that contain pointers to a specific integral type. For example, all of the following should be marked as being at least some type of char *.
...
0
votes
0answers
46 views
clang ASAN cross-compile ignoring sysroot for --whole-archive
I cross compile with debian x86_64, and target both aarch64 and armv6l by using --sysroot to point to a complete filesystem (I.E /cache/arm64 or /cache/armel) for the target architectures. I use qemu-...
-1
votes
1answer
38 views
C++ arrays with user input size (aka Why does this compile?)
I was experimenting with clang (10.0) on win 10, with the following snippet:
#include <iostream>
using namespace std;
int main()
{
const int N = 10;
int ii;
cout << "Enter ...
0
votes
0answers
16 views
CMake asio using clang compiler not able to find the library pthread
I am working on a test asio app using Ubuntu 20.04.2 LTS. I can build the project using default compler g++10 with the CMake, but when I try to use clang13, the CMake is not able to find pthread lib.
...
0
votes
0answers
26 views
LLVM ir ll code compiled with debug - how to get line numbers
Compiled LLVM IR code with -O0 -g -emit-llvm -S
How can I pinpoint llvm block to C code?
Found a problematic code using Static Analysis of LL file, but need to know where this is in C code, without ...
0
votes
0answers
10 views
polyhedral optimizations on 1D loop
Will Polly in LLVM recognize 1d for loop as scop? If not, why? When I tried a simple program with a single for loop and ran the below command, I got Invalid Scop!
$ opt -basicaa -polly-ast -analyze ...
0
votes
1answer
9 views
Running clang-query only on input files
I'm running clang-query on a specific file using a compilation database as follows:
clang-query -p build foo/bar.cpp
This works, but when I run a simple query (e.g. match ifStmt()) it returns ...
0
votes
0answers
36 views
Locate cache index with LLVM instrumented code and compute cache stats
I instrumented LLVM bc code and for each Store/Load Inst, when dynamically executed, it will print out a physical address. Here is an example sequence:
Store : 0x7ffca642f8f4
Store : 0x6010a0
Load : ...
0
votes
1answer
51 views
error: static_assert failed due to requirement '!is_signed<int>::value' “” static_assert((!is_signed<_Tp>::value), “”); [duplicate]
note: in instantiation of function template specialization 'std::__1::__gcd' requested here
while (__gcd(n, k) <= 1) n++;
The above line was displayed along with the error shown earlier, I know ...
0
votes
0answers
25 views
LLVM IR - from IR Assembly Format to C
I know you can you llvm-dis to get Assembly Format (*.ll) from IR. Is there a way to get C from Assembly Format? Actually to translate certain parts of it to C?
I.e this code:
test.c
#define NMAX 9 ...
1
vote
0answers
33 views
Why does LLVM pass nonsense values to an FFI function?
I have a C++ header declared like:
struct Inner {
// ...
};
struct MyStruct {
Inner* _inner;
size_t _x;
size_t _y;
};
extern "C" {
MyStruct my_fn(MyStruct* s, bool ...
2
votes
0answers
85 views
Clang produced executable is 94% null bytes, how to shrink it?
I've compiled my project with the following flags: clang -MMD -MP -D_FORTIFY_SOURCE=2 -Weverything -Wno-poison-system-directories -O2 -fPIE -fPIC -fstack-protector -finline-functions -march=native -...
1
vote
0answers
26 views
Why does clang ignore inline threshold flag?
I'm trying to find ways to compile my project optimally, however I've noted that if I pass -Rpass-missed=inline -mllvm -inline-threshold=500 I get nonsense output like the following:
src/getargv.c:241:...
2
votes
1answer
44 views
How to make older versions of clang happy with atomic's default exception specification
I have a class that has a member variable that wraps a std time_point in an atomic. I'm having a hard time getting older compilers happy with it. I initially had issues with versions of GCC earlier ...
0
votes
1answer
51 views
Is there a convenient way to switch the default Standard Library to Custom Library during compilation?
I'm looking for a way to switch the default Standard Library to a Custom Library during compilation without using external scripts.
I want to switch default Standard Library to Boost or Facebook Folly,...
0
votes
1answer
61 views
Clang Pragma Error: marked ‘override’, but does not override [closed]
I was trying to add a new pragma in clang and follow steps in LLVM document (Start from page 30). I've add new annotation in TokenKinds.def,
ANNOTATION(pragma_begin_mark)
and define Pragma Handler in ...
-3
votes
0answers
23 views
Porting Libcamera2 (HAL v2) to Android Marshmallow
I have a board that runs a custom Android Kitkat ROM with some customizations in the Libcamera2 (HAL V2) code. Here's the parts:
Seco - Board - A62
Driver - Freescale (NXP) 5640
ISP (Image sensor/...
0
votes
0answers
49 views
Why do Rustc and Clang's target-triple have 4 components
The target-triple in Rustc/Clang to choose compilation target has 4 components:
<arch><sub>-<vendor>-<sys>-<abi>
Why is it called a target-triple then?
1
vote
0answers
13 views
Example program showing how to use register_printf_domain_function?
I see very few google search result of register_printf_domain_function.
https://www.unix.com/man-page/osx/3/register_printf_domain_function/
Could anybody provide a minimal working example on how to ...