forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "[clang] Add experimental option to omit the RTTI comp…
…onent from the vtable when -fno-rtti is used"" This attempts to reland 6385c1d but with a fix for the test failure.
- Loading branch information
Showing
11 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
clang/test/CodeGenCXX/OmitRTTIComponentABI/simple-vtable-definition.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/// Check that -fexperimental-omit-vtable-rtti omits the RTTI component from | ||
/// the vtable. | ||
|
||
// RUN: %clang_cc1 %s -triple=aarch64-unknown-linux-gnu -fno-rtti -fexperimental-omit-vtable-rtti -S -o - -emit-llvm | FileCheck -check-prefixes=POINTER,RTTI %s | ||
// RUN: %clang_cc1 %s -triple=aarch64-unknown-linux-gnu -fexperimental-relative-c++-abi-vtables -fno-rtti -fexperimental-omit-vtable-rtti -S -o - -emit-llvm | FileCheck -check-prefixes=RELATIVE,RTTI %s | ||
|
||
/// Normally, the vtable would contain at least three components: | ||
/// - An offset to top | ||
/// - A pointer to the RTTI struct | ||
/// - A virtual function | ||
/// | ||
/// Now vtables should have just two components. | ||
// POINTER: @_ZTV1A = unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr null, ptr @_ZN1A3fooEv] }, align 8 | ||
// RELATIVE: @_ZTV1A.local = private unnamed_addr constant { [2 x i32] } { [2 x i32] [i32 0, i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @_ZN1A3fooEv to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [2 x i32] }, ptr @_ZTV1A.local, i32 0, i32 0, i32 1) to i64)) to i32)] }, align 4 | ||
// RELATIVE: @_ZTV1A = unnamed_addr alias { [2 x i32] }, ptr @_ZTV1A.local | ||
|
||
/// None of these supplementary symbols should be emitted with -fno-rtti, but | ||
/// as a sanity check lets make sure they're not emitted also. | ||
// RTTI-NOT: @_ZTVN10__cxxabiv117__class_type_infoE | ||
// RTTI-NOT: @_ZTS1A | ||
// RTTI-NOT: @_ZTI1A | ||
|
||
class A { | ||
public: | ||
virtual void foo(); | ||
}; | ||
|
||
void A::foo() {} | ||
|
||
void A_foo(A *a) { | ||
a->foo(); | ||
} |
51 changes: 51 additions & 0 deletions
51
clang/test/CodeGenCXX/OmitRTTIComponentABI/vbase-offset.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/// Check that the offset to top calculation is adjusted to account for the | ||
/// omitted RTTI entry. | ||
|
||
// RUN: %clang_cc1 %s -triple=aarch64-unknown-linux-gnu -fexperimental-omit-vtable-rtti -fno-rtti -S -o - -emit-llvm | FileCheck -check-prefixes=POINTER %s | ||
// RUN: %clang_cc1 %s -triple=aarch64-unknown-linux-gnu -fexperimental-relative-c++-abi-vtables -fexperimental-omit-vtable-rtti -fno-rtti -S -o - -emit-llvm | FileCheck -check-prefixes=RELATIVE %s | ||
|
||
/// Some important things to check: | ||
/// - The n16 here represents the virtual thunk size. Normally this would be 24 | ||
/// to represent 3 components (offset to top, RTTI component, vcall offset), | ||
/// but since one 8-byte component is removed, this is now 16. | ||
// POINTER-LABEL: @_ZTv0_n16_N7Derived1fEi( | ||
// POINTER-NEXT: entry: | ||
// POINTER: [[vtable:%.+]] = load ptr, ptr %this1, align 8 | ||
|
||
/// Same here - When getting the vbase offset, we subtract 2 pointer sizes | ||
/// instead of 3. | ||
// POINTER-NEXT: [[vbase_offset_ptr:%.+]] = getelementptr inbounds i8, ptr [[vtable]], i64 -16 | ||
// POINTER-NEXT: [[vbase_offset:%.+]] = load i64, ptr [[vbase_offset_ptr]], align 8 | ||
// POINTER-NEXT: [[adj_this:%.+]] = getelementptr inbounds i8, ptr %this1, i64 [[vbase_offset]] | ||
// POINTER: [[call:%.+]] = tail call noundef i32 @_ZN7Derived1fEi(ptr noundef{{[^,]*}} [[adj_this]], i32 noundef {{.*}}) | ||
// POINTER: ret i32 [[call]] | ||
|
||
/// For relative vtables, it's almost the same except the offset sizes are | ||
/// halved. | ||
// RELATIVE-LABEL: @_ZTv0_n8_N7Derived1fEi( | ||
// RELATIVE-NEXT: entry: | ||
// RELATIVE: [[vtable:%.+]] = load ptr, ptr %this1, align 8 | ||
// RELATIVE-NEXT: [[vbase_offset_ptr:%.+]] = getelementptr inbounds i8, ptr [[vtable]], i64 -8 | ||
// RELATIVE-NEXT: [[vbase_offset:%.+]] = load i32, ptr [[vbase_offset_ptr]], align 4 | ||
// RELATIVE-NEXT: [[adj_this:%.+]] = getelementptr inbounds i8, ptr %this1, i32 [[vbase_offset]] | ||
// RELATIVE: [[call:%.+]] = tail call noundef i32 @_ZN7Derived1fEi(ptr noundef{{[^,]*}} [[adj_this]], i32 noundef {{.*}}) | ||
// RELATIVE: ret i32 [[call]] | ||
|
||
class Base { | ||
public: | ||
virtual int f(int x); | ||
|
||
private: | ||
long x; | ||
}; | ||
|
||
class Derived : public virtual Base { | ||
public: | ||
virtual int f(int x); | ||
|
||
private: | ||
long y; | ||
}; | ||
|
||
int Base::f(int x) { return x + 1; } | ||
int Derived::f(int x) { return x + 2; } |
19 changes: 19 additions & 0 deletions
19
clang/test/CodeGenCXX/OmitRTTIComponentABI/vtable-layout.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/// Ensure -fdump-vtable-layout omits the rtti component when passed -fexperimental-omit-vtable-rtti. | ||
|
||
// RUN: %clang_cc1 %s -triple=aarch64-unknown-linux-gnu -fno-rtti -fexperimental-omit-vtable-rtti -emit-llvm-only -fdump-vtable-layouts | FileCheck %s | ||
|
||
// CHECK: Vtable for 'A' (2 entries). | ||
// CHECK-NEXT: 0 | offset_to_top (0) | ||
// CHECK-NEXT: -- (A, 0) vtable address -- | ||
// CHECK-NEXT: 1 | void A::foo() | ||
|
||
class A { | ||
public: | ||
virtual void foo(); | ||
}; | ||
|
||
void A::foo() {} | ||
|
||
void A_foo(A *a) { | ||
a->foo(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// RUN: %clangxx --target=aarch64-unknown-linux -fno-rtti -Xclang -fexperimental-omit-vtable-rtti -c %s -### 2>&1 | FileCheck %s --check-prefix=OMIT | ||
// RUN: %clangxx --target=aarch64-unknown-linux -fno-rtti -Xclang -fno-experimental-omit-vtable-rtti -c %s -### 2>&1 | FileCheck %s --check-prefix=NO-OMIT | ||
|
||
// OMIT: "-fexperimental-omit-vtable-rtti" | ||
// NO-OMIT-NOT: "-fexperimental-omit-vtable-rtti" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/// Ensure that -fexperimental-omit-vtable-rtti is only allowed if rtti is | ||
/// disabled. | ||
|
||
// UNSUPPORTED: system-windows | ||
|
||
// RUN: not %clang -c -Xclang -fexperimental-omit-vtable-rtti %s 2>&1 | FileCheck -check-prefix=ERROR %s | ||
// RUN: not %clang -c -Xclang -fexperimental-omit-vtable-rtti -frtti %s 2>&1 | FileCheck -check-prefix=ERROR %s | ||
// RUN: not %clang -c -Xclang -fexperimental-omit-vtable-rtti -fno-rtti -frtti %s 2>&1 | FileCheck -check-prefix=ERROR %s | ||
|
||
// RUN: %clang -c -Xclang -fexperimental-omit-vtable-rtti -fno-rtti %s 2>&1 | FileCheck -check-prefix=NO-ERROR %s --allow-empty | ||
// RUN: %clang -c -Xclang -fno-experimental-omit-vtable-rtti -frtti %s 2>&1 | FileCheck -check-prefix=NO-ERROR %s --allow-empty | ||
// RUN: %clang -c -Xclang -fexperimental-omit-vtable-rtti -Xclang -fno-experimental-omit-vtable-rtti -frtti %s 2>&1 | FileCheck -check-prefix=NO-ERROR %s --allow-empty | ||
|
||
// ERROR: -fexperimental-omit-vtable-rtti call only be used with -fno-rtti | ||
// NO-ERROR-NOT: -fexperimental-omit-vtable-rtti call only be used with -fno-rtti |