From: Richard Smith Date: Mon, 3 Jun 2013 07:13:35 +0000 (+0000) Subject: Do not walk through member-accesses on bitfields when looking for the object X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d1b55dcf6bd61d4350b01e15590bde9bb5a334bb;p=clang Do not walk through member-accesses on bitfields when looking for the object which is lifetime-extended by a reference binding. An additional temporary is created for such a bitfield access (although we have no explicit AST representation for it). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183095 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 2a9b9eb453..db4269bf16 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -76,9 +76,11 @@ const Expr *Expr::skipRValueSubobjectAdjustments( if (!ME->isArrow() && ME->getBase()->isRValue()) { assert(ME->getBase()->getType()->isRecordType()); if (FieldDecl *Field = dyn_cast(ME->getMemberDecl())) { - E = ME->getBase(); - Adjustments.push_back(SubobjectAdjustment(Field)); - continue; + if (!Field->isBitField()) { + E = ME->getBase(); + Adjustments.push_back(SubobjectAdjustment(Field)); + continue; + } } } } else if (const BinaryOperator *BO = dyn_cast(E)) { diff --git a/test/CodeGenCXX/temporaries.cpp b/test/CodeGenCXX/temporaries.cpp index ea87e7f8e3..c2adf90ac4 100644 --- a/test/CodeGenCXX/temporaries.cpp +++ b/test/CodeGenCXX/temporaries.cpp @@ -604,3 +604,15 @@ namespace BindToSubobject { // CHECK: store i32* {{.*}}, i32** @_ZN15BindToSubobject1dE, align 8 int &&d = (B().a).*h(); } + +namespace Bitfield { + struct S { int a : 5; ~S(); }; + + // Do not lifetime extend the S() temporary here. +  // CHECK: alloca +  // CHECK: call {{.*}}memset +  // CHECK: store i32 {{.*}}, i32* @_ZGRN8Bitfield1rE, align 4 + // CHECK: call void @_ZN8Bitfield1SD1 +  // CHECK: store i32* @_ZGRN8Bitfield1rE, i32** @_ZN8Bitfield1rE, align 8 + int &&r = S().a; +}