Index: lib/Sema/SemaStmtAsm.cpp =================================================================== --- lib/Sema/SemaStmtAsm.cpp +++ lib/Sema/SemaStmtAsm.cpp @@ -662,11 +662,21 @@ } fillInlineAsmTypeInfo(Context, T, Info); - + + Expr *Res = Result.get(); // We can work with the expression as long as it's not an r-value. - if (!Result.get()->isRValue()) + if (!Res->isRValue()) { Info.IsVarDecl = true; + return Result; + } + Expr::EvalResult EvlResult; + // Try to evaluate the identifier as enum constant + if (isa(Res->getType()) && Res->EvaluateAsRValue(EvlResult, + getASTContext())) { + Info.ConstIntValue = EvlResult.Val.getInt(); + Info.IsConstEnum = true; + } return Result; } Index: test/CodeGen/x86-ms-inline-asm-enum_feature.cpp =================================================================== --- test/CodeGen/x86-ms-inline-asm-enum_feature.cpp +++ test/CodeGen/x86-ms-inline-asm-enum_feature.cpp @@ -0,0 +1,44 @@ +// REQUIRES: x86-registered-target +// RUN: %clang_cc1 %s -fasm-blocks -emit-llvm -o - | FileCheck %s +namespace x { +enum { A = 12 }; +namespace y { +enum { A = 17 }; +} +} + +void x86_enum_namespaces() { + enum { A = 1 }; + // CHECK: mov eax, $$12 + __asm mov eax, x::A + // CHECK: mov eax, $$17 + __asm mov eax, x::y::A + // CHECK: mov eax, $$1 + __asm mov eax, A +} + +void x86_enum_arithmethic() { + enum { A = 1, B }; + // CHECK: mov eax, $$21 + __asm mov eax, (A + 9) * 2 + A + // CHECK: mov eax, $$4 + __asm mov eax, A << 2 + // CHECK: mov eax, $$2 + __asm mov eax, B & 3 + // CHECK: mov eax, $$5 + __asm mov eax, 3 + (B & 3) + // CHECK: mov eax, $$8 + __asm mov eax, 2 << A * B +} + +void x86_enum_mem() { + int arr[4]; + enum { A = 4, B }; + + // CHECK: mov eax, [($$12 + $$9) + $$4 * $$5 + $$3 + $$3 + eax] + __asm { mov eax, [(x::A + 9) + A * B + 3 + 3 + eax] } + // CHECK: mov eax, dword ptr $$4$0 + __asm { mov eax, dword ptr [arr + A] } + // CHECK: mov eax, dword ptr $$8$0 + __asm { mov eax, dword ptr A[arr + A] } +} \ No newline at end of file