More on fixing sized deallocation implementation logic: Fix PR21754.
authorLarisse Voufo <lvoufo@google.com>
Sun, 15 Feb 2015 08:16:37 +0000 (08:16 +0000)
committerLarisse Voufo <lvoufo@google.com>
Sun, 15 Feb 2015 08:16:37 +0000 (08:16 +0000)
llvm-svn: 229291

clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCXX/pr21754.cpp [new file with mode: 0644]

index fdcbe2a..ea7da8c 100644 (file)
@@ -1617,11 +1617,14 @@ CodeGenModule::GetOrCreateLLVMFunction(StringRef MangledName,
       DeferredDecls.erase(DDI);
       
       // Otherwise, if this is a sized deallocation function, emit a weak
-      // definition for it at the end of the translation unit.
-    } else if (D && cast<FunctionDecl>(D)
-                        ->getCorrespondingUnsizedGlobalDeallocationFunction()) {
-      if (getLangOpts().DefaultSizedDelete)
-        addDeferredDeclToEmit(F, GD);
+      // definition for it at the end of the translation unit (if allowed),
+      // unless the sized deallocation function is aliased.
+    } else if (D &&
+               cast<FunctionDecl>(D)
+                  ->getCorrespondingUnsizedGlobalDeallocationFunction() &&
+               !getLangOpts().DefaultSizedDelete &&
+               !D->hasAttr<AliasAttr>()) {
+      addDeferredDeclToEmit(F, GD);
 
       // Otherwise, there are cases we have to worry about where we're
       // using a declaration for which we must emit a definition but where
diff --git a/clang/test/CodeGenCXX/pr21754.cpp b/clang/test/CodeGenCXX/pr21754.cpp
new file mode 100644 (file)
index 0000000..c9fa033
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: %clang -cc1 -emit-llvm -triple x86_64-unknown-unknown -std=c++1y %s -o -
+// RUN: %clang -cc1 -emit-llvm -triple x86_64-unknown-unknown -std=c++1y %s -fdef-sized-delete -o -
+// RUN: %clang -cc1 -emit-llvm -triple x86_64-unknown-unknown -std=c++11 -fsized-deallocation %s -o -
+// RUN: %clang -cc1 -emit-llvm -triple x86_64-unknown-unknown -std=c++11 -fsized-deallocation -fdef-sized-delete %s -o -
+// RUN: %clang -cc1 -emit-llvm -triple x86_64-unknown-unknown -std=c++11 %s -o -
+
+// CHECK-UNSIZED-NOT: _ZdlPvm
+// CHECK-UNSIZED-NOT: _ZdaPvm
+
+void operator delete(void*, unsigned long) throw() __attribute__((alias("foo")));
+extern "C" void foo(void*, unsigned long) {}
+
+// CHECK-DAG: @_ZdlPvm = alias void (i8*, i64)* @my_delete