In my application, I have the following Objective-C code:
-(void)layoutPages { NSMutableArray* sections = [NSMutableArray array]; [sections addObject:[[NSAttributedString alloc] initWithString:@"Hello world"]]; for (NSAttributedString* contentSection in sections) { NSLog(@"%@",contentSection); } }

Console exit: 2014-04-22 14:11:01.505 MyApp[24784:830b] Hello world{}
If I compile for the x86_64 architecture using the -Os optimization, LLVM then silently optimizes the 'contentSection' loop variable. When I use -O0, the error disappears. This is the result when I try to print a description of the variable 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
How is this possible? From my point of view, a loop variable should never be optimized when used inside a loop. I saw that other people have a similar problem with LLVM, but not with a loop variable. Could this be a compiler error?
compiler-optimization objective-c llvm xcode5
Sbhklr
source share