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 false; 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,6 +240,8 @@ Result = Actions.LookupInlineAsmVarDeclField( Result.get(), Id->getName(), OffsetUnused, Info, Tok.getLocation()); } + if (Tok.is(tok::kw_this)) + Result = ParseCXXThis(); // Figure out how many tokens we are into LineToks. unsigned LineIndex = 0; Index: test/CodeGen/ms_this.cpp =================================================================== --- test/CodeGen/ms_this.cpp +++ test/CodeGen/ms_this.cpp @@ -0,0 +1,44 @@ +// 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(); +}; + +struct s { + void func() { + __asm mov eax, [this] + //CHECK: %this.addr = alloca %struct.s* + } +} f3; + +void t2::runc() { + double num = 0; + __asm { + mov rax,[this] + //CHECK :%this.addr = alloca %class.t2* + mov rbx,[rax] + mov num, rbx + }; +} + +void t1::runc() { + double num = 0; + __asm { + mov rax,[this] + //CHECK :%this.addr = alloca %class.t1* + mov rbx,[rax] + mov num, rbx + }; +} + +int main() { + f3.func(); + return 0; +}