标签: clang++

手动链接时 Clang 不生成 profraw 文件

我正在尝试clang使用llvm-cov和的分析功能llvm-profdata。我已经使用 CMake 设置了所有内容,但它没有default.profraw按预期生成。我手动尝试了这些步骤,发现如果我将生成目标文件和编译可执行文件之间的步骤分开,则clang不会生成文件。default.profraw

\n\n

例如,以下作品:

\n\n
$ clang++ -g -O0 -fprofile-instr-generate -fcoverage-mapping -std=gnu++2a binoperator.cpp main.cpp\n$ ./a.out\n38\nDone...\n$ ls -al default.profraw\n-rw-rw-r--. 1 marten marten 224 May 13 13:59 default.profraw\n
Run Code Online (Sandbox Code Playgroud)\n\n

以下内容不起作用(这大致是 CMake 尝试做的事情):

\n\n
$ clang++ -g -O0 -fprofile-instr-generate -fcoverage-mapping -std=gnu++2a -o binoperator.cpp.o -c binoperator.cpp\n$ clang++ -g -O0 -fprofile-instr-generate -fcoverage-mapping -std=gnu++2a -o main.cpp.o -c main.cpp\n$\xc2\xa0clang++ -o a.out binoperator.cpp.o main.cpp.o \n$\xc2\xa0./a.out\n38\nDone...\n$ ls -al default.profraw\nls: cannot access \'default.profraw\': No such file or directory\n …
Run Code Online (Sandbox Code Playgroud)

c++ clang llvm-clang clang++

5
推荐指数
1
解决办法
1618
查看次数

当我用 clang 编译代码时,gcov 抛出内存不足错误

我正在尝试建立一个基本项目,并且我想使用 gcov。当我使用 g++ 时,它可以工作:

g++ main.cpp whatever.cpp -fprofile-arcs -ftest-coverage
Run Code Online (Sandbox Code Playgroud)

gcov 的输出正常:

gcov main.gcno 
main.gcda:cannot open data file, assuming not executed
File 'main.cpp'
Lines executed:0.00% of 20
Creating 'main.cpp.gcov'

File '/usr/include/c++/7/iostream'
Lines executed:0.00% of 1
Creating 'iostream.gcov'
Run Code Online (Sandbox Code Playgroud)

但是,我需要使用 clang。运行编译命令后:

clang++-6.0 main.cpp whatever.cpp -fprofile-arcs -ftest-coverage
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

main.gcno:version '402*', prefer 'A73*'

gcov: out of memory allocating 16158246392 bytes after a total of 0 bytes
Run Code Online (Sandbox Code Playgroud)

我的gcov版本是7.3.0,与gcc和g++相同。

知道出了什么问题以及我能做些什么吗?

谢谢!

c++ clang gcov clang++

5
推荐指数
2
解决办法
5798
查看次数

clang++ 8.0.1 自分配重载警告

考虑这段代码:

class Vector {
public:
    Vector& operator+=(const Vector &v) { return *this; }
    Vector& operator-=(const Vector &v) { return *this; }
    Vector& operator*=(const Vector &v) { return *this; }
    Vector& operator/=(const Vector &v) { return *this; }
};

int main()
{
    Vector v;
    v += v;
    v -= v;
    v *= v;
    v /= v;
}
Run Code Online (Sandbox Code Playgroud)

当使用 clang++ 8.0.1 编译时,我收到以下警告:

$ clang++ -Wall example2.cpp -o example2
example2.cpp:13:7: warning: explicitly assigning value of variable of type 'Vector' to
      itself [-Wself-assign-overloaded]
    v …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-warnings clang++

5
推荐指数
1
解决办法
2416
查看次数

解决方法 --exclude-libs 在 OS X 的 clang 上不可用

我需要创建一个需要使用不同版本的 OpenSSL (BoringSSL) 的包装器库,原因请参阅“包装器共享对象”[1]。

问题是 --exclude-libs 不适用于 OS X 的 clang,因此符号被导出,这是我必须避免的。

我必须采取哪些选项来解决此问题,例如在构建库后剥离符号?

[1] https://wiki.openssl.org/index.php/Android

macos g++ clang ld clang++

5
推荐指数
1
解决办法
1542
查看次数

无法在 Mac OSX 上使用 clang++ 编译 C++17

铿锵++版本:

Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Run Code Online (Sandbox Code Playgroud)

尝试一些 C++ 并行性:

Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Run Code Online (Sandbox Code Playgroud)

我尝试过使用所有这些进行编译:

#include <algorithm>
#include <execution>
#include <iostream>
#include <vector>
#include <random>
#include <math.h>

#define N 10000000

double myFunction(double x) {
    return pow(x, x) / (int(x) % 3);
}

int main() {
    std::random_device rd;
    std::uniform_real_distribution<double> uniform(0.0, 20.0);

    std::vector<double> inputs;
    std::vector<double> returnValues;
    for (int i = 0; i < N; ++i) {
        double r …
Run Code Online (Sandbox Code Playgroud)

c++ macos g++ clang++ c++17

5
推荐指数
2
解决办法
6313
查看次数

为什么添加链接器标志 `-save-temps` 可以解决 clang-8 错误:“无法创建临时文件”?

我正在使用 Windows + Cygwin + Eclipse + LLVM 工具链来构建 C/C++ 项目。

这些文件可以使用clangC 编译器正常编译,但使用clang++多个error: unable to make temporary file: No such file or directory.

clang++ -o test "source1.bc" "source2.bc" "source3.bc" 
clang-8: error: unable to make temporary file: No such file or directory
clang-8: error: unable to make temporary file: No such file or directory
clang-8: error: unable to make temporary file: No such file or directory
Run Code Online (Sandbox Code Playgroud)

链接器为每个目标文件生成一个错误。

当我将-save-temps选项添加到链接器时,它工作正常!

可能是什么问题呢?

添加--verbose给出:

clang …
Run Code Online (Sandbox Code Playgroud)

c llvm clang clang++

5
推荐指数
1
解决办法
1552
查看次数

与 GNU Make 链接时参数列表太长

我有一个相当大的项目(4272 .o 文件),但无法将其与 GNU Make 链接。我遇到了make: /bin/sh: Argument list too long。这是一个使用 qmake 生成 makefile 的 Qt 5 项目。

我知道有很多关于此的问题,但我不知道如何将任何解决方案应用于我的问题。我也不完全确定为什么我在链接步骤中遇到这个问题。我得到的错误是:

make: /bin/sh: Argument list too long

用于链接我的项目的 makefile 条目如下所示:

build/debug/my_target/my_target:  $(OBJECTS)  
    @test -d build/debug/my_target/ || mkdir -p build/debug/my_target/
    $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
Run Code Online (Sandbox Code Playgroud)

它扩展到类似:

@echo linking /build/debug/my_target/my_target && clang++ -ccc-gcc-name g++ -lc++ -L/path/to/licensing/lib -Wl,-rpath,/path/to/qt/lib -Wl,-rpath-link,/path/to/qt/lib -o build/debug/my_target/my_target build/debug/my_target/obj/object1.o build/debug/my_target/obj/object2.o ... build/debug/my_target/obj/object4272.o  ... [ a bunch of moc_X.o ] ... [ a bunch of libs ] …
Run Code Online (Sandbox Code Playgroud)

linux makefile gnu-make clang++

5
推荐指数
1
解决办法
5641
查看次数

Clang 错误“未定义模板 std::tuple_size&lt;auto&gt; 的隐式实例化”

对于 Clang 的行为“未定义的模板 smthg<auto>”,是否有一个(干净的)解决方法?

代码示例:

额外的见解:

我期望的是,根据上面提供的示例,分别获得两种具有相同 -可评估- 的类型std::tuple_size_v

  error : cannot mangle this 'auto' type yet
Run Code Online (Sandbox Code Playgroud)

我是否遗漏了一点?

代码示例:

class std::tuple<
   struct std::integral_constant<bool,0>,
   struct std::integral_constant<bool,1>,
   struct std::integral_constant<bool,0>
>
class std::tuple<bool,bool,bool>
Run Code Online (Sandbox Code Playgroud)

c++ clang++ c++20

5
推荐指数
1
解决办法
1621
查看次数

如何在 C++17 中定义用户定义的字符串文字运算符模板?

根据我的C++17(草案)版本(16.5.8 [over.literal]) 以及cppreference.com,C++17应该支持用户定义的字符串文字的模板化运算符。

具体来说:

template <char...>
double operator "" _pi() {
    return 0.;
}

int main() {
  "test"_pi;
}
Run Code Online (Sandbox Code Playgroud)

然而,gcc 和 clang 都对我大喊大叫:

// gcc -Wall -Wextra -pedantic -std=c++17
error: no matching function for call to 'operator""_pi<char, 't', 'e', 's', 't'>()'
    7 |   "test"_pi;
      |   ^~~~~~~~~
note: candidate: 'template<char ...<anonymous> > double operator""_pi()'
    2 | double operator "" _pi() {

// clang -Wall -Wextra -pedantic -std=c++17
error: no matching literal operator for call to …
Run Code Online (Sandbox Code Playgroud)

c++ g++ string-literals clang++ c++17

5
推荐指数
1
解决办法
1099
查看次数

在生产中使用地址消毒剂或其他未定义行为消毒剂?

过去,人们对在某些环境中的生产中使用 ASAN 存在担忧:https://seclists.org/oss-sec/2016/q1/363。评论是2016年的——今天的风景怎么样?

是否建议在用户设备上运行的生产系统中使用消毒剂?应用程序接收来自其他方的不受信任的输入,并以各种方式处理这些输入。

使用它们是否会产生与安全相关的影响?添加的任何工具实际上是否可以更轻松地远程利用错误?

我正在考虑的应用程序是开源的,因此在这种情况下简化逆向工程不会成为问题。

c++ undefined-behavior clang++ address-sanitizer

5
推荐指数
1
解决办法
1111
查看次数