diff options
author | Yonghong Song <yhs@fb.com> | 2019-07-16 17:24:33 +0000 |
---|---|---|
committer | Yonghong Song <yhs@fb.com> | 2019-07-16 17:24:33 +0000 |
commit | 4754814c5a68cf609f83b491feb38ad53c5acd4e (patch) | |
tree | a0fee3d41ecc2d0b0d2fd617734500f59f94f688 /clang/lib/CodeGen/CGExpr.cpp | |
parent | c65a9db43e17f0acdd39b76498d1c23e4a70f9a1 (diff) | |
download | bcm5719-llvm-4754814c5a68cf609f83b491feb38ad53c5acd4e.tar.gz bcm5719-llvm-4754814c5a68cf609f83b491feb38ad53c5acd4e.zip |
fix unnamed fiefield issue and add tests for __builtin_preserve_access_index intrinsic
The original commit is r366076. It is temporarily reverted (r366155)
due to test failure. This resubmit makes test more robust by accepting
regex instead of hardcoded names/references in several places.
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>
llvm-svn: 366231
Diffstat (limited to 'clang/lib/CodeGen/CGExpr.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 4d19a12e5cb..5a4b1188b71 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/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 { |