[cfe-commits] r67499 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/2009-03-22-increment-bitfield.c
Eli Friedman
eli.friedman at gmail.com
Sun Mar 22 20:00:06 PDT 2009
Author: efriedma
Date: Sun Mar 22 22:00:06 2009
New Revision: 67499
URL: http://llvm.org/viewvc/llvm-project?rev=67499&view=rev
Log:
Fix a subtle bug in CodeGen for the increment of a bitfield.
Added:
cfe/trunk/test/CodeGen/2009-03-22-increment-bitfield.c
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=67499&r1=67498&r2=67499&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Sun Mar 22 22:00:06 2009
@@ -620,9 +620,8 @@
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 @@
}
// 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.
Added: cfe/trunk/test/CodeGen/2009-03-22-increment-bitfield.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/2009-03-22-increment-bitfield.c?rev=67499&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/2009-03-22-increment-bitfield.c (added)
+++ cfe/trunk/test/CodeGen/2009-03-22-increment-bitfield.c Sun Mar 22 22:00:06 2009
@@ -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;
+}
+
+
More information about the cfe-commits
mailing list