<div dir="ltr">FTR, this was reverted in r309004.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jul 25, 2017 at 12:43 PM, Matan Haroush via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: mharoush<br>
Date: Tue Jul 25 03:43:43 2017<br>
New Revision: 308965<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=308965&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=308965&view=rev</a><br>
Log:<br>
This patch enables the usage of constant Enum identifiers within Microsoft style inline assembly statements.<br>
<br>
Differential Revision:<br>
<a href="https://reviews.llvm.org/D33277" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D33277</a><br>
<a href="https://reviews.llvm.org/D33278" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D33278</a><br>
<br>
<br>
Added:<br>
cfe/trunk/test/CodeGen/x86-ms-<wbr>inline-asm-enum_feature.cpp<br>
Modified:<br>
cfe/trunk/lib/Sema/<wbr>SemaStmtAsm.cpp<br>
cfe/trunk/test/CodeGen/ms-<wbr>inline-asm.c<br>
cfe/trunk/test/CodeGenCXX/ms-<wbr>inline-asm-return.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/<wbr>SemaStmtAsm.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=308965&r1=308964&r2=308965&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaStmtAsm.cpp?rev=308965&r1=<wbr>308964&r2=308965&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/<wbr>SemaStmtAsm.cpp (original)<br>
+++ cfe/trunk/lib/Sema/<wbr>SemaStmtAsm.cpp Tue Jul 25 03:43:43 2017<br>
@@ -645,8 +645,8 @@ ExprResult Sema::LookupInlineAsmIdentifi<br>
// Referring to parameters is not allowed in naked functions.<br>
if (CheckNakedParmReference(<wbr>Result.get(), *this))<br>
return ExprError();<br>
-<br>
- QualType T = Result.get()->getType();<br>
+ Expr *Res = Result.get();<br>
+ QualType T = Res->getType();<br>
<br>
if (T->isDependentType()) {<br>
return Result;<br>
@@ -658,16 +658,26 @@ ExprResult Sema::LookupInlineAsmIdentifi<br>
}<br>
<br>
// Otherwise, it needs to be a complete type.<br>
- if (RequireCompleteExprType(<wbr>Result.get(), diag::err_asm_incomplete_type)<wbr>) {<br>
+ if (RequireCompleteExprType(Res, diag::err_asm_incomplete_type)<wbr>) {<br>
return ExprError();<br>
}<br>
<br>
fillInlineAsmTypeInfo(Context, T, Info);<br>
<br>
// We can work with the expression as long as it's not an r-value.<br>
- if (!Result.get()->isRValue())<br>
- Info.IsVarDecl = true;<br>
+ if (!Res->isRValue()) {<br>
+ Info.setKindVariable();<br>
+ return Result;<br>
+ }<br>
<br>
+ Expr::EvalResult EvlResult;<br>
+ // Try to evaluate the identifier as enum constant, currently we do not allow<br>
+ // other constant integers to be folded.<br>
+ if (isa<clang::EnumType>(T) &&<br>
+ Res->EvaluateAsRValue(<wbr>EvlResult, getASTContext())) {<br>
+ Info.ConstIntValue = EvlResult.Val.getInt();<br>
+ Info.setKindConstEnum();<br>
+ }<br>
return Result;<br>
}<br>
<br>
@@ -774,7 +784,7 @@ Sema::<wbr>LookupInlineAsmVarDeclField(<wbr>Expr *<br>
fillInlineAsmTypeInfo(Context, Result.get()->getType(), Info);<br>
<br>
// Fields are "variables" as far as inline assembly is concerned.<br>
- Info.IsVarDecl = true;<br>
+ Info.setKindVariable();<br>
<br>
return Result;<br>
}<br>
<br>
Modified: cfe/trunk/test/CodeGen/ms-<wbr>inline-asm.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms-inline-asm.c?rev=308965&r1=308964&r2=308965&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/<wbr>CodeGen/ms-inline-asm.c?rev=<wbr>308965&r1=308964&r2=308965&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/CodeGen/ms-<wbr>inline-asm.c (original)<br>
+++ cfe/trunk/test/CodeGen/ms-<wbr>inline-asm.c Tue Jul 25 03:43:43 2017<br>
@@ -42,7 +42,7 @@ void t5(void) {<br>
void t6(void) {<br>
__asm int 0x2c<br>
// CHECK: t6<br>
-// CHECK: call void asm sideeffect inteldialect "int $$0x2c", "~{dirflag},~{fpsr},~{flags}"(<wbr>)<br>
+// CHECK: call void asm sideeffect inteldialect "int $$44", "~{dirflag},~{fpsr},~{flags}"(<wbr>)<br>
}<br>
<br>
void t7() {<br>
@@ -61,7 +61,7 @@ void t7() {<br>
mov eax, ebx<br>
}<br>
// CHECK: t7<br>
-// CHECK: call void asm sideeffect inteldialect "int $$0x2cU", "~{dirflag},~{fpsr},~{flags}"(<wbr>)<br>
+// CHECK: call void asm sideeffect inteldialect "int $$44", "~{dirflag},~{fpsr},~{flags}"(<wbr>)<br>
// CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"(<wbr>)<br>
// CHECK: call void asm sideeffect inteldialect "mov eax, ebx", "~{eax},~{dirflag},~{fpsr},~{<wbr>flags}"()<br>
}<br>
@@ -94,7 +94,7 @@ void t9() {<br>
// CHECK: t9<br>
// CHECK: call void asm sideeffect inteldialect<br>
// CHECK-SAME: push ebx<br>
-// CHECK-SAME: mov ebx, $$0x07<br>
+// CHECK-SAME: mov ebx, $$7<br>
// CHECK-SAME: pop ebx<br>
// CHECK-SAME: "~{ebx},~{esp},~{dirflag},~{<wbr>fpsr},~{flags}"()<br>
}<br>
@@ -265,7 +265,7 @@ void t21() {<br>
// CHECK: t21<br>
// CHECK: call void asm sideeffect inteldialect<br>
// CHECK-SAME: push ebx<br>
-// CHECK-SAME: mov ebx, $$07H<br>
+// CHECK-SAME: mov ebx, $$7<br>
// CHECK-SAME: pop ebx<br>
// CHECK-SAME: "~{ebx},~{esp},~{dirflag},~{<wbr>fpsr},~{flags}"()<br>
}<br>
@@ -312,13 +312,13 @@ void t24() {<br>
void t25() {<br>
// CHECK: t25<br>
__asm mov eax, 0ffffffffh<br>
-// CHECK: mov eax, $$0ffffffffh<br>
+// CHECK: mov eax, $$4294967295<br>
__asm mov eax, 0fhU<br>
// CHECK: mov eax, $$15<br>
__asm mov eax, 0a2h<br>
-// CHECK: mov eax, $$0a2h<br>
+// CHECK: mov eax, $$162<br>
__asm mov eax, 10100010b<br>
-// CHECK: mov eax, $$10100010b<br>
+// CHECK: mov eax, $$162<br>
__asm mov eax, 10100010BU<br>
// CHECK: mov eax, $$162<br>
// CHECK: "~{eax},~{dirflag},~{fpsr},~{<wbr>flags}"()<br>
<br>
Added: cfe/trunk/test/CodeGen/x86-ms-<wbr>inline-asm-enum_feature.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/x86-ms-inline-asm-enum_feature.cpp?rev=308965&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/<wbr>CodeGen/x86-ms-inline-asm-<wbr>enum_feature.cpp?rev=308965&<wbr>view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/CodeGen/x86-ms-<wbr>inline-asm-enum_feature.cpp (added)<br>
+++ cfe/trunk/test/CodeGen/x86-ms-<wbr>inline-asm-enum_feature.cpp Tue Jul 25 03:43:43 2017<br>
@@ -0,0 +1,60 @@<br>
+// REQUIRES: x86-registered-target<br>
+// RUN: %clang_cc1 %s -fasm-blocks -emit-llvm -o - | FileCHECK %s<br>
+namespace x {<br>
+enum { A = 12 };<br>
+struct y_t {<br>
+ enum { A = 17 };<br>
+ int r;<br>
+} y;<br>
+}<br>
+// CHECK-LABEL: x86_enum_only<br>
+void x86_enum_only(){<br>
+ const int a = 0;<br>
+ // CHECK-NOT: mov eax, [$$0]<br>
+ // Other constant type folding is currently unwanted.<br>
+ __asm mov eax, [a]<br>
+ }<br>
+<br>
+// CHECK-LABEL: x86_enum_namespaces<br>
+void x86_enum_namespaces() {<br>
+ enum { A = 1 };<br>
+ // CHECK: call void asm<br>
+ // CHECK-SAME: mov eax, $$12<br>
+ __asm mov eax, x::A<br>
+ // CHECK-SAME: mov eax, $$17<br>
+ __asm mov eax, x::y_t::A<br>
+ // CHECK-NEXT: call void asm<br>
+ // CHECK-SAME: mov eax, $$1<br>
+ __asm {mov eax, A}<br>
+}<br>
+<br>
+// CHECK-LABEL: x86_enum_arithmethic<br>
+void x86_enum_arithmethic() {<br>
+ enum { A = 1, B };<br>
+ // CHECK: call void asm<br>
+ // CHECK-SAME: mov eax, $$21<br>
+ __asm mov eax, (A + 9) * 2 + A<br>
+ // CHECK-SAME: mov eax, $$4<br>
+ __asm mov eax, A << 2<br>
+ // CHECK-SAME: mov eax, $$2<br>
+ __asm mov eax, B & 3<br>
+ // CHECK-SAME: mov eax, $$5<br>
+ __asm mov eax, 3 + (B & 3)<br>
+ // CHECK-SAME: mov eax, $$8<br>
+ __asm mov eax, 2 << A * B<br>
+}<br>
+<br>
+// CHECK-LABEL: x86_enum_mem<br>
+void x86_enum_mem() {<br>
+ int arr[4];<br>
+ enum { A = 4, B };<br>
+ // CHECK: call void asm<br>
+ // CHECK-SAME: mov eax, [($$12 + $$9) + $$4 * $$5 + $$3 + $$3 + eax]<br>
+ __asm { mov eax, [(x::A + 9) + A * B + 3 + 3 + eax] }<br>
+ // CHECK-NEXT: call void asm<br>
+ // CHECK-SAME: mov eax, dword ptr $$4$0<br>
+ __asm { mov eax, dword ptr [arr + A] }<br>
+ // CHECK-NEXT: call void asm<br>
+ // CHECK-SAME: mov eax, dword ptr $$8$0<br>
+ __asm { mov eax, dword ptr A[arr + A] }<br>
+}<br>
<br>
Modified: cfe/trunk/test/CodeGenCXX/ms-<wbr>inline-asm-return.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ms-inline-asm-return.cpp?rev=308965&r1=308964&r2=308965&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/<wbr>CodeGenCXX/ms-inline-asm-<wbr>return.cpp?rev=308965&r1=<wbr>308964&r2=308965&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/CodeGenCXX/ms-<wbr>inline-asm-return.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/ms-<wbr>inline-asm-return.cpp Tue Jul 25 03:43:43 2017<br>
@@ -70,7 +70,7 @@ FourChars f_s4() {<br>
}<br>
}<br>
// CHECK-LABEL: define i32 @f_s4()<br>
-// CHECK: %[[r:[^ ]*]] = call i32 asm sideeffect inteldialect "mov eax, $$0x01010101", "={eax},~{eax},{{.*}}"<br>
+// CHECK: %[[r:[^ ]*]] = call i32 asm sideeffect inteldialect "mov eax, $$16843009", "={eax},~{eax},{{.*}}"<br>
// CHECK: store i32 %[[r]], i32* %{{.*}}<br>
// CHECK: %[[r_i32:[^ ]*]] = load i32, i32* %{{.*}}<br>
// CHECK: ret i32 %[[r_i32]]<br>
@@ -85,7 +85,7 @@ EightChars f_s8() {<br>
}<br>
}<br>
// CHECK-LABEL: define i64 @f_s8()<br>
-// CHECK: %[[r:[^ ]*]] = call i64 asm sideeffect inteldialect "mov eax, $$01010101h\0A\09mov edx, $$01010101b", "=A,~{eax},{{.*}}"<br>
+// CHECK: %[[r:[^ ]*]] = call i64 asm sideeffect inteldialect "mov eax, $$16843009\0A\09mov edx, $$85", "=A,~{eax},{{.*}}"<br>
// CHECK: store i64 %[[r]], i64* %{{.*}}<br>
// CHECK: %[[r_i64:[^ ]*]] = load i64, i64* %{{.*}}<br>
// CHECK: ret i64 %[[r_i64]]<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>