OSDN Git Service

Quick compiler: Fix ambiguous LoadValue()
authorbuzbee <buzbee@google.com>
Fri, 3 Oct 2014 20:14:17 +0000 (13:14 -0700)
committerbuzbee <buzbee@google.com>
Fri, 3 Oct 2014 20:14:17 +0000 (13:14 -0700)
commit7c02e918e752ab36f0b6cab7528f10c0cf55a4ee
tree704cb9845bbdecc977c8fb31dc0a677450d17303
parentb5325e24ca58299b2b011e57e784b2584f99d687
Quick compiler: Fix ambiguous LoadValue()

Internal b/17790197 & hat tip to Stephen Kyle

The following custom-edited dex program demonstrated
incorrect code generation caused by type confusion.
In the example, the constant held in v0 is used in both
float and int contexts, and the register class gets
confused at the if-eq.

.method private static getInt()I
    .registers 4
    const/16 v0, 100
    const/4 v1, 1
    const/4 v2, 7
    :loop
    if-eq v2, v0, :done
    add-int v2, v2, v1
    goto :loop
    :done
    add-float v3, v0, v1
    return v2
.end method

The bug was introduced in c/96499, "Quick compiler: reference cleanup"
That CL created a convenience variant of LoadValue which selected the
target register type based on the type of the RegLocation.  It should
not have done so.  The type of a RegLocation is the compiler's best
guess of the Dalvik type - and Dalvik allows constants to be used
in multiple type contexts.  All code generation utilities must specify
desired register class based on the capabilities of the instructions
to be emitted.  In the failing case, OpCmpImmBranch (and
GenCompareZeroAndBranch) will be using core registers, so the
LoadValue must specify  either kCoreReg or kRefReg.

The CL deletes the dangerous LoadValue() variant.

Change-Id: Ie4ec6e51b19676dbbb9628c72c8b3473a419e7ec
compiler/dex/quick/arm/int_arm.cc
compiler/dex/quick/gen_common.cc
compiler/dex/quick/gen_invoke.cc
compiler/dex/quick/gen_loadstore.cc
compiler/dex/quick/mir_to_lir.h
compiler/dex/quick/x86/int_x86.cc