]> granicus.if.org Git - clang/commitdiff
Fix a subtle bug in CodeGen for the increment of a bitfield.
authorEli Friedman <eli.friedman@gmail.com>
Mon, 23 Mar 2009 03:00:06 +0000 (03:00 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Mon, 23 Mar 2009 03:00:06 +0000 (03:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67499 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprScalar.cpp
test/CodeGen/2009-03-22-increment-bitfield.c [new file with mode: 0644]

index 80aa755e189794fa531e0bc0d97c470f61fb112e..89f28bea6d3418731023d684a9e8d300c065123d 100644 (file)
@@ -620,9 +620,8 @@ Value *ScalarExprEmitter::VisitBlockDeclRefExpr(const BlockDeclRefExpr *E) {
 Value *ScalarExprEmitter::VisitPrePostIncDec(const UnaryOperator *E,
                                              bool isInc, bool isPre) {
   LValue LV = EmitLValue(E->getSubExpr());
-  // FIXME: Handle volatile!
-  Value *InVal = CGF.EmitLoadOfLValue(LV, // false
-                                     E->getSubExpr()->getType()).getScalarVal();
+  QualType ValTy = E->getSubExpr()->getType();
+  Value *InVal = CGF.EmitLoadOfLValue(LV, ValTy).getScalarVal();
   
   int AmountVal = isInc ? 1 : -1;
   
@@ -667,8 +666,11 @@ Value *ScalarExprEmitter::VisitPrePostIncDec(const UnaryOperator *E,
   }
   
   // Store the updated result through the lvalue.
-  CGF.EmitStoreThroughLValue(RValue::get(NextVal), LV, 
-                             E->getSubExpr()->getType());
+  if (LV.isBitfield())
+    CGF.EmitStoreThroughBitfieldLValue(RValue::get(NextVal), LV, ValTy,
+                                       &NextVal);
+  else
+    CGF.EmitStoreThroughLValue(RValue::get(NextVal), LV, ValTy);
 
   // If this is a postinc, return the value read from memory, otherwise use the
   // updated value.
diff --git a/test/CodeGen/2009-03-22-increment-bitfield.c b/test/CodeGen/2009-03-22-increment-bitfield.c
new file mode 100644 (file)
index 0000000..7a18cea
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: clang -emit-llvm -O1 < %s | grep "ret i32 0"
+
+int a(void) {
+  return ++(struct x {unsigned x : 2;}){3}.x;
+}
+
+