Author: Richard Smith Date: 2020-06-30T16:07:50-07:00 New Revision: b6c490349d1524aefeb1c4a686411f860e6a3555
URL: https://github.com/llvm/llvm-project/commit/b6c490349d1524aefeb1c4a686411f860e6a3555 DIFF: https://github.com/llvm/llvm-project/commit/b6c490349d1524aefeb1c4a686411f860e6a3555.diff LOG: A constexpr virtual function is implicitly inline so should never be a key function. Added: clang/test/CodeGenCXX/vtable-constexpr.cpp Modified: clang/lib/AST/RecordLayoutBuilder.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp index 028e82a5df4d..3d5f785e943e 100644 --- a/clang/lib/AST/RecordLayoutBuilder.cpp +++ b/clang/lib/AST/RecordLayoutBuilder.cpp @@ -2107,7 +2107,7 @@ static const CXXMethodDecl *computeKeyFunction(ASTContext &Context, if (MD->isImplicit()) continue; - if (MD->isInlineSpecified()) + if (MD->isInlineSpecified() || MD->isConstexpr()) continue; if (MD->hasInlineBody()) diff --git a/clang/test/CodeGenCXX/vtable-constexpr.cpp b/clang/test/CodeGenCXX/vtable-constexpr.cpp new file mode 100644 index 000000000000..e398a9e5835d --- /dev/null +++ b/clang/test/CodeGenCXX/vtable-constexpr.cpp @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -std=c++20 %s -emit-llvm -o - -triple %itanium_abi_triple | FileCheck %s --implicit-check-not=DoNotEmit + +// constexpr virtual functions can be called at runtime and go in the vtable as +// normal. But they are implicitly inline so are never the key function. + +struct DoNotEmit { + virtual constexpr void f(); +}; +constexpr void DoNotEmit::f() {} + +// CHECK-DAG: @_ZTV1B = {{.*}} constant { [3 x i8*] } { {{.*}} null, {{.*}} @_ZTI1B {{.*}} @_ZN1B1fEv +struct B { + // CHECK-DAG: define {{.*}} @_ZN1B1fEv + virtual constexpr void f() {} +}; +B b; + +struct CBase { + virtual constexpr void f(); // not key function +}; + +// CHECK-DAG: @_ZTV1C = {{.*}} constant {{.*}} null, {{.*}} @_ZTI1C {{.*}} @_ZN1C1fEv +struct C : CBase { + void f(); // key function +}; +// CHECK-DAG: define {{.*}} @_ZN1C1fEv +void C::f() {} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits