]> granicus.if.org Git - clang/commitdiff
Do not walk through member-accesses on bitfields when looking for the object
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 3 Jun 2013 07:13:35 +0000 (07:13 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 3 Jun 2013 07:13:35 +0000 (07:13 +0000)
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

lib/AST/Expr.cpp
test/CodeGenCXX/temporaries.cpp

index 2a9b9eb4534e4dcb8bdbc32c28de69d4b7326570..db4269bf163061a19fd02cb3e3ca7668b4228e1a 100644 (file)
@@ -76,9 +76,11 @@ const Expr *Expr::skipRValueSubobjectAdjustments(
       if (!ME->isArrow() && ME->getBase()->isRValue()) {
         assert(ME->getBase()->getType()->isRecordType());
         if (FieldDecl *Field = dyn_cast<FieldDecl>(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<BinaryOperator>(E)) {
index ea87e7f8e384bdeb89470d97abee4adf9f9be7f9..c2adf90ac482ba2edf7ab5e746b81284888aec99 100644 (file)
@@ -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;
+}