]> granicus.if.org Git - clang/commitdiff
Restore r101841 without modification. Also mark 'operator delete' as used for
authorJohn McCall <rjmccall@apple.com>
Tue, 20 Apr 2010 02:18:25 +0000 (02:18 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 20 Apr 2010 02:18:25 +0000 (02:18 +0000)
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
test/CXX/expr/expr.unary/expr.new/p19.cpp
test/CXX/expr/expr.unary/expr.new/p20-0x.cpp
test/CXX/expr/expr.unary/expr.new/p20.cpp
test/CodeGenCXX/delete.cpp
test/SemaCXX/no-exceptions.cpp [new file with mode: 0644]

index 9440772fc6e43eb1c4dc276e427b256844983310..5f1eee1f0a581081163954952e3b171961ef460e 100644 (file)
@@ -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.
   }
 
index 6134779f1fd22f96057e135373b7a5df3951f678..bb69fd55fd8034abbb1abc83c4d66aa3b0583fc4 100644 (file)
@@ -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
index c188e1e25e04eb484ec38648959601d155c0210a..4c924b137ccdfe38dd31791d0f3aa5b30167910a 100644 (file)
@@ -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 {
index 71e584e775c3f5c640c7f8b640408e6c5208504c..8cbe2b9be3be72b6c5b251a47a3e7cbecd0f85ba 100644 (file)
@@ -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
index 7cc264f5c5f5ea3bd016c7f124c5105ba666db4a..87f8698b84c3a75a77c139607511ad0193e4e203 100644 (file)
@@ -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 (file)
index 0000000..019e25c
--- /dev/null
@@ -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();
+  }
+}