[PATCH] D51990: [DebugInfo] Fix emitting of bit offset for ObjC

Jonas Devlieghere via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 12 08:12:04 PDT 2018


JDevlieghere created this revision.
JDevlieghere added reviewers: aprantl, dexonsmith.

We generate incorrect values for the DW_AT_data_bit_offset for interfaces in Objective-C. I can only speculate as to what we were trying to achieve by taking the modulo of the bit size with the byte size, but given that the size and offset is expressed in bits, this seems wrong.


Repository:
  rC Clang

https://reviews.llvm.org/D51990

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenObjC/debug-info-ivars.m


Index: clang/test/CodeGenObjC/debug-info-ivars.m
===================================================================
--- clang/test/CodeGenObjC/debug-info-ivars.m
+++ clang/test/CodeGenObjC/debug-info-ivars.m
@@ -15,30 +15,29 @@
 }
 @end
 
- at implementation BaseClass
- at end
+    @implementation BaseClass
+    @end
 
-// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "i"
-// CHECK-SAME:           line: 10
-// CHECK-SAME:           baseType: ![[INT:[0-9]+]]
-// CHECK-SAME:           size: 32,
-// CHECK-NOT:            offset:
-// CHECK-SAME:           flags: DIFlagProtected
-// CHECK: ![[INT]] = !DIBasicType(name: "int"
-// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_1"
-// CHECK-SAME:           line: 11
-// CHECK-SAME:           baseType: ![[UNSIGNED:[0-9]+]]
-// CHECK-SAME:           size: 9,
-// CHECK-NOT:            offset:
-// CHECK-SAME:           flags: DIFlagProtected
-// CHECK: ![[UNSIGNED]] = !DIBasicType(name: "unsigned int"
-// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_2"
-// CHECK-SAME:           line: 12
-// CHECK-SAME:           baseType: ![[UNSIGNED]]
-// CHECK-SAME:           size: 9, offset: 1,
-// CHECK-SAME:           flags: DIFlagProtected
-// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_3"
-// CHECK-SAME:           line: 14
-// CHECK-SAME:           baseType: ![[UNSIGNED]]
-// CHECK-SAME:           size: 9, offset: 3,
-// CHECK-SAME:           flags: DIFlagProtected
+    // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "i"
+    // CHECK-SAME:           line: 10
+    // CHECK-SAME:           baseType: ![[INT:[0-9]+]]
+    // CHECK-SAME:           size: 32,
+    // CHECK-NOT:            offset:
+    // CHECK-SAME:           flags: DIFlagProtected
+    // CHECK: ![[INT]] = !DIBasicType(name: "int"
+    // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_1"
+    // CHECK-SAME:           line: 11
+    // CHECK-SAME:           baseType: ![[UNSIGNED:[0-9]+]]
+    // CHECK-SAME:           size: 9, offset: 96
+    // CHECK-SAME:           flags: DIFlagProtected
+    // CHECK: ![[UNSIGNED]] = !DIBasicType(name: "unsigned int"
+    // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_2"
+    // CHECK-SAME:           line: 12
+    // CHECK-SAME:           baseType: ![[UNSIGNED]]
+    // CHECK-SAME:           size: 9, offset: 105
+    // CHECK-SAME:           flags: DIFlagProtected
+    // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_3"
+    // CHECK-SAME:           line: 14
+    // CHECK-SAME:           baseType: ![[UNSIGNED]]
+    // CHECK-SAME:           size: 9, offset: 115
+    // CHECK-SAME:           flags: DIFlagProtected
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2363,13 +2363,10 @@
       // We don't know the runtime offset of an ivar if we're using the
       // non-fragile ABI.  For bitfields, use the bit offset into the first
       // byte of storage of the bitfield.  For other fields, use zero.
-      if (Field->isBitField()) {
-        FieldOffset =
-            CGM.getObjCRuntime().ComputeBitfieldBitOffset(CGM, ID, Field);
-        FieldOffset %= CGM.getContext().getCharWidth();
-      } else {
-        FieldOffset = 0;
-      }
+      FieldOffset =
+          Field->isBitField()
+              ? CGM.getObjCRuntime().ComputeBitfieldBitOffset(CGM, ID, Field)
+              : 0;
     } else {
       FieldOffset = RL.getFieldOffset(FieldNo);
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51990.165093.patch
Type: text/x-patch
Size: 3526 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180912/405e34e3/attachment.bin>


More information about the cfe-commits mailing list