https://github.com/minglotus-6 updated https://github.com/llvm/llvm-project/pull/70841
>From 99abebc88c09346bd4a70bbf39df13b249116c09 Mon Sep 17 00:00:00 2001 From: Mingming Liu <mingmi...@google.com> Date: Tue, 31 Oct 2023 01:17:03 -0700 Subject: [PATCH 1/2] [Clang]Emit type metadata when -fprofile-generate is on --- clang/lib/CodeGen/CGVTables.cpp | 2 +- clang/lib/CodeGen/MicrosoftCXXABI.cpp | 3 +- clang/test/CodeGenCXX/type-metadata.cpp | 150 ++++++++++++------------ 3 files changed, 80 insertions(+), 75 deletions(-) diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp index 25e4b1c27932026..895e160dfa8a536 100644 --- a/clang/lib/CodeGen/CGVTables.cpp +++ b/clang/lib/CodeGen/CGVTables.cpp @@ -1312,7 +1312,7 @@ llvm::GlobalObject::VCallVisibility CodeGenModule::GetVCallVisibilityLevel( void CodeGenModule::EmitVTableTypeMetadata(const CXXRecordDecl *RD, llvm::GlobalVariable *VTable, const VTableLayout &VTLayout) { - if (!getCodeGenOpts().LTOUnit) + if (!getCodeGenOpts().LTOUnit && !getCodeGenOpts().hasProfileIRInstr()) return; CharUnits ComponentWidth = GetTargetTypeStoreSize(getVTableComponentType()); diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp index d623f8f63ae56c4..740c0b6cb1aac04 100644 --- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp @@ -1673,7 +1673,8 @@ void MicrosoftCXXABI::EmitDestructorCall(CodeGenFunction &CGF, void MicrosoftCXXABI::emitVTableTypeMetadata(const VPtrInfo &Info, const CXXRecordDecl *RD, llvm::GlobalVariable *VTable) { - if (!CGM.getCodeGenOpts().LTOUnit) + if (!CGM.getCodeGenOpts().LTOUnit && + !CGM.getCodeGenOpts().hasProfileIRInstr()) return; // TODO: Should VirtualFunctionElimination also be supported here? diff --git a/clang/test/CodeGenCXX/type-metadata.cpp b/clang/test/CodeGenCXX/type-metadata.cpp index 3f8b54af801f8d6..637ec6e6c326ab6 100644 --- a/clang/test/CodeGenCXX/type-metadata.cpp +++ b/clang/test/CodeGenCXX/type-metadata.cpp @@ -1,113 +1,117 @@ // Tests for the cfi-vcall feature: -// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM --check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG %s -// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM --check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-ABORT %s -// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM --check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s -// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=MS --check-prefix=TT-MS --check-prefix=NDIAG %s +// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG %s +// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-ABORT %s +// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s +// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=MS-TYPEMETADATA --check-prefix=MS --check-prefix=TT-MS --check-prefix=NDIAG %s // Tests for the whole-program-vtables feature: -// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM --check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN %s +// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN %s // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM-DEFAULTVIS --check-prefix=TT-ITANIUM-DEFAULT %s // RUN: %clang_cc1 -O2 -flto -flto-unit -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=ITANIUM-OPT --check-prefix=ITANIUM-OPT-LAYOUT %s -// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=MS --check-prefix=TT-MS %s +// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=MS-TYPEMETADATA --check-prefix=MS --check-prefix=TT-MS %s // Tests for cfi + whole-program-vtables: -// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-VT --check-prefix=ITANIUM --check-prefix=TC-ITANIUM --check-prefix=ITANIUM-MD %s +// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-VT --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=TC-ITANIUM --check-prefix=ITANIUM-MD %s // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-VT --check-prefix=MS --check-prefix=TC-MS %s // Equivalent tests for above, but with relative-vtables. // Tests for the cfi-vcall feature: -// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT --check-prefix=RV-MD --check-prefix=ITANIUM --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG --check-prefix=CFI-NVT-RV %s -// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT --check-prefix=CFI-NVT-RV --check-prefix=ITANIUM --check-prefix=RV-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-DIAG --check-prefix=RV-MD-DIAG --check-prefix=DIAG --check-prefix=DIAG-ABORT %s -// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT --check-prefix=CFI-NVT-RV --check-prefix=ITANIUM --check-prefix=RV-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-DIAG --check-prefix=RV-MD-DIAG --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s +// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT --check-prefix=RV-MD --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG --check-prefix=CFI-NVT-RV %s +// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT --check-prefix=CFI-NVT-RV --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=RV-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-DIAG --check-prefix=RV-MD-DIAG --check-prefix=DIAG --check-prefix=DIAG-ABORT %s +// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT --check-prefix=CFI-NVT-RV --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=RV-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-DIAG --check-prefix=RV-MD-DIAG --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s // Tests for the whole-program-vtables feature: -// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM -check-prefix=RV-MD --check-prefix=TT-ITANIUM-HIDDEN %s +// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN -check-prefix=RV-MD --check-prefix=TT-ITANIUM-HIDDEN %s // RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM-DEFAULTVIS --check-prefix=TT-ITANIUM-DEFAULT %s // RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -O2 -flto -flto-unit -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=ITANIUM-OPT --check-prefix=RV-OPT-LAYOUT %s // Tests for cfi + whole-program-vtables: -// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-VT --check-prefix=ITANIUM --check-prefix=RV-MD --check-prefix=TC-ITANIUM %s +// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-VT --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=RV-MD --check-prefix=TC-ITANIUM %s -// ITANIUM: @_ZTV1A = {{[^!]*}}, !type [[A16:![0-9]+]] +// Test that type metadata are emitted with -fprofile-generate +// RUN: %clang -fprofile-generate -fno-lto -target x86_64-unknown-linux -emit-llvm -S %s -o - | FileCheck %s --check-prefix=ITANIUM-TYPEMETADATA +// RUN: %clang -fprofile-generate -fno-lto -target x86_64-pc-windows-msvc -emit-llvm -S %s -o - | FileCheck %s --check-prefix=MS-TYPEMETADATA + +// ITANIUM-TYPEMETADATA: @_ZTV1A = {{[^!]*}}, !type [[A16:![0-9]+]] // ITANIUM-DIAG-SAME: !type [[ALL16:![0-9]+]] -// ITANIUM-SAME: !type [[AF16:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[AF16:![0-9]+]] -// ITANIUM: @_ZTV1B = {{[^!]*}}, !type [[A32:![0-9]+]] +// ITANIUM-TYPEMETADATA: @_ZTV1B = {{[^!]*}}, !type [[A32:![0-9]+]] // ITANIUM-DIAG-SAME: !type [[ALL32:![0-9]+]] -// ITANIUM-SAME: !type [[AF32:![0-9]+]] -// ITANIUM-SAME: !type [[AF40:![0-9]+]] -// ITANIUM-SAME: !type [[AF48:![0-9]+]] -// ITANIUM-SAME: !type [[B32:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[AF32:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[AF40:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[AF48:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[B32:![0-9]+]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM-SAME: !type [[BF32:![0-9]+]] -// ITANIUM-SAME: !type [[BF40:![0-9]+]] -// ITANIUM-SAME: !type [[BF48:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[BF32:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[BF40:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[BF48:![0-9]+]] -// ITANIUM: @_ZTV1C = {{[^!]*}}, !type [[A32]] +// ITANIUM-TYPEMETADATA: @_ZTV1C = {{[^!]*}}, !type [[A32]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM-SAME: !type [[AF32]] -// ITANIUM-SAME: !type [[C32:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[AF32]] +// ITANIUM-TYPEMETADATA-SAME: !type [[C32:![0-9]+]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM-SAME: !type [[CF32:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[CF32:![0-9]+]] // DIAG: @[[SRC:.*]] = private unnamed_addr constant [{{.*}} x i8] c"{{.*}}type-metadata.cpp\00", align 1 // DIAG: @[[TYPE:.*]] = private unnamed_addr constant { i16, i16, [4 x i8] } { i16 -1, i16 0, [4 x i8] c"'A'\00" } // DIAG: @[[BADTYPESTATIC:.*]] = private unnamed_addr global { i8, { ptr, i32, i32 }, ptr } { i8 0, { ptr, i32, i32 } { ptr @[[SRC]], i32 123, i32 3 }, ptr @[[TYPE]] } -// ITANIUM: @_ZTVN12_GLOBAL__N_11DE = {{[^!]*}}, !type [[A32]] +// ITANIUM-TYPEMETADATA: @_ZTVN12_GLOBAL__N_11DE = {{[^!]*}}, !type [[A32]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM-SAME: !type [[AF32]] -// ITANIUM-SAME: !type [[AF40]] -// ITANIUM-SAME: !type [[AF48]] -// ITANIUM-SAME: !type [[B32]] +// ITANIUM-TYPEMETADATA-SAME: !type [[AF32]] +// ITANIUM-TYPEMETADATA-SAME: !type [[AF40]] +// ITANIUM-TYPEMETADATA-SAME: !type [[AF48]] +// ITANIUM-TYPEMETADATA-SAME: !type [[B32]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM-SAME: !type [[BF32]] -// ITANIUM-SAME: !type [[BF40]] -// ITANIUM-SAME: !type [[BF48]] -// ITANIUM-SAME: !type [[C88:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[BF32]] +// ITANIUM-TYPEMETADATA-SAME: !type [[BF40]] +// ITANIUM-TYPEMETADATA-SAME: !type [[BF48]] +// ITANIUM-TYPEMETADATA-SAME: !type [[C88:![0-9]+]] // ITANIUM-DIAG-SAME: !type [[ALL88:![0-9]+]] -// ITANIUM-SAME: !type [[CF32]] -// ITANIUM-SAME: !type [[CF40:![0-9]+]] -// ITANIUM-SAME: !type [[CF48:![0-9]+]] -// ITANIUM-SAME: !type [[D32:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[CF32]] +// ITANIUM-TYPEMETADATA-SAME: !type [[CF40:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[CF48:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[D32:![0-9]+]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM-SAME: !type [[DF32:![0-9]+]] -// ITANIUM-SAME: !type [[DF40:![0-9]+]] -// ITANIUM-SAME: !type [[DF48:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[DF32:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[DF40:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[DF48:![0-9]+]] -// ITANIUM: @_ZTCN12_GLOBAL__N_11DE0_1B = {{[^!]*}}, !type [[A32]] +// ITANIUM-TYPEMETADATA: @_ZTCN12_GLOBAL__N_11DE0_1B = {{[^!]*}}, !type [[A32]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM-SAME: !type [[B32]] +// ITANIUM-TYPEMETADATA-SAME: !type [[B32]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM: @_ZTCN12_GLOBAL__N_11DE8_1C = {{[^!]*}}, !type [[A64:![0-9]+]] +// ITANIUM-TYPEMETADATA: @_ZTCN12_GLOBAL__N_11DE8_1C = {{[^!]*}}, !type [[A64:![0-9]+]] // ITANIUM-DIAG-SAME: !type [[ALL64:![0-9]+]] -// ITANIUM-SAME: !type [[AF64:![0-9]+]] -// ITANIUM-SAME: !type [[C32]] +// ITANIUM-TYPEMETADATA-SAME: !type [[AF64:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[C32]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM-SAME: !type [[CF64:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[CF64:![0-9]+]] -// ITANIUM: @_ZTVZ3foovE2FA = {{[^!]*}}, !type [[A16]] +// ITANIUM-TYPEMETADATA: @_ZTVZ3foovE2FA = {{[^!]*}}, !type [[A16]] // ITANIUM-DIAG-SAME: !type [[ALL16]] -// ITANIUM-SAME: !type [[AF16]] -// ITANIUM-SAME: !type [[FA16:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[AF16]] +// ITANIUM-TYPEMETADATA-SAME: !type [[FA16:![0-9]+]] // ITANIUM-DIAG-SAME: !type [[ALL16]] -// ITANIUM-SAME: !type [[FAF16:![0-9]+]] +// ITANIUM-TYPEMETADATA-SAME: !type [[FAF16:![0-9]+]] -// ITANIUM: @_ZTVN5test31EE = external unnamed_addr constant +// ITANIUM-TYPEMETADATA: @_ZTVN5test31EE = external unnamed_addr constant // ITANIUM-DEFAULTVIS: @_ZTVN5test31EE = external unnamed_addr constant // ITANIUM-OPT: @_ZTVN5test31EE = available_externally unnamed_addr constant {{[^!]*}}, // ITANIUM-OPT-SAME: !type [[E16:![0-9]+]], // ITANIUM-OPT-SAME: !type [[EF16:![0-9]+]] // ITANIUM-OPT: @llvm.compiler.used = appending global [1 x ptr] [ptr @_ZTVN5test31EE] -// MS: comdat($"??_7A@@6B@"), !type [[A8:![0-9]+]] -// MS: comdat($"??_7B@@6B0@@"), !type [[B8:![0-9]+]] -// MS: comdat($"??_7B@@6BA@@@"), !type [[A8]] -// MS: comdat($"??_7C@@6B@"), !type [[A8]] -// MS: comdat($"??_7D@?A0x{{[^@]*}}@@6BB@@@"), !type [[B8]], !type [[D8:![0-9]+]] -// MS: comdat($"??_7D@?A0x{{[^@]*}}@@6BA@@@"), !type [[A8]] -// MS: comdat($"??_7FA@?1??foo@@YAXXZ@6B@"), !type [[A8]], !type [[FA8:![0-9]+]] +// MS-TYPEMETADATA: comdat($"??_7A@@6B@"), !type [[A8:![0-9]+]] +// MS-TYPEMETADATA: comdat($"??_7B@@6B0@@"), !type [[B8:![0-9]+]] +// MS-TYPEMETADATA: comdat($"??_7B@@6BA@@@"), !type [[A8]] +// MS-TYPEMETADATA: comdat($"??_7C@@6B@"), !type [[A8]] +// MS-TYPEMETADATA: comdat($"??_7D@?A0x{{[^@]*}}@@6BB@@@"), !type [[B8]], !type [[D8:![0-9]+]] +// MS-TYPEMETADATA: comdat($"??_7D@?A0x{{[^@]*}}@@6BA@@@"), !type [[A8]] +// MS-TYPEMETADATA: comdat($"??_7FA@?1??foo@@YAXXZ@6B@"), !type [[A8]], !type [[FA8:![0-9]+]] struct A { A(); @@ -151,7 +155,7 @@ void D::f() { void D::h() { } -// ITANIUM: define hidden void @_Z2afP1A +// ITANIUM-HIDDEN: define hidden void @_Z2afP1A // ITANIUM-DEFAULTVIS: define{{.*}} void @_Z2afP1A // MS: define dso_local void @"?af@@YAXPEAUA@@@Z" void af(A *a) { @@ -185,7 +189,7 @@ void af(A *a) { a->f(); } -// ITANIUM: define internal void @_Z3df1PN12_GLOBAL__N_11DE +// ITANIUM-HIDDEN: define internal void @_Z3df1PN12_GLOBAL__N_11DE // MS: define internal void @"?df1@@YAXPEAUD@?A0x{{[^@]*}}@@@Z" void df1(D *d) { // TT-ITANIUM-HIDDEN: {{%[^ ]*}} = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata ![[DTYPE:[0-9]+]]) @@ -196,7 +200,7 @@ void df1(D *d) { d->f(); } -// ITANIUM: define internal void @_Z3dg1PN12_GLOBAL__N_11DE +// ITANIUM-HIDDEN: define internal void @_Z3dg1PN12_GLOBAL__N_11DE // MS: define internal void @"?dg1@@YAXPEAUD@?A0x{{[^@]*}}@@@Z" void dg1(D *d) { // TT-ITANIUM-HIDDEN: {{%[^ ]*}} = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"_ZTS1B") @@ -207,7 +211,7 @@ void dg1(D *d) { d->g(); } -// ITANIUM: define internal void @_Z3dh1PN12_GLOBAL__N_11DE +// ITANIUM-HIDDEN: define internal void @_Z3dh1PN12_GLOBAL__N_11DE // MS: define internal void @"?dh1@@YAXPEAUD@?A0x{{[^@]*}}@@@Z" void dh1(D *d) { // TT-ITANIUM-HIDDEN: {{%[^ ]*}} = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata ![[DTYPE]]) @@ -218,7 +222,7 @@ void dh1(D *d) { d->h(); } -// ITANIUM: define internal void @_Z3df2PN12_GLOBAL__N_11DE +// ITANIUM-HIDDEN: define internal void @_Z3df2PN12_GLOBAL__N_11DE // MS: define internal void @"?df2@@YAXPEAUD@?A0x{{[^@]*}}@@@Z" __attribute__((no_sanitize("cfi"))) void df2(D *d) { @@ -228,7 +232,7 @@ void df2(D *d) { d->f(); } -// ITANIUM: define internal void @_Z3df3PN12_GLOBAL__N_11DE +// ITANIUM-HIDDEN: define internal void @_Z3df3PN12_GLOBAL__N_11DE // MS: define internal void @"?df3@@YAXPEAUD@?A0x{{[^@]*}}@@@Z" __attribute__((no_sanitize("address"))) __attribute__((no_sanitize("cfi-vcall"))) void df3(D *d) { @@ -266,7 +270,7 @@ struct D : C { void m_fn1(); }; -// ITANIUM: define hidden void @_ZN5test21fEPNS_1DE +// ITANIUM-HIDDEN: define hidden void @_ZN5test21fEPNS_1DE // ITANIUM-DEFAULTVIS: define{{.*}} void @_ZN5test21fEPNS_1DE // MS: define dso_local void @"?f@test2@@YAXPEAUD@1@@Z" void f(D *d) { @@ -365,9 +369,9 @@ void g() { // RV-OPT-LAYOUT: [[E16]] = !{i64 8, !"_ZTSN5test31EE"} // RV-OPT-LAYOUT: [[EF16]] = !{i64 8, !"_ZTSMN5test31EEFvvE.virtual"} -// MS: [[A8]] = !{i64 8, !"?AUA@@"} -// MS: [[B8]] = !{i64 8, !"?AUB@@"} -// MS: [[D8]] = !{i64 8, [[D_ID:![0-9]+]]} -// MS: [[D_ID]] = distinct !{} -// MS: [[FA8]] = !{i64 8, [[FA_ID:![0-9]+]]} -// MS: [[FA_ID]] = distinct !{} +// MS-TYPEMETADATA: [[A8]] = !{i64 8, !"?AUA@@"} +// MS-TYPEMETADATA: [[B8]] = !{i64 8, !"?AUB@@"} +// MS-TYPEMETADATA: [[D8]] = !{i64 8, [[D_ID:![0-9]+]]} +// MS-TYPEMETADATA: [[D_ID]] = distinct !{} +// MS-TYPEMETADATA: [[FA8]] = !{i64 8, [[FA_ID:![0-9]+]]} +// MS-TYPEMETADATA: [[FA_ID]] = distinct !{} >From 5b53f31c5aa3729f084dd827781ac903c5e655ec Mon Sep 17 00:00:00 2001 From: Mingming Liu <mingmi...@google.com> Date: Tue, 31 Oct 2023 22:00:22 -0700 Subject: [PATCH 2/2] Emit type metadata on vtables if IRPGO instrumentation or profile use is on. - Add test case in clang/test/Driver directory. Undo the change (added in previous commit in this PR) in clang/test/CodeGenCXX/type-metadata.cpp since the test coverage is in clang driver. --- clang/include/clang/Basic/CodeGenOptions.h | 10 ++ clang/lib/CodeGen/CGVTables.cpp | 2 +- clang/lib/CodeGen/MicrosoftCXXABI.cpp | 2 +- clang/test/CodeGenCXX/type-metadata.cpp | 150 ++++++++++---------- clang/test/Driver/Inputs/csirpgo.proftext | 9 ++ clang/test/Driver/Inputs/irpgo.proftext | 8 ++ clang/test/Driver/type-metadata.cpp | 151 +++++++++++++++++++++ 7 files changed, 253 insertions(+), 79 deletions(-) create mode 100644 clang/test/Driver/Inputs/csirpgo.proftext create mode 100644 clang/test/Driver/Inputs/irpgo.proftext create mode 100644 clang/test/Driver/type-metadata.cpp diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h index 12be4e0025a7054..f81bbed65895834 100644 --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -488,6 +488,16 @@ class CodeGenOptions : public CodeGenOptionsBase { return getProfileInstr() == ProfileClangInstr; } + // Returns true if IR level profile instrumentation or use is on; + // returns true for CS IR instrumentation or profile use as well. + bool hasProfileIRInstrOrUse() const { + // For CS IR PGO, hasProfileIRUse is true for both instrumentation + // and profile use. `-fprofile-use` points to IR PGO profiles + // in the former case and points to CS IR PGO profiles in the latter + // case. + return hasProfileIRInstr() || hasProfileIRUse(); + } + /// Check if IR level profile instrumentation is on. bool hasProfileIRInstr() const { return getProfileInstr() == ProfileIRInstr; diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp index 895e160dfa8a536..e8cef3dbf7c4707 100644 --- a/clang/lib/CodeGen/CGVTables.cpp +++ b/clang/lib/CodeGen/CGVTables.cpp @@ -1312,7 +1312,7 @@ llvm::GlobalObject::VCallVisibility CodeGenModule::GetVCallVisibilityLevel( void CodeGenModule::EmitVTableTypeMetadata(const CXXRecordDecl *RD, llvm::GlobalVariable *VTable, const VTableLayout &VTLayout) { - if (!getCodeGenOpts().LTOUnit && !getCodeGenOpts().hasProfileIRInstr()) + if (!getCodeGenOpts().LTOUnit && !getCodeGenOpts().hasProfileIRInstrOrUse()) return; CharUnits ComponentWidth = GetTargetTypeStoreSize(getVTableComponentType()); diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp index 740c0b6cb1aac04..c3500338aca137c 100644 --- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp @@ -1674,7 +1674,7 @@ void MicrosoftCXXABI::emitVTableTypeMetadata(const VPtrInfo &Info, const CXXRecordDecl *RD, llvm::GlobalVariable *VTable) { if (!CGM.getCodeGenOpts().LTOUnit && - !CGM.getCodeGenOpts().hasProfileIRInstr()) + !CGM.getCodeGenOpts().hasProfileIRInstrOrUse()) return; // TODO: Should VirtualFunctionElimination also be supported here? diff --git a/clang/test/CodeGenCXX/type-metadata.cpp b/clang/test/CodeGenCXX/type-metadata.cpp index 637ec6e6c326ab6..3f8b54af801f8d6 100644 --- a/clang/test/CodeGenCXX/type-metadata.cpp +++ b/clang/test/CodeGenCXX/type-metadata.cpp @@ -1,117 +1,113 @@ // Tests for the cfi-vcall feature: -// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG %s -// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-ABORT %s -// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s -// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=MS-TYPEMETADATA --check-prefix=MS --check-prefix=TT-MS --check-prefix=NDIAG %s +// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM --check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG %s +// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM --check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-ABORT %s +// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM --check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s +// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=MS --check-prefix=TT-MS --check-prefix=NDIAG %s // Tests for the whole-program-vtables feature: -// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN %s +// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM --check-prefix=ITANIUM-MD --check-prefix=TT-ITANIUM-HIDDEN %s // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM-DEFAULTVIS --check-prefix=TT-ITANIUM-DEFAULT %s // RUN: %clang_cc1 -O2 -flto -flto-unit -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=ITANIUM-OPT --check-prefix=ITANIUM-OPT-LAYOUT %s -// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=MS-TYPEMETADATA --check-prefix=MS --check-prefix=TT-MS %s +// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=MS --check-prefix=TT-MS %s // Tests for cfi + whole-program-vtables: -// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-VT --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=TC-ITANIUM --check-prefix=ITANIUM-MD %s +// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-VT --check-prefix=ITANIUM --check-prefix=TC-ITANIUM --check-prefix=ITANIUM-MD %s // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-VT --check-prefix=MS --check-prefix=TC-MS %s // Equivalent tests for above, but with relative-vtables. // Tests for the cfi-vcall feature: -// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT --check-prefix=RV-MD --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG --check-prefix=CFI-NVT-RV %s -// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT --check-prefix=CFI-NVT-RV --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=RV-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-DIAG --check-prefix=RV-MD-DIAG --check-prefix=DIAG --check-prefix=DIAG-ABORT %s -// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT --check-prefix=CFI-NVT-RV --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=RV-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-DIAG --check-prefix=RV-MD-DIAG --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s +// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT --check-prefix=RV-MD --check-prefix=ITANIUM --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG --check-prefix=CFI-NVT-RV %s +// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT --check-prefix=CFI-NVT-RV --check-prefix=ITANIUM --check-prefix=RV-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-DIAG --check-prefix=RV-MD-DIAG --check-prefix=DIAG --check-prefix=DIAG-ABORT %s +// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT --check-prefix=CFI-NVT-RV --check-prefix=ITANIUM --check-prefix=RV-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-DIAG --check-prefix=RV-MD-DIAG --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s // Tests for the whole-program-vtables feature: -// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN -check-prefix=RV-MD --check-prefix=TT-ITANIUM-HIDDEN %s +// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM -check-prefix=RV-MD --check-prefix=TT-ITANIUM-HIDDEN %s // RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM-DEFAULTVIS --check-prefix=TT-ITANIUM-DEFAULT %s // RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -O2 -flto -flto-unit -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=ITANIUM-OPT --check-prefix=RV-OPT-LAYOUT %s // Tests for cfi + whole-program-vtables: -// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-VT --check-prefix=ITANIUM-TYPEMETADATA --check-prefix=ITANIUM-HIDDEN --check-prefix=RV-MD --check-prefix=TC-ITANIUM %s +// RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-VT --check-prefix=ITANIUM --check-prefix=RV-MD --check-prefix=TC-ITANIUM %s -// Test that type metadata are emitted with -fprofile-generate -// RUN: %clang -fprofile-generate -fno-lto -target x86_64-unknown-linux -emit-llvm -S %s -o - | FileCheck %s --check-prefix=ITANIUM-TYPEMETADATA -// RUN: %clang -fprofile-generate -fno-lto -target x86_64-pc-windows-msvc -emit-llvm -S %s -o - | FileCheck %s --check-prefix=MS-TYPEMETADATA - -// ITANIUM-TYPEMETADATA: @_ZTV1A = {{[^!]*}}, !type [[A16:![0-9]+]] +// ITANIUM: @_ZTV1A = {{[^!]*}}, !type [[A16:![0-9]+]] // ITANIUM-DIAG-SAME: !type [[ALL16:![0-9]+]] -// ITANIUM-TYPEMETADATA-SAME: !type [[AF16:![0-9]+]] +// ITANIUM-SAME: !type [[AF16:![0-9]+]] -// ITANIUM-TYPEMETADATA: @_ZTV1B = {{[^!]*}}, !type [[A32:![0-9]+]] +// ITANIUM: @_ZTV1B = {{[^!]*}}, !type [[A32:![0-9]+]] // ITANIUM-DIAG-SAME: !type [[ALL32:![0-9]+]] -// ITANIUM-TYPEMETADATA-SAME: !type [[AF32:![0-9]+]] -// ITANIUM-TYPEMETADATA-SAME: !type [[AF40:![0-9]+]] -// ITANIUM-TYPEMETADATA-SAME: !type [[AF48:![0-9]+]] -// ITANIUM-TYPEMETADATA-SAME: !type [[B32:![0-9]+]] +// ITANIUM-SAME: !type [[AF32:![0-9]+]] +// ITANIUM-SAME: !type [[AF40:![0-9]+]] +// ITANIUM-SAME: !type [[AF48:![0-9]+]] +// ITANIUM-SAME: !type [[B32:![0-9]+]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM-TYPEMETADATA-SAME: !type [[BF32:![0-9]+]] -// ITANIUM-TYPEMETADATA-SAME: !type [[BF40:![0-9]+]] -// ITANIUM-TYPEMETADATA-SAME: !type [[BF48:![0-9]+]] +// ITANIUM-SAME: !type [[BF32:![0-9]+]] +// ITANIUM-SAME: !type [[BF40:![0-9]+]] +// ITANIUM-SAME: !type [[BF48:![0-9]+]] -// ITANIUM-TYPEMETADATA: @_ZTV1C = {{[^!]*}}, !type [[A32]] +// ITANIUM: @_ZTV1C = {{[^!]*}}, !type [[A32]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM-TYPEMETADATA-SAME: !type [[AF32]] -// ITANIUM-TYPEMETADATA-SAME: !type [[C32:![0-9]+]] +// ITANIUM-SAME: !type [[AF32]] +// ITANIUM-SAME: !type [[C32:![0-9]+]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM-TYPEMETADATA-SAME: !type [[CF32:![0-9]+]] +// ITANIUM-SAME: !type [[CF32:![0-9]+]] // DIAG: @[[SRC:.*]] = private unnamed_addr constant [{{.*}} x i8] c"{{.*}}type-metadata.cpp\00", align 1 // DIAG: @[[TYPE:.*]] = private unnamed_addr constant { i16, i16, [4 x i8] } { i16 -1, i16 0, [4 x i8] c"'A'\00" } // DIAG: @[[BADTYPESTATIC:.*]] = private unnamed_addr global { i8, { ptr, i32, i32 }, ptr } { i8 0, { ptr, i32, i32 } { ptr @[[SRC]], i32 123, i32 3 }, ptr @[[TYPE]] } -// ITANIUM-TYPEMETADATA: @_ZTVN12_GLOBAL__N_11DE = {{[^!]*}}, !type [[A32]] +// ITANIUM: @_ZTVN12_GLOBAL__N_11DE = {{[^!]*}}, !type [[A32]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM-TYPEMETADATA-SAME: !type [[AF32]] -// ITANIUM-TYPEMETADATA-SAME: !type [[AF40]] -// ITANIUM-TYPEMETADATA-SAME: !type [[AF48]] -// ITANIUM-TYPEMETADATA-SAME: !type [[B32]] +// ITANIUM-SAME: !type [[AF32]] +// ITANIUM-SAME: !type [[AF40]] +// ITANIUM-SAME: !type [[AF48]] +// ITANIUM-SAME: !type [[B32]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM-TYPEMETADATA-SAME: !type [[BF32]] -// ITANIUM-TYPEMETADATA-SAME: !type [[BF40]] -// ITANIUM-TYPEMETADATA-SAME: !type [[BF48]] -// ITANIUM-TYPEMETADATA-SAME: !type [[C88:![0-9]+]] +// ITANIUM-SAME: !type [[BF32]] +// ITANIUM-SAME: !type [[BF40]] +// ITANIUM-SAME: !type [[BF48]] +// ITANIUM-SAME: !type [[C88:![0-9]+]] // ITANIUM-DIAG-SAME: !type [[ALL88:![0-9]+]] -// ITANIUM-TYPEMETADATA-SAME: !type [[CF32]] -// ITANIUM-TYPEMETADATA-SAME: !type [[CF40:![0-9]+]] -// ITANIUM-TYPEMETADATA-SAME: !type [[CF48:![0-9]+]] -// ITANIUM-TYPEMETADATA-SAME: !type [[D32:![0-9]+]] +// ITANIUM-SAME: !type [[CF32]] +// ITANIUM-SAME: !type [[CF40:![0-9]+]] +// ITANIUM-SAME: !type [[CF48:![0-9]+]] +// ITANIUM-SAME: !type [[D32:![0-9]+]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM-TYPEMETADATA-SAME: !type [[DF32:![0-9]+]] -// ITANIUM-TYPEMETADATA-SAME: !type [[DF40:![0-9]+]] -// ITANIUM-TYPEMETADATA-SAME: !type [[DF48:![0-9]+]] +// ITANIUM-SAME: !type [[DF32:![0-9]+]] +// ITANIUM-SAME: !type [[DF40:![0-9]+]] +// ITANIUM-SAME: !type [[DF48:![0-9]+]] -// ITANIUM-TYPEMETADATA: @_ZTCN12_GLOBAL__N_11DE0_1B = {{[^!]*}}, !type [[A32]] +// ITANIUM: @_ZTCN12_GLOBAL__N_11DE0_1B = {{[^!]*}}, !type [[A32]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM-TYPEMETADATA-SAME: !type [[B32]] +// ITANIUM-SAME: !type [[B32]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM-TYPEMETADATA: @_ZTCN12_GLOBAL__N_11DE8_1C = {{[^!]*}}, !type [[A64:![0-9]+]] +// ITANIUM: @_ZTCN12_GLOBAL__N_11DE8_1C = {{[^!]*}}, !type [[A64:![0-9]+]] // ITANIUM-DIAG-SAME: !type [[ALL64:![0-9]+]] -// ITANIUM-TYPEMETADATA-SAME: !type [[AF64:![0-9]+]] -// ITANIUM-TYPEMETADATA-SAME: !type [[C32]] +// ITANIUM-SAME: !type [[AF64:![0-9]+]] +// ITANIUM-SAME: !type [[C32]] // ITANIUM-DIAG-SAME: !type [[ALL32]] -// ITANIUM-TYPEMETADATA-SAME: !type [[CF64:![0-9]+]] +// ITANIUM-SAME: !type [[CF64:![0-9]+]] -// ITANIUM-TYPEMETADATA: @_ZTVZ3foovE2FA = {{[^!]*}}, !type [[A16]] +// ITANIUM: @_ZTVZ3foovE2FA = {{[^!]*}}, !type [[A16]] // ITANIUM-DIAG-SAME: !type [[ALL16]] -// ITANIUM-TYPEMETADATA-SAME: !type [[AF16]] -// ITANIUM-TYPEMETADATA-SAME: !type [[FA16:![0-9]+]] +// ITANIUM-SAME: !type [[AF16]] +// ITANIUM-SAME: !type [[FA16:![0-9]+]] // ITANIUM-DIAG-SAME: !type [[ALL16]] -// ITANIUM-TYPEMETADATA-SAME: !type [[FAF16:![0-9]+]] +// ITANIUM-SAME: !type [[FAF16:![0-9]+]] -// ITANIUM-TYPEMETADATA: @_ZTVN5test31EE = external unnamed_addr constant +// ITANIUM: @_ZTVN5test31EE = external unnamed_addr constant // ITANIUM-DEFAULTVIS: @_ZTVN5test31EE = external unnamed_addr constant // ITANIUM-OPT: @_ZTVN5test31EE = available_externally unnamed_addr constant {{[^!]*}}, // ITANIUM-OPT-SAME: !type [[E16:![0-9]+]], // ITANIUM-OPT-SAME: !type [[EF16:![0-9]+]] // ITANIUM-OPT: @llvm.compiler.used = appending global [1 x ptr] [ptr @_ZTVN5test31EE] -// MS-TYPEMETADATA: comdat($"??_7A@@6B@"), !type [[A8:![0-9]+]] -// MS-TYPEMETADATA: comdat($"??_7B@@6B0@@"), !type [[B8:![0-9]+]] -// MS-TYPEMETADATA: comdat($"??_7B@@6BA@@@"), !type [[A8]] -// MS-TYPEMETADATA: comdat($"??_7C@@6B@"), !type [[A8]] -// MS-TYPEMETADATA: comdat($"??_7D@?A0x{{[^@]*}}@@6BB@@@"), !type [[B8]], !type [[D8:![0-9]+]] -// MS-TYPEMETADATA: comdat($"??_7D@?A0x{{[^@]*}}@@6BA@@@"), !type [[A8]] -// MS-TYPEMETADATA: comdat($"??_7FA@?1??foo@@YAXXZ@6B@"), !type [[A8]], !type [[FA8:![0-9]+]] +// MS: comdat($"??_7A@@6B@"), !type [[A8:![0-9]+]] +// MS: comdat($"??_7B@@6B0@@"), !type [[B8:![0-9]+]] +// MS: comdat($"??_7B@@6BA@@@"), !type [[A8]] +// MS: comdat($"??_7C@@6B@"), !type [[A8]] +// MS: comdat($"??_7D@?A0x{{[^@]*}}@@6BB@@@"), !type [[B8]], !type [[D8:![0-9]+]] +// MS: comdat($"??_7D@?A0x{{[^@]*}}@@6BA@@@"), !type [[A8]] +// MS: comdat($"??_7FA@?1??foo@@YAXXZ@6B@"), !type [[A8]], !type [[FA8:![0-9]+]] struct A { A(); @@ -155,7 +151,7 @@ void D::f() { void D::h() { } -// ITANIUM-HIDDEN: define hidden void @_Z2afP1A +// ITANIUM: define hidden void @_Z2afP1A // ITANIUM-DEFAULTVIS: define{{.*}} void @_Z2afP1A // MS: define dso_local void @"?af@@YAXPEAUA@@@Z" void af(A *a) { @@ -189,7 +185,7 @@ void af(A *a) { a->f(); } -// ITANIUM-HIDDEN: define internal void @_Z3df1PN12_GLOBAL__N_11DE +// ITANIUM: define internal void @_Z3df1PN12_GLOBAL__N_11DE // MS: define internal void @"?df1@@YAXPEAUD@?A0x{{[^@]*}}@@@Z" void df1(D *d) { // TT-ITANIUM-HIDDEN: {{%[^ ]*}} = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata ![[DTYPE:[0-9]+]]) @@ -200,7 +196,7 @@ void df1(D *d) { d->f(); } -// ITANIUM-HIDDEN: define internal void @_Z3dg1PN12_GLOBAL__N_11DE +// ITANIUM: define internal void @_Z3dg1PN12_GLOBAL__N_11DE // MS: define internal void @"?dg1@@YAXPEAUD@?A0x{{[^@]*}}@@@Z" void dg1(D *d) { // TT-ITANIUM-HIDDEN: {{%[^ ]*}} = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"_ZTS1B") @@ -211,7 +207,7 @@ void dg1(D *d) { d->g(); } -// ITANIUM-HIDDEN: define internal void @_Z3dh1PN12_GLOBAL__N_11DE +// ITANIUM: define internal void @_Z3dh1PN12_GLOBAL__N_11DE // MS: define internal void @"?dh1@@YAXPEAUD@?A0x{{[^@]*}}@@@Z" void dh1(D *d) { // TT-ITANIUM-HIDDEN: {{%[^ ]*}} = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata ![[DTYPE]]) @@ -222,7 +218,7 @@ void dh1(D *d) { d->h(); } -// ITANIUM-HIDDEN: define internal void @_Z3df2PN12_GLOBAL__N_11DE +// ITANIUM: define internal void @_Z3df2PN12_GLOBAL__N_11DE // MS: define internal void @"?df2@@YAXPEAUD@?A0x{{[^@]*}}@@@Z" __attribute__((no_sanitize("cfi"))) void df2(D *d) { @@ -232,7 +228,7 @@ void df2(D *d) { d->f(); } -// ITANIUM-HIDDEN: define internal void @_Z3df3PN12_GLOBAL__N_11DE +// ITANIUM: define internal void @_Z3df3PN12_GLOBAL__N_11DE // MS: define internal void @"?df3@@YAXPEAUD@?A0x{{[^@]*}}@@@Z" __attribute__((no_sanitize("address"))) __attribute__((no_sanitize("cfi-vcall"))) void df3(D *d) { @@ -270,7 +266,7 @@ struct D : C { void m_fn1(); }; -// ITANIUM-HIDDEN: define hidden void @_ZN5test21fEPNS_1DE +// ITANIUM: define hidden void @_ZN5test21fEPNS_1DE // ITANIUM-DEFAULTVIS: define{{.*}} void @_ZN5test21fEPNS_1DE // MS: define dso_local void @"?f@test2@@YAXPEAUD@1@@Z" void f(D *d) { @@ -369,9 +365,9 @@ void g() { // RV-OPT-LAYOUT: [[E16]] = !{i64 8, !"_ZTSN5test31EE"} // RV-OPT-LAYOUT: [[EF16]] = !{i64 8, !"_ZTSMN5test31EEFvvE.virtual"} -// MS-TYPEMETADATA: [[A8]] = !{i64 8, !"?AUA@@"} -// MS-TYPEMETADATA: [[B8]] = !{i64 8, !"?AUB@@"} -// MS-TYPEMETADATA: [[D8]] = !{i64 8, [[D_ID:![0-9]+]]} -// MS-TYPEMETADATA: [[D_ID]] = distinct !{} -// MS-TYPEMETADATA: [[FA8]] = !{i64 8, [[FA_ID:![0-9]+]]} -// MS-TYPEMETADATA: [[FA_ID]] = distinct !{} +// MS: [[A8]] = !{i64 8, !"?AUA@@"} +// MS: [[B8]] = !{i64 8, !"?AUB@@"} +// MS: [[D8]] = !{i64 8, [[D_ID:![0-9]+]]} +// MS: [[D_ID]] = distinct !{} +// MS: [[FA8]] = !{i64 8, [[FA_ID:![0-9]+]]} +// MS: [[FA_ID]] = distinct !{} diff --git a/clang/test/Driver/Inputs/csirpgo.proftext b/clang/test/Driver/Inputs/csirpgo.proftext new file mode 100644 index 000000000000000..f2f3658c5c8e839 --- /dev/null +++ b/clang/test/Driver/Inputs/csirpgo.proftext @@ -0,0 +1,9 @@ +# CSIR level Instrumentation Flag +:csir +foo +# Func Hash: +742261418966908927 +# Num Counters: +1 +# Counter Values: +1 \ No newline at end of file diff --git a/clang/test/Driver/Inputs/irpgo.proftext b/clang/test/Driver/Inputs/irpgo.proftext new file mode 100644 index 000000000000000..205dc1c7deaa900 --- /dev/null +++ b/clang/test/Driver/Inputs/irpgo.proftext @@ -0,0 +1,8 @@ +:ir +foo +# Func Hash: +742261418966908927 +# Num Counters: +1 +# Counter Values: +1 diff --git a/clang/test/Driver/type-metadata.cpp b/clang/test/Driver/type-metadata.cpp new file mode 100644 index 000000000000000..47aca345d449bad --- /dev/null +++ b/clang/test/Driver/type-metadata.cpp @@ -0,0 +1,151 @@ +// Test that type metadata are emitted with -fprofile-generate +// +// RUN: %clang -fprofile-generate -fno-lto -target x86_64-unknown-linux -emit-llvm -S %s -o - | FileCheck %s --check-prefix=ITANIUM +// RUN: %clang -fprofile-generate -fno-lto -target x86_64-pc-windows-msvc -emit-llvm -S %s -o - | FileCheck %s --check-prefix=MS + +// Test that type metadata are emitted with -fprofile-use +// +// RUN: llvm-profdata merge %S/Inputs/irpgo.proftext -o %t-ir.profdata +// RUN: %clang -fprofile-use=%t-ir.profdata -fno-lto -target x86_64-unknown-linux -emit-llvm -S %s -o - | FileCheck %s --check-prefix=ITANIUM +// RUN: %clang -fprofile-use=%t-ir.profdata -fno-lto -target x86_64-pc-windows-msvc -emit-llvm -S %s -o - | FileCheck %s --check-prefix=MS + +// ITANIUM: @_ZTV1A = {{[^!]*}}, !type [[A16:![0-9]+]] +// ITANIUM-SAME: !type [[AF16:![0-9]+]] + +// ITANIUM: @_ZTV1B = {{[^!]*}}, !type [[A32:![0-9]+]] +// ITANIUM-SAME: !type [[AF32:![0-9]+]] +// ITANIUM-SAME: !type [[AF40:![0-9]+]] +// ITANIUM-SAME: !type [[AF48:![0-9]+]] +// ITANIUM-SAME: !type [[B32:![0-9]+]] +// ITANIUM-SAME: !type [[BF32:![0-9]+]] +// ITANIUM-SAME: !type [[BF40:![0-9]+]] +// ITANIUM-SAME: !type [[BF48:![0-9]+]] + +// ITANIUM: @_ZTV1C = {{[^!]*}}, !type [[A32]] +// ITANIUM-SAME: !type [[AF32]] +// ITANIUM-SAME: !type [[C32:![0-9]+]] +// ITANIUM-SAME: !type [[CF32:![0-9]+]] + +// ITANIUM: @_ZTVN12_GLOBAL__N_11DE = {{[^!]*}}, !type [[A32]] +// ITANIUM-SAME: !type [[AF32]] +// ITANIUM-SAME: !type [[AF40]] +// ITANIUM-SAME: !type [[AF48]] +// ITANIUM-SAME: !type [[B32]] +// ITANIUM-SAME: !type [[BF32]] +// ITANIUM-SAME: !type [[BF40]] +// ITANIUM-SAME: !type [[BF48]] +// ITANIUM-SAME: !type [[C88:![0-9]+]] +// ITANIUM-SAME: !type [[CF32]] +// ITANIUM-SAME: !type [[CF40:![0-9]+]] +// ITANIUM-SAME: !type [[CF48:![0-9]+]] +// ITANIUM-SAME: !type [[D32:![0-9]+]] +// ITANIUM-SAME: !type [[DF32:![0-9]+]] +// ITANIUM-SAME: !type [[DF40:![0-9]+]] +// ITANIUM-SAME: !type [[DF48:![0-9]+]] + +// ITANIUM: @_ZTCN12_GLOBAL__N_11DE0_1B = {{[^!]*}}, !type [[A32]] +// ITANIUM-SAME: !type [[B32]] + +// ITANIUM: @_ZTCN12_GLOBAL__N_11DE8_1C = {{[^!]*}}, !type [[A64:![0-9]+]] +// ITANIUM-SAME: !type [[AF64:![0-9]+]] +// ITANIUM-SAME: !type [[C32]] +// ITANIUM-SAME: !type [[CF64:![0-9]+]] + +// ITANIUM: @_ZTVZ3foovE2FA = {{[^!]*}}, !type [[A16]] +// ITANIUM-SAME: !type [[AF16]] +// ITANIUM-SAME: !type [[FA16:![0-9]+]] +// ITANIUM-SAME: !type [[FAF16:![0-9]+]] + +// MS: comdat($"??_7A@@6B@"), !type [[A8:![0-9]+]] +// MS: comdat($"??_7B@@6B0@@"), !type [[B8:![0-9]+]] +// MS: comdat($"??_7B@@6BA@@@"), !type [[A8]] +// MS: comdat($"??_7C@@6B@"), !type [[A8]] +// MS: comdat($"??_7D@?A0x{{[^@]*}}@@6BB@@@"), !type [[B8]], !type [[D8:![0-9]+]] +// MS: comdat($"??_7D@?A0x{{[^@]*}}@@6BA@@@"), !type [[A8]] +// MS: comdat($"??_7FA@?1??foo@@YAXXZ@6B@"), !type [[A8]], !type [[FA8:![0-9]+]] + +struct A { + A(); + virtual void f(); +}; + +struct B : virtual A { + B(); + virtual void g(); + virtual void h(); +}; + +struct C : virtual A { + C(); +}; + +namespace { + +struct D : B, C { + D(); + virtual void f(); + virtual void h(); +}; + +} + +A::A() {} +B::B() {} +C::C() {} +D::D() {} + +void A::f() { +} + +void B::g() { +} + +void D::f() { +} + +void D::h() { +} + +void af(A *a) { + a->f(); +} + +void df1(D *d) { + + d->f(); +} + +void dg1(D *d) { + + d->g(); +} + +void dh1(D *d) { + + d->h(); +} + +void df2(D *d) { + + d->f(); +} + +void df3(D *d) { + + d->f(); +} + +D d; + +void foo() { + df1(&d); + dg1(&d); + dh1(&d); + df2(&d); + df3(&d); + + struct FA : A { + void f() {} + } fa; + af(&fa); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits