From 1fd1e288d0f45b86d191d8f53f569e5143f3a18a Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 11 Apr 2013 00:58:58 +0000 Subject: Force a load when creating a reference to a temporary copied from a bitfield. For this source: const int &ref = someStruct.bitfield; We used to generate this AST: DeclStmt [...] `-VarDecl [...] ref 'const int &' `-MaterializeTemporaryExpr [...] 'const int' lvalue `-ImplicitCastExpr [...] 'const int' lvalue `-MemberExpr [...] 'int' lvalue bitfield .bitfield [...] `-DeclRefExpr [...] 'struct X' lvalue ParmVar [...] 'someStruct' 'struct X' Notice the lvalue inside the MaterializeTemporaryExpr, which is very confusing (and caused an assertion to fire in the analyzer - PR15694). We now generate this: DeclStmt [...] `-VarDecl [...] ref 'const int &' `-MaterializeTemporaryExpr [...] 'const int' lvalue `-ImplicitCastExpr [...] 'int' `-MemberExpr [...] 'int' lvalue bitfield .bitfield [...] `-DeclRefExpr [...] 'struct X' lvalue ParmVar [...] 'someStruct' 'struct X' Which makes a lot more sense. This allows us to remove code in both CodeGen and AST that hacked around this special case. The commit also makes Clang accept this (legal) C++11 code: int &&ref = std::move(someStruct).bitfield PR15694 / git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179250 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Analysis/reference.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/Analysis/reference.cpp') diff --git a/test/Analysis/reference.cpp b/test/Analysis/reference.cpp index 8dd0baf8c3..bcab80b04b 100644 --- a/test/Analysis/reference.cpp +++ b/test/Analysis/reference.cpp @@ -224,3 +224,13 @@ namespace rdar11212286 { return *x; // no-warning } } + +namespace PR15694 { + class C { + bool bit : 1; + template void bar(const T &obj) {} + void foo() { + bar(bit); // don't crash + } + }; +} -- cgit v1.2.3-18-g5258