Hi everyone,
Since r230724 ("Skip promotable allocas to improve performance at -O0"), there is a regression in the generated debug info for those non-instrumented variables. When inspecting such a variable's value in LLDB, you often get garbage instead of the actual value. Fred was able to track this down:
What happens is quite sad: The variable doesn’t get instrumented and thus should behave like a standard stack variable. However, ASAN’s instrumentation is inserted before the creation of the non-instrumented alloca. The only allocas that are considered standard stack variables are the ones declared in the first basic-block, but the initial instrumentation setup in the function breaks that invariant. Indeed, if moving the alloca to the first BB, things work. (This shows that the llvm.dbg.declare intrinsic is badly defined. Depending on whether the alloca it refers to is in the first BB or not, it means something quite different…)
The simplest way that I can think of preventing this issue is to make sure that the uninstrumented allocas stay in the first BB. I think this is safe, because static promotable allocas shouldn’t depend on any other value, and moving them up they will still dominate their uses, thus the SSA form should be maintained. I might very well be missing some corner cases though. The following patch does that.