Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 7745786

Browse files
committed
Put something sane in the DWARF offset field for bitfield ObjC ivars.
This is useful because unnamed bitfields can have effects on the offsets which are not otherwise reflected in the DWARF information. <rdar://problem/12629719> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167503 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent f616ae2 commit 7745786

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

lib/CodeGen/CGDebugInfo.cpp

+16-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "CodeGenFunction.h"
1616
#include "CodeGenModule.h"
1717
#include "CGBlocks.h"
18+
#include "CGObjCRuntime.h"
1819
#include "clang/AST/ASTContext.h"
1920
#include "clang/AST/DeclFriend.h"
2021
#include "clang/AST/DeclObjC.h"
@@ -1412,12 +1413,21 @@ llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty,
14121413
FieldAlign = CGM.getContext().getTypeAlign(FType);
14131414
}
14141415

1415-
// We can't know the offset of our ivar in the structure if we're using
1416-
// the non-fragile abi and the debugger should ignore the value anyways.
1417-
// Call it the FieldNo+1 due to how debuggers use the information,
1418-
// e.g. negating the value when it needs a lookup in the dynamic table.
1419-
uint64_t FieldOffset = CGM.getLangOpts().ObjCRuntime.isNonFragile()
1420-
? FieldNo+1 : RL.getFieldOffset(FieldNo);
1416+
uint64_t FieldOffset;
1417+
if (CGM.getLangOpts().ObjCRuntime.isNonFragile()) {
1418+
// We don't know the runtime offset of an ivar if we're using the
1419+
// non-fragile ABI. For bitfields, use the bit offset into the first
1420+
// byte of storage of the bitfield. For other fields, use zero.
1421+
if (Field->isBitField()) {
1422+
FieldOffset = CGM.getObjCRuntime().ComputeBitfieldBitOffset(
1423+
CGM, ID, Field);
1424+
FieldOffset %= CGM.getContext().getCharWidth();
1425+
} else {
1426+
FieldOffset = 0;
1427+
}
1428+
} else {
1429+
FieldOffset = RL.getFieldOffset(FieldNo);
1430+
}
14211431

14221432
unsigned Flags = 0;
14231433
if (Field->getAccessControl() == ObjCIvarDecl::Protected)

lib/CodeGen/CGObjCRuntime.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ uint64_t CGObjCRuntime::ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
7878
CGM.getContext().getCharWidth();
7979
}
8080

81+
unsigned CGObjCRuntime::ComputeBitfieldBitOffset(
82+
CodeGen::CodeGenModule &CGM,
83+
const ObjCInterfaceDecl *ID,
84+
const ObjCIvarDecl *Ivar) {
85+
return LookupFieldBitOffset(CGM, ID, ID->getImplementation(), Ivar);
86+
}
87+
8188
LValue CGObjCRuntime::EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF,
8289
const ObjCInterfaceDecl *OID,
8390
llvm::Value *BaseValue,

lib/CodeGen/CGObjCRuntime.h

+6
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ class CGObjCRuntime {
277277
MessageSendInfo getMessageSendInfo(const ObjCMethodDecl *method,
278278
QualType resultType,
279279
CallArgList &callArgs);
280+
281+
// FIXME: This probably shouldn't be here, but the code to compute
282+
// it is here.
283+
unsigned ComputeBitfieldBitOffset(CodeGen::CodeGenModule &CGM,
284+
const ObjCInterfaceDecl *ID,
285+
const ObjCIvarDecl *Ivar);
280286
};
281287

282288
/// Creates an instance of an Objective-C runtime class.

test/CodeGenObjC/debug-info-ivars.m

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -g %s -o - | FileCheck %s
2+
3+
__attribute((objc_root_class)) @interface NSObject {
4+
id isa;
5+
}
6+
@end
7+
8+
@interface BaseClass : NSObject
9+
{
10+
int i;
11+
unsigned flag_1 : 9;
12+
unsigned flag_2 : 9;
13+
unsigned : 1;
14+
unsigned flag_3 : 9;
15+
}
16+
@end
17+
18+
@implementation BaseClass
19+
@end
20+
21+
// CHECK: metadata !{i32 786445, metadata !{{[0-9]*}}, metadata !"i", metadata !{{[0-9]*}}, i32 10, i64 32, i64 32, i64 0, i32 2, metadata !{{[0-9]*}}, null} ; [ DW_TAG_member ] [i] [line 10, size 32, align 32, offset 0] [protected] [from int]
22+
// CHECK: metadata !{i32 786445, metadata !{{[0-9]*}}, metadata !"flag_1", metadata !{{[0-9]*}}, i32 11, i64 9, i64 32, i64 0, i32 2, metadata !{{[0-9]*}}, null} ; [ DW_TAG_member ] [flag_1] [line 11, size 9, align 32, offset 0] [protected] [from unsigned int]
23+
// CHECK: metadata !{i32 786445, metadata !{{[0-9]*}}, metadata !"flag_2", metadata !{{[0-9]*}}, i32 12, i64 9, i64 32, i64 1, i32 2, metadata !{{[0-9]*}}, null} ; [ DW_TAG_member ] [flag_2] [line 12, size 9, align 32, offset 1] [protected] [from unsigned int]
24+
// CHECK: metadata !{i32 786445, metadata !{{[0-9]*}}, metadata !"flag_3", metadata !{{[0-9]*}}, i32 14, i64 9, i64 32, i64 3, i32 2, metadata !{{[0-9]*}}, null} ; [ DW_TAG_member ] [flag_3] [line 14, size 9, align 32, offset 3] [protected] [from unsigned int]

0 commit comments

Comments
 (0)