This is an archive of the discontinued LLVM Phabricator instance.

CodeGen: Let arrays be inputs to inline asm
ClosedPublic

Authored by majnemer on Jul 4 2014, 1:07 AM.

Details

Summary

An array showing up in an inline assembly input is accepted in ICC and
GCC 4.8

This fixes PR20201.

Diff Detail

Repository
rL LLVM

Event Timeline

majnemer updated this revision to Diff 11077.Jul 4 2014, 1:07 AM
majnemer retitled this revision from to CodeGen: Let arrays be inputs to inline asm.
majnemer updated this object.
majnemer added reviewers: rsmith, rnk.
majnemer added a subscriber: Unknown Object (MLST).
rsmith edited edge metadata.Jul 7 2014, 4:31 PM

2014-07-04 1:07 GMT-07:00 David Majnemer <david.majnemer@gmail.com>:

Hi rsmith, rnk,

An array showing up in an inline assembly input is accepted in ICC and
GCC 4.8

This fixes PR20201.

http://reviews.llvm.org/D4382

Files:

lib/CodeGen/CGExpr.cpp
test/CodeGen/asm.c
test/CodeGen/x86-64-inline-asm.c

Index: lib/CodeGen/CGExpr.cpp

  • lib/CodeGen/CGExpr.cpp

+++ lib/CodeGen/CGExpr.cpp
@@ -2781,7 +2781,6 @@

switch (E->getCastKind()) {
case CK_ToVoid:
case CK_BitCast:
  • case CK_ArrayToPointerDecay:

As discussed in person, I think this is addressing the symptom rather than
the cause. A memory operand expects an lvalue, and we're incorrectly
performing an lvalue-to-rvalue conversion on it in Sema.

case CK_FunctionToPointerDecay:
case CK_NullToMemberPointer:
case CK_NullToPointer:

@@ -2836,6 +2835,7 @@

  return MakeAddrLValue(EmitDynamicCast(V, DCE), E->getType());
}

+ case CK_ArrayToPointerDecay:

case CK_ConstructorConversion:
case CK_UserDefinedConversion:
case CK_CPointerToObjCPointerCast:

Index: test/CodeGen/asm.c

  • test/CodeGen/asm.c

+++ test/CodeGen/asm.c
@@ -239,3 +239,12 @@
// CHECK: call void asm sideeffect "/* $0 */",
"i|r,~{dirflag},~{fpsr},~{flags}"(i32 1)
}

+static unsigned t29_var[1];
+
+void t29(void) {
+ asm volatile("movl %%eax, %0"
+ :
+ : "m"(t29_var));
+ CHECK: @t29
+
CHECK: call void asm sideeffect "movl %eax, $0",
"*m,~{dirflag},~{fpsr},~{flags}"([1 x i32]* @t29_var)
+}

Index: test/CodeGen/x86-64-inline-asm.c

  • test/CodeGen/x86-64-inline-asm.c

+++ test/CodeGen/x86-64-inline-asm.c
@@ -10,3 +10,8 @@
// expected-error@-5 {{scale factor without index register is ignored}}
#endif
}
+
+static unsigned var[1] = {};
+void g(void) { asm volatile("movd %%xmm0, %0"
+ :
+ : "m"(var)); }

majnemer updated this revision to Diff 11129.Jul 7 2014, 4:37 PM
majnemer edited edge metadata.
  • This is a Sema bug, not a CodeGen bug.
majnemer updated this revision to Diff 11134.Jul 7 2014, 4:56 PM
  • Remove changes from CodeGen.
rnk accepted this revision.Jul 8 2014, 2:31 PM
rnk edited edge metadata.

lgtm, but please wait for http://crbug.com/391927 in libyuv to be resolved.

This revision is now accepted and ready to land.Jul 8 2014, 2:31 PM
rnk added a comment.Jul 11 2014, 11:44 AM

Looks like we can land this now.

majnemer closed this revision.Jul 14 2014, 9:36 AM
majnemer updated this revision to Diff 11389.

Closed by commit rL212954 (authored by @majnemer).