From 9c82afc7d1f57b427053e6679d87539b0dc63b1a Mon Sep 17 00:00:00 2001 From: John McCall Date: Tue, 20 Apr 2010 02:18:25 +0000 Subject: [PATCH] Restore r101841 without modification. Also mark 'operator delete' as used for actual delete expressions, not just new expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101861 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprCXX.cpp | 9 +++++++ test/CXX/expr/expr.unary/expr.new/p19.cpp | 2 +- test/CXX/expr/expr.unary/expr.new/p20-0x.cpp | 2 +- test/CXX/expr/expr.unary/expr.new/p20.cpp | 2 +- test/CodeGenCXX/delete.cpp | 26 ++++++++++++++++++-- test/SemaCXX/no-exceptions.cpp | 21 ++++++++++++++++ 6 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 test/SemaCXX/no-exceptions.cpp diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 9440772fc6..5f1eee1f0a 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -886,6 +886,13 @@ bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, return true; } + // We don't need an operator delete if we're running under + // -fno-exceptions. + if (!getLangOptions().Exceptions) { + OperatorDelete = 0; + return false; + } + // FindAllocationOverload can change the passed in arguments, so we need to // copy them back. if (NumPlaceArgs > 0) @@ -1392,6 +1399,8 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, return ExprError(); } + MarkDeclarationReferenced(StartLoc, OperatorDelete); + // FIXME: Check access and ambiguity of operator delete and destructor. } diff --git a/test/CXX/expr/expr.unary/expr.new/p19.cpp b/test/CXX/expr/expr.unary/expr.new/p19.cpp index 6134779f1f..bb69fd55fd 100644 --- a/test/CXX/expr/expr.unary/expr.new/p19.cpp +++ b/test/CXX/expr/expr.unary/expr.new/p19.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -fexceptions %s typedef __SIZE_TYPE__ size_t; // Operator delete template for placement new with global lookup diff --git a/test/CXX/expr/expr.unary/expr.new/p20-0x.cpp b/test/CXX/expr/expr.unary/expr.new/p20-0x.cpp index c188e1e25e..4c924b137c 100644 --- a/test/CXX/expr/expr.unary/expr.new/p20-0x.cpp +++ b/test/CXX/expr/expr.unary/expr.new/p20-0x.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x -fexceptions %s typedef __SIZE_TYPE__ size_t; struct S { diff --git a/test/CXX/expr/expr.unary/expr.new/p20.cpp b/test/CXX/expr/expr.unary/expr.new/p20.cpp index 71e584e775..8cbe2b9be3 100644 --- a/test/CXX/expr/expr.unary/expr.new/p20.cpp +++ b/test/CXX/expr/expr.unary/expr.new/p20.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -fexceptions %s typedef __SIZE_TYPE__ size_t; // Overloaded operator delete with two arguments diff --git a/test/CodeGenCXX/delete.cpp b/test/CodeGenCXX/delete.cpp index 7cc264f5c5..87f8698b84 100644 --- a/test/CodeGenCXX/delete.cpp +++ b/test/CodeGenCXX/delete.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -emit-llvm -o %t +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s void t1(int *a) { delete a; @@ -19,8 +19,11 @@ struct T { int a; }; +// CHECK: define void @_Z2t4P1T void t4(T *t) { - // RUN: grep "call void @_ZN1TD1Ev" %t | count 1 + // CHECK: call void @_ZN1TD1Ev + // CHECK-NEXT: bitcast + // CHECK-NEXT: call void @_ZdlPv delete t; } @@ -35,3 +38,22 @@ void f() { delete a; } + +namespace test0 { + struct A { + void *operator new(__SIZE_TYPE__ sz); + void operator delete(void *p) { ::operator delete(p); } + ~A() {} + }; + + // CHECK: define void @_ZN5test04testEPNS_1AE( + void test(A *a) { + // CHECK: call void @_ZN5test01AD1Ev + // CHECK-NEXT: bitcast + // CHECK-NEXT: call void @_ZN5test01AdlEPv + delete a; + } + + // CHECK: define linkonce_odr void @_ZN5test01AD1Ev + // CHECK: define linkonce_odr void @_ZN5test01AdlEPv +} diff --git a/test/SemaCXX/no-exceptions.cpp b/test/SemaCXX/no-exceptions.cpp new file mode 100644 index 0000000000..019e25c978 --- /dev/null +++ b/test/SemaCXX/no-exceptions.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// Various tests for -fno-exceptions + +typedef __SIZE_TYPE__ size_t; + +namespace test0 { + // rdar://problem/7878149 + class Foo { + public: + void* operator new(size_t x); + private: + void operator delete(void *x); + }; + + void test() { + // Under -fexceptions, this does access control for the associated + // 'operator delete'. + (void) new Foo(); + } +} -- 2.40.0