From 88fad6310d3104e3ac4ab685227beabaa76faf7b Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Sat, 7 Nov 2009 00:02:45 +0000 Subject: [PATCH] Make sure isCopyAssignment is only true for actual copy assignment operators, instead of all assignment operators. The mistake messes up IRGen because it ends up assuming that the assignment operator is actually the implicit copy assignment operator, and therefore tries to emit the RHS as an lvalue. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86307 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/DeclCXX.cpp | 3 +++ lib/Sema/SemaDeclCXX.cpp | 1 - test/CodeGenCXX/assign-operator.cpp | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/CodeGenCXX/assign-operator.cpp diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index b4c0c59733..e325a25c76 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -280,6 +280,9 @@ void CXXRecordDecl::addedAssignmentOperator(ASTContext &Context, return; // This is a copy assignment operator. + // Note on the decl that it is a copy assignment operator. + OpDecl->setCopyAssignment(true); + // Suppress the implicit declaration of a copy constructor. UserDeclaredCopyAssignment = true; diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index f3561bfa0f..c7fd5ccd1e 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -4183,7 +4183,6 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) { assert(isa(FnDecl) && "Overloaded = not member, but not filtered."); CXXMethodDecl *Method = cast(FnDecl); - Method->setCopyAssignment(true); Method->getParent()->addedAssignmentOperator(Context, Method); } diff --git a/test/CodeGenCXX/assign-operator.cpp b/test/CodeGenCXX/assign-operator.cpp new file mode 100644 index 0000000000..3e0be45194 --- /dev/null +++ b/test/CodeGenCXX/assign-operator.cpp @@ -0,0 +1,9 @@ +// RUN: clang-cc %s -emit-llvm-only -verify + +class x { +int operator=(int); +}; +void a() { + x a; + a = 1u; +} -- 2.40.0