[PATCH] D15115: [Microsoft][C++] Clang doesn't support a use of "this" pointer inside inline asm
michael zuckerman via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 2 05:21:19 PST 2015
m_zuckerman updated this revision to Diff 41612.
m_zuckerman marked an inline comment as done.
http://reviews.llvm.org/D15115
Files:
lib/CodeGen/CGStmt.cpp
lib/Parse/ParseExprCXX.cpp
lib/Parse/ParseStmtAsm.cpp
test/CodeGen/ms_this.cpp
test\CodeGen\ms_this.cpp
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: 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: 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;
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15115.41612.patch
Type: text/x-patch
Size: 2694 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151202/c0f6f6a6/attachment.bin>
More information about the llvm-commits
mailing list