r193964 - Sema: Do not allow overloading between methods based on restrict
David Majnemer
david.majnemer at gmail.com
Sun Nov 3 15:51:28 PST 2013
Author: majnemer
Date: Sun Nov 3 17:51:28 2013
New Revision: 193964
URL: http://llvm.org/viewvc/llvm-project?rev=193964&view=rev
Log:
Sema: Do not allow overloading between methods based on restrict
If the sole distinction between two declarations is that one has a
__restrict qualifier then we should not consider it to be an overload.
Instead, we will consider it as an incompatible redeclaration which is
similar to how MSVC, ICC and GCC would handle it.
This fixes PR17786.
N.B. We must not mangle in __restrict into method qualifiers becase we
don't allow overloading between such declarations anymore. To do
otherwise would be a violation of the Itanium ABI.
Modified:
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/CodeGenCXX/mangle.cpp
cfe/trunk/test/SemaCXX/overload-decl.cpp
Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=193964&r1=193963&r2=193964&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Sun Nov 3 17:51:28 2013
@@ -1239,7 +1239,12 @@ void CXXNameMangler::mangleNestedName(co
Out << 'N';
if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(ND)) {
- mangleQualifiers(Qualifiers::fromCVRMask(Method->getTypeQualifiers()));
+ Qualifiers MethodQuals =
+ Qualifiers::fromCVRMask(Method->getTypeQualifiers());
+ // We do not consider restrict a distinguishing attribute for overloading
+ // purposes so we must not mangle it.
+ MethodQuals.removeRestrict();
+ mangleQualifiers(MethodQuals);
mangleRefQualifier(Method->getRefQualifier());
}
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=193964&r1=193963&r2=193964&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Sun Nov 3 17:51:28 2013
@@ -1071,11 +1071,16 @@ bool Sema::IsOverload(FunctionDecl *New,
// function yet (because we haven't yet resolved whether this is a static
// or non-static member function). Add it now, on the assumption that this
// is a redeclaration of OldMethod.
+ unsigned OldQuals = OldMethod->getTypeQualifiers();
unsigned NewQuals = NewMethod->getTypeQualifiers();
if (!getLangOpts().CPlusPlus1y && NewMethod->isConstexpr() &&
!isa<CXXConstructorDecl>(NewMethod))
NewQuals |= Qualifiers::Const;
- if (OldMethod->getTypeQualifiers() != NewQuals)
+
+ // We do not allow overloading based off of '__restrict'.
+ OldQuals &= ~Qualifiers::Restrict;
+ NewQuals &= ~Qualifiers::Restrict;
+ if (OldQuals != NewQuals)
return true;
}
Modified: cfe/trunk/test/CodeGenCXX/mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle.cpp?rev=193964&r1=193963&r2=193964&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle.cpp Sun Nov 3 17:51:28 2013
@@ -942,3 +942,12 @@ namespace test43 {
void g(zed<&foo::bar>*)
{}
}
+
+namespace test44 {
+ struct foo { void bar() __restrict { }; } obj;
+
+ void f() {
+ obj.bar();
+ }
+ // CHECK-LABEL: define linkonce_odr void @_ZN6test443foo3barEv(%"struct.test44::foo"* %this)
+}
Modified: cfe/trunk/test/SemaCXX/overload-decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overload-decl.cpp?rev=193964&r1=193963&r2=193964&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/overload-decl.cpp (original)
+++ cfe/trunk/test/SemaCXX/overload-decl.cpp Sun Nov 3 17:51:28 2013
@@ -29,6 +29,11 @@ class X {
static void g(float); // expected-note {{previous declaration is here}}
static void g(int); // expected-error {{static and non-static member functions with the same parameter types cannot be overloaded}}
static void g(float); // expected-error {{class member cannot be redeclared}}
+
+ void h(); // expected-note {{previous declaration is here}} \
+ expected-note {{previous declaration is here}}
+ void h() __restrict; // expected-error {{class member cannot be redeclared}} \
+ expected-error {{conflicting types for 'h'}}
};
int main() {} // expected-note {{previous definition is here}}
More information about the cfe-commits
mailing list