Handle packed structs in the CBackend.
authorLauro Ramos Venancio <lauro.venancio@gmail.com>
Wed, 11 Jul 2007 19:56:53 +0000 (19:56 +0000)
committerLauro Ramos Venancio <lauro.venancio@gmail.com>
Wed, 11 Jul 2007 19:56:53 +0000 (19:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@39752 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/CBackend/CBackend.cpp
test/CodeGen/CBackend/2007-07-11-PackedStruct.ll [new file with mode: 0644]

index 91f427fa2cb5af3ca9baa93f211c982d078b5030..b0c76c8e8e71b35c77087ebdc94be02d58958f24 100644 (file)
@@ -466,7 +466,10 @@ std::ostream &CWriter::printType(std::ostream &Out, const Type *Ty,
       printType(Out, *I, false, "field" + utostr(Idx++));
       Out << ";\n";
     }
-    return Out << '}';
+    Out << '}';
+    if (STy->isPacked())
+      Out << " __attribute__ ((packed))";
+    return Out;
   }
 
   case Type::PointerTyID: {
diff --git a/test/CodeGen/CBackend/2007-07-11-PackedStruct.ll b/test/CodeGen/CBackend/2007-07-11-PackedStruct.ll
new file mode 100644 (file)
index 0000000..6057616
--- /dev/null
@@ -0,0 +1,9 @@
+; RUN: llvm-as < %s | llc -march=c | grep {packed}
+
+       %struct.p = type <{ i16 }>
+
+define i32 @main() {
+entry:
+        %t = alloca %struct.p, align 2
+       ret i32 5
+}