diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index 5692ec880c7a..0a42be9f5c31 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -182,6 +182,10 @@ public: /// declaration of that bit-field. FieldDecl *getBitField(); + const FieldDecl *getBitField() const { + return const_cast(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/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 299bb6b4a4ae..eaf0873610dd 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/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/clang/test/CodeGenCXX/references.cpp b/clang/test/CodeGenCXX/references.cpp index a1a6c0ae71a0..82b9ec73ff3e 100644 --- a/clang/test/CodeGenCXX/references.cpp +++ b/clang/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); }