summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExpr.cpp
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2019-07-15 15:42:41 +0000
committerYonghong Song <yhs@fb.com>2019-07-15 15:42:41 +0000
commit2a9412eebe35a77d52638843d4a5a8ef480bc5d8 (patch)
tree62e86124196440c3b02b28842ce3a0a0d9b9fb3a /lib/CodeGen/CGExpr.cpp
parentb946da5a6054247c34fe82f075f4c3a143445026 (diff)
downloadclang-2a9412eebe35a77d52638843d4a5a8ef480bc5d8.tar.gz
fix unnamed fiefield issue and add tests for __builtin_preserve_access_index intrinsic
This is a followup patch for https://reviews.llvm.org/D61809. Handle unnamed bitfield properly and add more test cases. Fixed the unnamed bitfield issue. The unnamed bitfield is ignored by debug info, so we need to ignore such a struct/union member when we try to get the member index in the debug info. D61809 contains two test cases but not enough as it does not checking generated IRs in the fine grain level, and also it does not have semantics checking tests. This patch added unit tests for both code gen and semantics checking for the new intrinsic. Signed-off-by: Yonghong Song <yhs@fb.com> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@366076 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
-rw-r--r--lib/CodeGen/CGExpr.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 62d930ca8c..25d2424eb8 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -3892,6 +3892,23 @@ LValue CodeGenFunction::EmitLValueForLambdaField(const FieldDecl *Field) {
return EmitLValueForField(LambdaLV, Field);
}
+/// Get the field index in the debug info. The debug info structure/union
+/// will ignore the unnamed bitfields.
+unsigned CodeGenFunction::getDebugInfoFIndex(const RecordDecl *Rec,
+ unsigned FieldIndex) {
+ unsigned I = 0, Skipped = 0;
+
+ for (auto F : Rec->getDefinition()->fields()) {
+ if (I == FieldIndex)
+ break;
+ if (F->isUnnamedBitfield())
+ Skipped++;
+ I++;
+ }
+
+ return FieldIndex - Skipped;
+}
+
/// Get the address of a zero-sized field within a record. The resulting
/// address doesn't necessarily have the right type.
static Address emitAddrOfZeroSizeField(CodeGenFunction &CGF, Address Base,
@@ -3931,7 +3948,7 @@ static Address emitPreserveStructAccess(CodeGenFunction &CGF, Address base,
CGF.CGM.getTypes().getCGRecordLayout(rec).getLLVMFieldNo(field);
return CGF.Builder.CreatePreserveStructAccessIndex(
- base, idx, field->getFieldIndex(), DbgInfo);
+ base, idx, CGF.getDebugInfoFIndex(rec, field->getFieldIndex()), DbgInfo);
}
static bool hasAnyVptr(const QualType Type, const ASTContext &Context) {
@@ -4048,7 +4065,7 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
getContext().getRecordType(rec), rec->getLocation());
addr = Address(
Builder.CreatePreserveUnionAccessIndex(
- addr.getPointer(), field->getFieldIndex(), DbgInfo),
+ addr.getPointer(), getDebugInfoFIndex(rec, field->getFieldIndex()), DbgInfo),
addr.getAlignment());
}
} else {