mharoush updated this revision to Diff 102172.
mharoush marked 6 inline comments as done.
mharoush added a comment.
Restored old test case for constant int folding and added check-label
directives for each tester function.
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
@@ -644,8 +644,8 @@
// Referring to parameters is not allowed in naked functions.
if (CheckNakedParmReference(Result.get(), *this))
return ExprError();
-
- QualType T = Result.get()->getType();
+ Expr *Res = Result.get();
+ QualType T = Res->getType();
if (T->isDependentType()) {
return Result;
@@ -657,16 +657,26 @@
}
// Otherwise, it needs to be a complete type.
- if (RequireCompleteExprType(Result.get(), diag::err_asm_incomplete_type)) {
+ if (RequireCompleteExprType(Res, diag::err_asm_incomplete_type)) {
return ExprError();
}
fillInlineAsmTypeInfo(Context, T, Info);
// We can work with the expression as long as it's not an r-value.
- if (!Result.get()->isRValue())
- Info.IsVarDecl = true;
+ if (!Res->isRValue()) {
+ Info.setKindVariable();
+ return Result;
+ }
+ Expr::EvalResult EvlResult;
+ // Try to evaluate the identifier as enum constant, currently we do not allow
+ // other constant integers to be folded.
+ if (isa<clang::EnumType>(T) &&
+ Res->EvaluateAsRValue(EvlResult, getASTContext())) {
+ Info.ConstIntValue = EvlResult.Val.getInt();
+ Info.setKindConstEnum();
+ }
return Result;
}
@@ -773,7 +783,7 @@
fillInlineAsmTypeInfo(Context, Result.get()->getType(), Info);
// Fields are "variables" as far as inline assembly is concerned.
- Info.IsVarDecl = true;
+ Info.setKindVariable();
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,55 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 %s -fasm-blocks -emit-llvm -o - | FileCHECK %s
+namespace x {
+enum { A = 12 };
+struct y_t {
+ enum { A = 17 };
+ int r;
+} y;
+}
+// CHECK-LABEL: x86_enum_only
+void x86_enum_only(){
+ const int a = 0;
+ // CHECK-NOT: mov eax, [$$0]
+ // Other constant type folding is currently unwanted.
+ __asm mov eax, [a]
+ }
+
+// CHECK-LABEL: x86_enum_namespaces
+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_t::A
+ // CHECK: mov eax, $$1
+ __asm {mov eax, A}
+}
+
+// CHECK-LABEL: x86_enum_arithmethic
+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
+}
+
+// CHECK-LABEL: x86_enum_mem
+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] }
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits