Index: lib/Sema/SemaStmtAsm.cpp =================================================================== --- lib/Sema/SemaStmtAsm.cpp +++ lib/Sema/SemaStmtAsm.cpp @@ -665,8 +665,12 @@ fillInlineAsmTypeInfo(Context, T, Info); // We can work with the expression as long as it's not an r-value. - if (!Result.get()->isRValue()) + if (!Result.get()->isRValue()) { Info.IsVarDecl = true; + Expr::EvalResult Eval; + if (Result.get()->EvaluateAsLValue(Eval, Context)) + Info.IsGlobalLV = Eval.isGlobalLValue(); + } return Result; } Index: test/CodeGen/ms-inline-asm-indirect-memory-ref.c =================================================================== --- test/CodeGen/ms-inline-asm-indirect-memory-ref.c +++ test/CodeGen/ms-inline-asm-indirect-memory-ref.c @@ -0,0 +1,36 @@ +// REQUIRES: x86-registered-target +// RUN: %clang_cc1 %s -fasm-blocks -triple x86_64-unknown-linux-gnu -emit-llvm -o - | FileCheck %s + +int gVar; + +void t1() { + // CHECK: add eax, dword ptr gVar[eax] + __asm add eax, dword ptr gVar[eax] + // CHECK: add dword ptr gVar[eax], eax + __asm add dword ptr [eax+gVar], eax + // CHECK: add ebx, dword ptr gVar[ebx + $$270] + __asm add ebx, dword ptr gVar[271 - 82 + 81 + ebx] + // CHECK: add dword ptr gVar[ebx + $$828], ebx + __asm add dword ptr [ebx + gVar + 828], ebx + // CHECK: add ecx, dword ptr gVar[ecx + ecx * $$4 + $$4590] + __asm add ecx, dword ptr gVar[4590 + ecx + ecx*4] + // CHECK: add dword ptr gVar[ecx + ecx * $$8 + $$73], ecx + __asm add dword ptr [gVar + ecx + 45 + 23 - 53 + 60 - 2 + ecx*8], ecx + // CHECK: add gVar[ecx + ebx + $$7], eax + __asm add 1 + 1 + 2 + 3[gVar + ecx + ebx], eax +} + +void t2() { + int lVar; + // CHECK: mov eax, dword ptr ${{[0-9]}}[eax] + __asm mov eax, dword ptr lVar[eax] + // CHECK: mov dword ptr ${{[0-9]}}[eax], eax + __asm mov dword ptr [eax+lVar], eax + // CHECK: mov ebx, dword ptr ${{[0-9]}}[ebx + $$270] + __asm mov ebx, dword ptr lVar[271 - 82 + 81 + ebx] + // CHECK: mov dword ptr ${{[0-9]}}[ebx + $$828], ebx + __asm mov dword ptr [ebx + lVar + 828], ebx + // CHECK: mov ${{[0-9]}}[ebx + $$47], eax + __asm mov 5 + 8 + 13 + 21[lVar + ebx], eax +} + Index: test/CodeGen/ms-inline-asm.c =================================================================== --- test/CodeGen/ms-inline-asm.c +++ test/CodeGen/ms-inline-asm.c @@ -515,7 +515,7 @@ __asm { mov eax, 4*(4-2)[64 + arr - 2*32] } // CHECK: call void asm sideeffect inteldialect "mov eax, $$8$0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"([4 x i32]* %{{.*}}) __asm { mov eax, 32*(4-2)[arr - 2*32] } -// CHECK: call void asm sideeffect inteldialect "mov eax, $$0$0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"([4 x i32]* %{{.*}}) +// CHECK: call void asm sideeffect inteldialect "mov eax, $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"([4 x i32]* %{{.*}}) } void cpuid() { Index: test/Sema/ms-inline-asm.c =================================================================== --- test/Sema/ms-inline-asm.c +++ test/Sema/ms-inline-asm.c @@ -59,10 +59,8 @@ mov eax, arr[1 + (2 * 5) - 3 + 1<<1]; } - // expected-error@+1 {{cannot use base register with variable reference}} - __asm { mov eax, arr[ebp + 1 + (2 * 5) - 3 + 1<<1] } - // expected-error@+1 {{cannot use index register with variable reference}} - __asm { mov eax, arr[esi * 4] } + // expected-error@+1 {{Can't use a local variable with both base and index registers}} + __asm { mov eax, [i + eax + ebx] } // expected-error@+1 {{cannot use more than one symbol in memory operand}} __asm { mov eax, arr[i] } // expected-error@+1 {{cannot use more than one symbol in memory operand}}