Fix invalid declaration of rsClearObject() iterator.

Bug: 23445219
Bug: 19545955

The erroneous code here triggered an assertion while building source
files that include an array destructor for RS object types (i.e.
rs_allocation a[4];). In the original case, the creation of the helper
iterator formed an invalid AST that caused the emission of its alloca
twice (because Clang would walk the outer scoped declaration first, and
then see another DeclRef to the creation within the loop). Moving the
iterator declaration into the loop (as an initialized variable) properly
scopes things, and makes the resulting AST a bit easier to read as well.
This never caused any harm without the assertion because the new (inner
scope) value would always overwrite the older (outer scope) value.

This change also fixes an improper use of the LValue for the iterator
when comparing it with the array bounds. The code now contains the
proper LValueToRValue cast. Relevant comments have been updated to show
the new AST that we have formed.

The final issue that this code defensively handles is the creation of
nested iterators (which isn't currently supported, but could be in the
future). In this case, we create a unique name for the iterator using a
static counter. The code should probably be refactored to use a proper
depth count (like other areas of Clang already do), but that can be part
of a separate cleanup CL, since it would be quite invasive.

The assertion fixed by this CL looks like:

llvm-rs-cc: external/clang/lib/CodeGen/CGDecl.cpp:1015: CodeGenFunction::AutoVarEmission clang::CodeGen::CodeGenFunction::EmitAutoVarAlloca(const clang::VarDecl &): Assertion `!DMEntry && "Decl already exists in localdeclmap!"' failed.

Change-Id: I4e8551de62112661d601d73104988e5adcfd6855
1 file changed