Index: lib/AST/Decl.cpp =================================================================== --- lib/AST/Decl.cpp +++ lib/AST/Decl.cpp @@ -666,7 +666,12 @@ // Use global type/value visibility as appropriate. Visibility globalVisibility; if (computation == LVForValue) { - globalVisibility = Context.getLangOpts().getValueVisibilityMode(); + const FunctionDecl *FD = D->getAsFunction(); + if (FD && FD->getCorrespondingUnsizedGlobalDeallocationFunction()) + // C++14's implicit sized deallocation functions always have default visibility. + globalVisibility = DefaultVisibility; + else + globalVisibility = Context.getLangOpts().getValueVisibilityMode(); } else { assert(computation == LVForType); globalVisibility = Context.getLangOpts().getTypeVisibilityMode(); Index: test/CodeGenCXX/cxx14-implicit-sized-delete.cpp =================================================================== --- /dev/null +++ test/CodeGenCXX/cxx14-implicit-sized-delete.cpp @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -o - -std=c++14 %s 2>&1 | FileCheck %s -check-prefix=CHECKDEF -check-prefix=CHECK +// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -o - -std=c++14 -fvisibility hidden %s 2>&1 | FileCheck %s -check-prefix=CHECKHID -check-prefix=CHECK + +// PR22419: Implicit sized deallocation functions always have default visibility. + +// CHECKDEF-DAG: define void @_Z3fooPi(i32* %is) +// CHECKHID-DAG: define hidden void @_Z3fooPi(i32* %is) +void foo(int* is) { + + // CHECK-DAG: call void @_ZdlPvm(i8* %1, i64 4) + delete is; +} + +// CHECK-DAG: define linkonce void @_ZdlPvm(i8*, i64) + +// CHECK-DAG: %struct.A = type { i8 } +struct A { ~A() { }}; + +// CHECKDEF-DAG: define void @_Z1fP1A(%struct.A* %p) +// CHECKHID-DAG: define hidden void @_Z1fP1A(%struct.A* %p) +void f(A *p) { + + // CHECK-DAG: call void @_ZdaPvm(i8* %2, i64 %6) + delete[] p; +} + +// CHECK-DAG: define linkonce void @_ZdaPvm(i8*, i64) \ No newline at end of file