LLVM循环优化错误?

在我的应用程序中,我有以下Objective-C代码:

-(void)layoutPages
{
    NSMutableArray* sections = [NSMutableArray array];
    [sections addObject:[[NSAttributedString alloc] initWithString:@"Hello world"]];

    for (NSAttributedString* contentSection in sections) {
        NSLog(@"%@",contentSection);
    }
}

在这里输入图像描述

控制台输出: 2014-04-22 14:11:01.505 MyApp[24784:830b] Hello world{}

如果我使用-Os优化编译x86_64架构,LLVM会默认优化循环变量'contentSection'。 当我使用-O0时,错误消失。 当我尝试打印contentSection变量的描述时,这是输出:

(lldb) po contentSection
error: Couldn't materialize struct: the variable 'contentSection' has no location, it may have been optimized out
Errored out in Execute, couldn't PrepareToExecuteJITExpression

这怎么可能? 从我的角度来看,循环变量在循环内部使用时不应该被优化。 我看到其他人与LLVM有类似的问题,但没有使用循环变量。 这可能是一个编译器错误?


这可能是一个编译器设置问题。 首先,您需要检查您的运行方案是否处于发布模式。 进入“Edit scheme ...” - >“Run” - >“Info” - >“Build Configuration”。 确保该值设置为“调试”。

如果这不是问题,那么请确保您的调试版本设置没有打开编译器优化。 确保“优化级别”设置为“无”用于调试。 还要确保没有其他可以设置编译器优化级别的地方,比如在“其他C标志”设置中。

链接地址: http://www.djcxy.com/p/20025.html

上一篇: LLVM loop optimization bug?

下一篇: Can't deduce f = f₁ from f x = f₁ y?