[patch] Let ms inline asm understand using statements and record names in addition to typedefs
Nico Weber
thakis at chromium.org
Sat May 3 17:26:50 PDT 2014
Hi,
while looking at something else, I learned that with -fasm-blocks,
clang understands
typedef struct {
int a;
int b;
} A;
__asm mov eax, [eax].A.b
It only supports typedefs though, not the same thing with `using A =
struct { ... };`, and also not the direct `struct A { ... }`. This
seems inconsistent, so the attached patch adds support for that. I
don't know if adding such support is useful or desirable, but since I
already wrote the 4 lines to make it work I figured I could at least
send out the patch :-)
Nico
ps: Fun fact: With s/struct/class/ in the snippet above, clang does
print "error: 'b' is a private member of 'A'" (yay!) but does so
without a source location (boo!, but understandable I suppose.)
-------------- next part --------------
Index: lib/Sema/SemaStmtAsm.cpp
===================================================================
--- lib/Sema/SemaStmtAsm.cpp (revision 207920)
+++ lib/Sema/SemaStmtAsm.cpp (working copy)
@@ -441,8 +441,10 @@
NamedDecl *FoundDecl = BaseResult.getFoundDecl();
if (VarDecl *VD = dyn_cast<VarDecl>(FoundDecl))
RT = VD->getType()->getAs<RecordType>();
- else if (TypedefDecl *TD = dyn_cast<TypedefDecl>(FoundDecl))
+ else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(FoundDecl))
RT = TD->getUnderlyingType()->getAs<RecordType>();
+ else if (TypeDecl *TD = dyn_cast<TypeDecl>(FoundDecl))
+ RT = TD->getTypeForDecl()->getAs<RecordType>();
if (!RT)
return true;
Index: test/CodeGen/ms-inline-asm.cpp
===================================================================
--- test/CodeGen/ms-inline-asm.cpp (revision 207920)
+++ test/CodeGen/ms-inline-asm.cpp (working copy)
@@ -1,5 +1,5 @@
// REQUIRES: x86-registered-target
-// RUN: %clang_cc1 -x c++ %s -triple i386-apple-darwin10 -fasm-blocks -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -x c++ %s -triple i386-apple-darwin10 -fasm-blocks -emit-llvm -o - -std=c++11 | FileCheck %s
// rdar://13645930
@@ -111,3 +111,33 @@
jmp a
}
}
+
+void t7_struct() {
+ struct A {
+ int a;
+ int b;
+ };
+ __asm mov eax, [eax].A.b
+ // CHECK-LABEL: define void @_Z9t7_structv
+ // CHECK: call void asm sideeffect inteldialect "mov eax, [eax].4", "~{eax},~{dirflag},~{fpsr},~{flags}"()
+}
+
+void t7_typedef() {
+ typedef struct {
+ int a;
+ int b;
+ } A;
+ __asm mov eax, [eax].A.b
+ // CHECK-LABEL: define void @_Z10t7_typedefv
+ // CHECK: call void asm sideeffect inteldialect "mov eax, [eax].4", "~{eax},~{dirflag},~{fpsr},~{flags}"()
+}
+
+void t7_using() {
+ using A = struct {
+ int a;
+ int b;
+ };
+ __asm mov eax, [eax].A.b
+ // CHECK-LABEL: define void @_Z8t7_usingv
+ // CHECK: call void asm sideeffect inteldialect "mov eax, [eax].4", "~{eax},~{dirflag},~{fpsr},~{flags}"()
+}
More information about the cfe-commits
mailing list