[PATCH] D33277: [Clang][x86][Inline Asm] - Enum support for MS syntax
Matan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 22 09:23:57 PDT 2017
mharoush updated this revision to Diff 99780.
mharoush added a comment.
removed functions and dropped an irrelevant test case.
Repository:
rL LLVM
https://reviews.llvm.org/D33277
Files:
lib/Sema/SemaStmtAsm.cpp
test/CodeGen/x86-ms-inline-asm-enum_feature.cpp
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<clang::EnumType>(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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33277.99780.patch
Type: text/x-patch
Size: 2177 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170522/3efa79b7/attachment.bin>
More information about the llvm-commits
mailing list