
This corrects the codegen for the final class optimization to correct handle the case where there is no path to perform the cast, and also corrects the codegen to handle ptrauth protected vtable pointers. As part of this fix we separate out the path computation as that makes it easier to reason about the failure code paths and more importantly means we can know what the type of the this object is during the cast. The allows us to use the GetVTablePointer interface which correctly performs the authentication operations required when pointer authentication is enabled. This still leaves incorrect authentication behavior in the multiple inheritance case but currently the optimization is disabled entirely if pointer authentication is enabled. Fixes #137518
33 lines
1.3 KiB
C++
33 lines
1.3 KiB
C++
// RUN: %clang_cc1 -I%S %s -triple x86_64-apple-darwin10 -O1 -emit-llvm -std=c++11 -o - | FileCheck %s --check-prefixes=CHECK,EXACT
|
|
// RUN: %clang_cc1 -I%S %s -triple x86_64-apple-darwin10 -O0 -emit-llvm -std=c++11 -o - | FileCheck %s --check-prefixes=CHECK,INEXACT
|
|
// RUN: %clang_cc1 -I%S %s -triple x86_64-apple-darwin10 -O1 -fvisibility=hidden -emit-llvm -std=c++11 -o - | FileCheck %s --check-prefixes=CHECK,INEXACT
|
|
// RUN: %clang_cc1 -I%S %s -triple x86_64-apple-darwin10 -O1 -fapple-kext -emit-llvm -std=c++11 -o - | FileCheck %s --check-prefixes=CHECK,INEXACT
|
|
// RUN: %clang_cc1 -I%S %s -triple x86_64-apple-darwin10 -O1 -fno-assume-unique-vtables -emit-llvm -std=c++11 -o - | FileCheck %s --check-prefixes=CHECK,INEXACT
|
|
// RUN: %clang_cc1 -I%S %s -triple arm64e-apple-darwin10 -O1 -fptrauth-calls -emit-llvm -std=c++11 -o - | FileCheck %s --check-prefixes=CHECK,INEXACT
|
|
|
|
struct A { virtual ~A(); };
|
|
struct B final : A { };
|
|
|
|
// CHECK-LABEL: @_Z5exactP1A
|
|
B *exact(A *a) {
|
|
// INEXACT: call {{.*}} @__dynamic_cast
|
|
// EXACT-NOT: call {{.*}} @__dynamic_cast
|
|
return dynamic_cast<B*>(a);
|
|
}
|
|
|
|
struct C {
|
|
virtual ~C();
|
|
};
|
|
|
|
struct D final : private C {
|
|
|
|
};
|
|
|
|
// CHECK-LABEL: @_Z5exactP1C
|
|
D *exact(C *a) {
|
|
// INEXACT: call {{.*}} @__dynamic_cast
|
|
// EXACT: entry:
|
|
// EXACT-NEXT: ret ptr null
|
|
return dynamic_cast<D*>(a);
|
|
}
|