我不确定这是否是Xcode 4.6.3(4H1503)附带的LLVM的实际错误,或者我是否正在做一些非常犹太的事情.代码片段如下
for(auto &a : matrix[j]) {
a = false;
}
Run Code Online (Sandbox Code Playgroud)
哪matrix一个vector是vector含有布尔的.我一直在使用Visual Studio 2012进行一段时间的开发,这似乎不是问题,但是应用程序也需要在Mac上运行,所以我继续测试它......我有点惊讶于我无法编译.仔细观察后,我发现我从铿锵声中得到了一个完整的段落故障,这通常表明非常糟糕的恶作剧正在发生.所以我迅速隔离了这段代码,并使用整数索引和所有爵士乐将循环更改为更农民的版本.它就像一个魅力.
假设我的原始循环应该正常工作我是否正确(我在SO中看到了类似的东西,除了VS2012之外没有任何可说的,真的)或者我犯了一个严重的错误你真的不应该使用这样的引用?
在向Apple报告错误之前,我想知道这一点.
编辑
#include <vector>
using namespace std;
int main(void) {
vector<vector<bool>> matrix = vector<vector<bool>>(10, vector<bool>(5, false));;
for(auto &a : matrix[0]) {
a = true;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
用clang -x c++ -std=c++11 -stdlib=libc++收益率编制
0 clang 0x0000000100c57bb2 main + 12932498
Stack dump:
0. Program arguments: /usr/bin/clang -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name rbloop.cpp -pic-level 2 -mdisable-fp-elim …Run Code Online (Sandbox Code Playgroud) 我期待从C代码生成LLVM-IR代码,并想知道函数的IR生成有多好:
stdio.h,string.h,stdlib.h和一般标准的基于内存的函数,如malloc,calloc,因为我还没有找到大多数常用函数:
http://llvm.org/docs/LangRef.html并且想知道这种表示的局限性以及是否可能需要添加我自己的内在函数来处理标准/最流行的c函数.
我希望在运行时更改代码,所以想知道哪种方法会给我最大的灵活性,例如:操作AST级别的代码.
谢谢
相关链接http://kevinaboos.wordpress.com/2013/07/23/clang-tutorial-part-ii-libtooling-example
我正在使用CommonOptionsParser解析clang工具的参数:
// parse the command-line args passed to your code
CommonOptionsParser op(argc, argv);
// create a new Clang Tool instance (a LibTooling environment)
ClangTool Tool(op.getCompilations(), op.getSourcePathList());
// run the Clang Tool, creating a new FrontendAction (explained below)
int result = Tool.run(newFrontendActionFactory<SomeAction>());
Run Code Online (Sandbox Code Playgroud)
和下一个参数:
llvm/Debug+Asserts/bin/mytool /somePath/someSource.mm --
Run Code Online (Sandbox Code Playgroud)
当我在某个源文件上运行我的工具(基于clang libtooling)时,工具尝试查找包含的文件,fe :
#import “SomeClass.h”,或#import<Foundation/Foundation.h>
如果它找不到标题,则会产生错误:
致命错误:找不到'Foundation/Foundation.h'文件.
你能告诉我,如果你知道,我怎样才能将工具引导到标准框架?我怎样才能将它指向某些标题搜索路径?如何在运行工具时设置标题搜索路径?
在编辑了我的Xcode 5.1.0源文件后,我突然收到此链接器错误:
0 0x1059b5f93 __assert_rtn + 144
1 0x105a1d7f5 ld::tool::OutputFile::compressedOrdinalForAtom(ld::Atom const*) + 281
2 0x105a1e469 ld::tool::OutputFile::addDyldInfo(ld::Internal&, ld::Internal::FinalSection*, ld::Atom const*, ld::Fixup*, ld::Fixup*, ld::Fixup*, ld::Atom const*, ld::Atom const*, unsigned long long, unsigned long long) + 2261
3 0x105a14496 ld::tool::OutputFile::generateLinkEditInfo(ld::Internal&) + 1322
4 0x105a0f952 ld::tool::OutputFile::write(ld::Internal&) + 116
5 0x1059b6c40 main + 1012
A linker snapshot was created at:
/tmp/keytech PLM-2014-03-05-101905.ld-snapshot
ld: Assertion failed: (0 && "dylib not assigned ordinal"), function compressedOrdinalForAtom, file /SourceCache/ld64/ld64-236.3/src/ld/OutputFile.cpp, line 3454.
clang: error: linker command failed with exit code …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用clang3.4编译程序,并且忽略了我使用的优化传递(或标志?!).
例如,我正在尝试编译,并传递以下选项"
-O1 -instcombine
我明白了:
clang34: warning: argument unused during compilation: '-instcombine'
Run Code Online (Sandbox Code Playgroud)
可以在此处找到LLVM的所有可用优化通道的列表,并在此问题中找到.我错过了什么吗?
谢谢.
我工作的一个简单的解决方案,以共同的"上形成不良的类型条件"的问题(像这个昨天的问题).
在我的代码库中,我有一个模板来保存未实例化的模板并在以后实例化它们.像这样的东西:
template<template<typename...> class F>
struct lazy
{};
namespace impl
{
template<typename L , typename... ARGS>
struct lazy_instance;
template<template<typename...> class F , typename... ARGS>
struct lazy_instance<lazy<F>,ARGS...> : public identity<F<ARGS...>>
{};
}
template<typename L , typename... ARGS>
using lazy_instance = typename impl::lazy_instance<L,ARGS...>::type;
Run Code Online (Sandbox Code Playgroud)
identity身份元功能在哪里.
这可以使用如下:
using vector = lazy<std::vector>;
using int_vector = lazy_instance<vector,int>;
Run Code Online (Sandbox Code Playgroud)
因此,我想到的解决方案是以这种方式包装条件的两个目标,并实例化条件的结果,因此只有选定的模板才会被实例化.为此,我修改了lazy并impl::lazy_instance允许我们在lazy瞬间点传递模板参数:
template<template<typename...> class F , typename... ARGS>
struct lazy
{};
namespace impl
{
template<typename L , typename... ARGS> …Run Code Online (Sandbox Code Playgroud) 我正在尝试从clang 构建PrintFunctionNames示例。但是我收到以下错误:
[mac-osx:clang/examples/PrintFunctionNames] osx% clang++ -std=c++0x PrintFunctionNames.cpp
In file included from PrintFunctionNames.cpp:15:
In file included from /usr/local/include/clang/Frontend/FrontendPluginRegistry.h:13:
In file included from /usr/local/include/clang/Frontend/FrontendAction.h:22:
In file included from /usr/local/include/clang/Basic/LLVM.h:22:
In file included from /usr/local/include/llvm/Support/Casting.h:19:
/usr/local/include/llvm/Support/type_traits.h:17:10: fatal error: 'type_traits' file not found
#include <type_traits>
Run Code Online (Sandbox Code Playgroud)
系统信息:
clang版本4.0.0(http://llvm.org/git/clang.git 6197d01def79876e2c1670ced871e10b12c36241)(http://llvm.org/git/llvm.git 24f7cd87f70ddcc91d50f77e405420c0c27853fd)目标:x86_64-apple-darwin15.6.0线程模型InstalledDir:/ usr / local / bin
OSX 10.11.6
编辑1:
在进行Alex建议的更改时,我开始遇到标题问题。通过include修复它时,再次抛出相同的错误
% clang++ -std=c++0x PrintFunctionNames.cpp -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -I../../../clang/include -I../../../../include -I../../../../../build/include
In file included from PrintFunctionNames.cpp:15:
In file included from ../../../clang/include/clang/Frontend/FrontendPluginRegistry.h:13:
In file included …Run Code Online (Sandbox Code Playgroud) 我已经测试过在我的ubuntu 16.04机器上用SDL2源代码(2.0.5)构建样本.
根据https://wiki.libsdl.org/Android,我安装了android sdk和ndk r14并设置我的环境变量.
但我无法在"简单构建"一章中使用以下命令构建.
cd /usr/src/SDL2/build-scripts/
./androidbuild.sh org.libsdl.testgles ../test/testgles.c
Run Code Online (Sandbox Code Playgroud)
它会产生以下错误.
Error: The project either has no target set or the target is invalid.
Please provide a --target to the 'android update' command.
[armeabi] Compile thumb : SDL2 <= SDL.c
[armeabi] Compile thumb : SDL2 <= SDL_assert.c
[armeabi] Compile thumb : SDL2 <= SDL_error.c
[armeabi] Compile thumb : SDL2 <= SDL_hints.c
[armeabi] Compile thumb : SDL2 <= SDL_log.c
[armeabi] Compile thumb : SDL2 <= SDL_audio.c
[armeabi] Compile …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用带有-fsanitize = address选项的clang编译最简单的可执行文件。直接使用clang做到这一点非常简单。但是我的意思是通过CMake做到这一点。
我正在做这件事。CMakeLists.txt文件:
cmake_minimum_required(VERSION 3.5.1 FATAL_ERROR)
project(TestSanitizer VERSION 0.1.0 LANGUAGES CXX)
add_executable(Test main.cpp)
target_compile_options(Test PUBLIC
-std=c++17
-Werror
-Weverything
-Wno-c++98-compat
-Wno-c++98-c++11-c++14-compat
-Wno-c++98-compat-pedantic
-fsanitize=address)
Run Code Online (Sandbox Code Playgroud)
main.cpp:
int main(int, const char**) { return 0; }
Run Code Online (Sandbox Code Playgroud)
使用bash脚本(config_gen_build.sh)进行配置和制作:
if [ -d "bin" ]; then
rm -rf bin
fi
mkdir bin
cd bin
#config and gen
export CC=/usr/bin/clang-5.0
export CXX=/usr/bin/clang++-5.0
cmake ./../
#build
make
Run Code Online (Sandbox Code Playgroud)
怎么了 我应该链接一些图书馆吗?
我正在使用Clang / libtooling(ASTComsumer带有Matcher)来访问所有return语句(ReturnStmt)。我需要提取return字符串形式的关键字之后的表达式,以便可以将其放入替换return语句的宏中。
例如,我要替换以下行:
return somefunc() + 1;
Run Code Online (Sandbox Code Playgroud)
与
FUNCTION_EXIT(somefunc() + 1); // FUNCTION_EXIT is a C macro
Run Code Online (Sandbox Code Playgroud)
return进行一些记录后,宏将从函数中获取。
我正在使用ReturnStmt::getRetValue()该返回值,Expr并尝试以字符串形式获取它(以便可以将其传递给宏),但是我还没有找到一种方法。有没有一种方法可以分类Expr?
llvm-clang ×10
c++ ×5
clang ×4
c++11 ×3
llvm ×2
android ×1
android-ndk ×1
c ×1
cmake ×1
compilation ×1
header-files ×1
include ×1
libtooling ×1
linker ×1
llvm-ir ×1
macos ×1
sdl-2 ×1
templates ×1
xcode ×1