Index: lib/CodeGen/CGStmt.cpp =================================================================== --- lib/CodeGen/CGStmt.cpp +++ lib/CodeGen/CGStmt.cpp @@ -1684,7 +1684,8 @@ if (Info.allowsRegister() || !Info.allowsMemory()) if (CodeGenFunction::hasScalarEvaluationKind(InputExpr->getType())) return EmitScalarExpr(InputExpr); - + if (InputExpr->getStmtClass() == Expr::CXXThisExprClass) + return EmitScalarExpr(InputExpr); InputExpr = InputExpr->IgnoreParenNoopCasts(getContext()); LValue Dest = EmitLValue(InputExpr); return EmitAsmInputLValue(Info, Dest, InputExpr->getType(), ConstraintStr, Index: lib/Parse/ParseExprCXX.cpp =================================================================== --- lib/Parse/ParseExprCXX.cpp +++ lib/Parse/ParseExprCXX.cpp @@ -2564,7 +2564,8 @@ Result.setDestructorName(TildeLoc, Ty, ClassNameLoc); return false; } - + if (Tok.is(tok::kw_this)) + return true; Diag(Tok, diag::err_expected_unqualified_id) << getLangOpts().CPlusPlus; return true; Index: lib/Parse/ParseStmtAsm.cpp =================================================================== --- lib/Parse/ParseStmtAsm.cpp +++ lib/Parse/ParseStmtAsm.cpp @@ -240,7 +240,10 @@ Result = Actions.LookupInlineAsmVarDeclField( Result.get(), Id->getName(), OffsetUnused, Info, Tok.getLocation()); } - + if (Tok.is(tok::kw_this)) { + Result = ParseCXXThis(); + Invalid = false; + } // Figure out how many tokens we are into LineToks. unsigned LineIndex = 0; if (Tok.is(EndOfStream)) { Index: test/CodeGen/ms_this.cpp =================================================================== --- test/CodeGen/ms_this.cpp +++ test/CodeGen/ms_this.cpp @@ -0,0 +1,47 @@ +// RUN: %clang_cc1 -fasm-blocks -emit-llvm %s -o - | FileCheck %s +class t1 { +public: + double a; + void runc(); +}; + +class t2 { +public: + double a; + void runc(); +}; + +void t2::runc() { + double num = 0; + __asm { + mov rax,[this] + //CHECK: %this.addr = alloca %class.t2* + //CHECK: call void asm sideeffect inteldialect "mov rax,qword ptr $1{{.*}}%class.t2* %this1 + mov rbx,[rax] + mov num, rbx + }; +} + +void t1::runc() { + double num = 0; + __asm { + mov rax,[this] + //CHECK: %this.addr = alloca %class.t1* + //CHECK: call void asm sideeffect inteldialect "mov rax,qword ptr $1{{.*}}%class.t1* %this1 + mov rbx,[rax] + mov num, rbx + }; +} + +struct s { + void func() { + __asm mov eax, [this] + //CHECK: %this.addr = alloca %struct.s* + //CHECK: call void asm sideeffect inteldialect "mov eax, qword ptr this" + } +} f3; + +int main() { + f3.func(); + return 0; +}