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
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h
index 5692ec8..0a42be9 100644
--- a/include/clang/AST/Expr.h
+++ b/include/clang/AST/Expr.h
@@ -182,6 +182,10 @@
/// 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 299bb6b..eaf0873 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -72,7 +72,7 @@
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 a1a6c0a..82b9ec7 100644
--- a/test/CodeGenCXX/references.cpp
+++ b/test/CodeGenCXX/references.cpp
@@ -35,6 +35,9 @@
int a = 10;
f(a);
+ struct { int bitfield : 3; } s = { 3 };
+ f(s.bitfield)
+
f(10);
}