Commits

David Schneider committed 09f85e9

Fix for the alignment calculation of anonymous and zero sized bitfields on ARM.

Comments (0)

Files changed (2)

c/_cffi_backend.c

             goto error;
 
         do_align = 1;
+#ifndef __arm__
         if (fbitsize >= 0) {
             if (!(sflags & SF_MSVC_BITFIELDS)) {
                 /* GCC: anonymous bitfields (of any size) don't cause alignment */
                 do_align = fbitsize > 0;
             }
         }
+#endif
         if (alignment < falign && do_align)
             alignment = falign;
 

testing/test_ffi_backend.py

-import py, sys
+import py, sys, platform
+import pytest
 from testing import backend_tests, test_function, test_ownlib
 from cffi import FFI
 import _cffi_backend
         self.check("int a:2; short b:15; char c:2; char y;", 5, 4, 8)
         self.check("int a:2; char b:1; char c:1; char y;", 1, 4, 4)
 
+    @pytest.mark.skipif("platform.machine().startswith('arm')")
     def test_bitfield_anonymous_no_align(self):
         L = FFI().alignof("long long")
         self.check("char y; int :1;", 0, 1, 2)
         self.check("char x; long long z:57; char y;", L + 8, L, L + 8 + L)
         self.check("char x; long long  :57; char y;", L + 8, 1, L + 9)
 
+    @pytest.mark.skipif("not platform.machine().startswith('arm')")
+    def test_bitfield_anonymous_align_arm(self):
+        L = FFI().alignof("long long")
+        self.check("char y; int :1;", 0, 4, 4)
+        self.check("char x; int z:1; char y;", 2, 4, 4)
+        self.check("char x; int  :1; char y;", 2, 4, 4)
+        self.check("char x; long long z:48; char y;", 7, L, 8)
+        self.check("char x; long long  :48; char y;", 7, 8, 8)
+        self.check("char x; long long z:56; char y;", 8, L, 8 + L)
+        self.check("char x; long long  :56; char y;", 8, L, 8 + L)
+        self.check("char x; long long z:57; char y;", L + 8, L, L + 8 + L)
+        self.check("char x; long long  :57; char y;", L + 8, L, L + 8 + L)
+
+    @pytest.mark.skipif("platform.machine().startswith('arm')")
     def test_bitfield_zero(self):
         L = FFI().alignof("long long")
         self.check("char y; int :0;", 0, 1, 4)
         self.check("char x; int :0; short b:1; char y;", 5, 2, 6)
         self.check("int a:1; int :0; int b:1; char y;", 5, 4, 8)
 
+    @pytest.mark.skipif("not platform.machine().startswith('arm')")
+    def test_bitfield_zero_arm(self):
+        L = FFI().alignof("long long")
+        self.check("char y; int :0;", 0, 4, 4)
+        self.check("char x; int :0; char y;", 4, 4, 8)
+        self.check("char x; int :0; int :0; char y;", 4, 4, 8)
+        self.check("char x; long long :0; char y;", L, 8, L + 8)
+        self.check("short x, y; int :0; int :0;", 2, 4, 4)
+        self.check("char x; int :0; short b:1; char y;", 5, 4, 8)
+        self.check("int a:1; int :0; int b:1; char y;", 5, 4, 8)
+
     def test_error_cases(self):
         ffi = FFI()
         py.test.raises(TypeError,