aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-05-20 01:24:22 +0000
committerAnders Carlsson <andersca@mac.com>2009-05-20 01:24:22 +0000
commit38d068e8f13a119b89a3b8b0f79f35cab1ffd09a (patch)
treea2cbc5d81446fe5bbb28d0137f2fc8894388eece
parente04d1c77ae15a6e973e2fac7723f6c364884f58d (diff)
Create a temporary if the lvalue is a bitfield. Reported by Eli.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72155 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/Expr.h4
-rw-r--r--lib/CodeGen/CGExpr.cpp2
-rw-r--r--test/CodeGenCXX/references.cpp3
3 files changed, 8 insertions, 1 deletions
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h
index 5692ec880c..0a42be9f5c 100644
--- a/include/clang/AST/Expr.h
+++ b/include/clang/AST/Expr.h
@@ -182,6 +182,10 @@ public:
/// declaration of that bit-field.
FieldDecl *getBitField();
+ const FieldDecl *getBitField() const {
+ return const_cast<Expr*>(this)->getBitField();
+ }
+
/// isIntegerConstantExpr - Return true if this expression is a valid integer
/// constant expression, and, if so, return its value in Result. If not a
/// valid i-c-e, return false and fill in Loc (if specified) with the location
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 299bb6b4a4..eaf0873610 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -72,7 +72,7 @@ RValue CodeGenFunction::EmitAnyExprToTemp(const Expr *E, llvm::Value *AggLoc,
RValue CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E,
QualType DestType) {
- if (E->isLvalue(getContext()) == Expr::LV_Valid) {
+ if (E->isLvalue(getContext()) == Expr::LV_Valid && !E->getBitField()) {
// Emit the expr as an lvalue.
LValue LV = EmitLValue(E);
return RValue::get(LV.getAddress());
diff --git a/test/CodeGenCXX/references.cpp b/test/CodeGenCXX/references.cpp
index a1a6c0ae71..82b9ec73ff 100644
--- a/test/CodeGenCXX/references.cpp
+++ b/test/CodeGenCXX/references.cpp
@@ -35,6 +35,9 @@ void test_scalar() {
int a = 10;
f(a);
+ struct { int bitfield : 3; } s = { 3 };
+ f(s.bitfield)
+
f(10);
}