LLVM loop optimization error?

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); } } 

enter image description here

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?

+7
compiler-optimization objective-c llvm xcode5
source share
1 answer

This is probably a problem with the compiler settings. First, you will want to verify that your trigger pattern is not in release mode. Go to "Edit Schema ..." β†’ "Run" β†’ "Information" β†’ "Assembly Configuration". Make sure the value is set to Debug.

If this is not a problem, make sure that there is no compiler optimizer in the settings of your debug version. Verify that Optimization Level is set to none for debugging. Also make sure that there is no other place where compiler optimization levels can be set, for example, in the "Other C flags" setting.

+3
source share

All Articles