[PATCH] [ms-cxxabi] Elide dtor access checks for pass-by-val objects in callees
Hans Wennborg
hans at chromium.org
Fri Jan 10 08:50:15 PST 2014
Thanks Richard! New patch attached/uploaded that only elides the direct access check. Does this look OK?
Hi rnk, rsmith,
http://llvm-reviews.chandlerc.com/D2409
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D2409?vs=6154&id=6412#toc
Files:
lib/Sema/SemaChecking.cpp
test/SemaCXX/microsoft-dtor-lookup.cpp
test/SemaObjCXX/microsoft-abi-byval.mm
Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -6239,12 +6239,21 @@
// MSVC destroys objects passed by value in the callee. Therefore a
// function definition which takes such a parameter must be able to call the
- // object's destructor.
+ // object's destructor. However, we don't perform any direct access check
+ // on the dtor.
if (getLangOpts().CPlusPlus && Context.getTargetInfo()
.getCXXABI()
.areArgsDestroyedLeftToRightInCallee()) {
- if (const RecordType *RT = Param->getType()->getAs<RecordType>())
- FinalizeVarWithDestructor(Param, RT);
+ if (const RecordType *RT = Param->getType()->getAs<RecordType>()) {
+ CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(RT->getDecl());
+ if (!ClassDecl->isInvalidDecl() &&
+ !ClassDecl->hasIrrelevantDestructor() &&
+ !ClassDecl->isDependentContext()) {
+ CXXDestructorDecl *Destructor = LookupDestructor(ClassDecl);
+ MarkFunctionReferenced(Param->getLocation(), Destructor);
+ DiagnoseUseOfDecl(Destructor, Param->getLocation());
+ }
+ }
}
}
Index: test/SemaCXX/microsoft-dtor-lookup.cpp
===================================================================
--- test/SemaCXX/microsoft-dtor-lookup.cpp
+++ test/SemaCXX/microsoft-dtor-lookup.cpp
@@ -32,10 +32,9 @@
// requires a dtor for B, but we can't implicitly define it because ~A is
// private. bar should be able to call A's private dtor without error, even
// though MSVC rejects bar.
-
class A {
private:
- ~A(); // expected-note 2{{declared private here}}
+ ~A(); // expected-note {{declared private here}}
int a;
};
@@ -54,7 +53,7 @@
};
void foo(B b) { } // expected-note {{implicit destructor for 'Test2::B' first required here}}
-void bar(A a) { } // expected-error {{variable of type 'Test2::A' has private destructor}}
+void bar(A a) { } // no error; MSVC rejects this, but we skip the direct access check.
void baz(D d) { } // no error
}
@@ -64,13 +63,13 @@
class A {
A();
- ~A(); // expected-note 2{{implicitly declared private here}}
+ ~A(); // expected-note {{implicitly declared private here}}
friend void bar(A);
int a;
};
void bar(A a) { }
-void baz(A a) { } // expected-error {{variable of type 'Test3::A' has private destructor}}
+void baz(A a) { } // no error; MSVC rejects this, but the standard allows it.
// MSVC accepts foo() but we reject it for consistency with Itanium. MSVC also
// rejects this if A has a copy ctor or if we call A's ctor.
Index: test/SemaObjCXX/microsoft-abi-byval.mm
===================================================================
--- test/SemaObjCXX/microsoft-abi-byval.mm
+++ test/SemaObjCXX/microsoft-abi-byval.mm
@@ -1,14 +1,15 @@
// RUN: %clang_cc1 -fsyntax-only -verify -cxx-abi microsoft -Wno-objc-root-class %s
+// expected-no-diagnostics
class Foo {
- ~Foo(); // expected-note {{implicitly declared private here}}
+ ~Foo();
};
@interface bar
- (void) my_method: (Foo)arg;
@end
@implementation bar
-- (void) my_method: (Foo)arg { // expected-error {{variable of type 'Foo' has private destructor}}
+- (void) my_method: (Foo)arg { // no error; MS ABI will call Foo's dtor, but we skip the access check.
}
@end
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2409.3.patch
Type: text/x-patch
Size: 3460 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140110/dd5f8fc8/attachment.bin>
More information about the cfe-commits
mailing list