OCaml 4.14.0 rebuild: ocaml-ctypes 0.20.1-1
[arch-packages.git] / clang13 / trunk / strip-exception-specifications-in-CFI-type-names.patch
blob2de6ba637d7cf45a6af4a4755b9cf1641456beec
1 From 0a14674f276b598d23353290635fc62f93e9ab30 Mon Sep 17 00:00:00 2001
2 From: Peter Collingbourne <peter@pcc.me.uk>
3 Date: Fri, 3 Dec 2021 14:48:57 -0500
4 Subject: [PATCH] CodeGen: Strip exception specifications from function types
5 in CFI type names.
7 With C++17 the exception specification has been made part of the
8 function type, and therefore part of mangled type names.
10 However, it's valid to convert function pointers with an exception
11 specification to function pointers with the same argument and return
12 types but without an exception specification, which means that e.g. a
13 function of type "void () noexcept" can be called through a pointer
14 of type "void ()". We must therefore consider the two types to be
15 compatible for CFI purposes.
17 We can do this by stripping the exception specification before mangling
18 the type name, which is what this patch does.
20 Differential Revision: https://reviews.llvm.org/D115015
21 ---
22 clang/lib/CodeGen/CodeGenModule.cpp | 5 +++++
23 clang/test/CodeGenCXX/cfi-icall-noexcept.cpp | 11 +++++++++++
24 2 files changed, 16 insertions(+)
25 create mode 100644 clang/test/CodeGenCXX/cfi-icall-noexcept.cpp
27 diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
28 index 9ba1a5c25e81a..39044617d6774 100644
29 --- a/clang/lib/CodeGen/CodeGenModule.cpp
30 +++ b/clang/lib/CodeGen/CodeGenModule.cpp
31 @@ -6398,6 +6398,11 @@ void CodeGenModule::EmitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
32 llvm::Metadata *
33 CodeGenModule::CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
34 StringRef Suffix) {
35 + if (auto *FnType = T->getAs<FunctionProtoType>())
36 + T = getContext().getFunctionType(
37 + FnType->getReturnType(), FnType->getParamTypes(),
38 + FnType->getExtProtoInfo().withExceptionSpec(EST_None));
40 llvm::Metadata *&InternalId = Map[T.getCanonicalType()];
41 if (InternalId)
42 return InternalId;
43 diff --git a/clang/test/CodeGenCXX/cfi-icall-noexcept.cpp b/clang/test/CodeGenCXX/cfi-icall-noexcept.cpp
44 new file mode 100644
45 index 0000000000000..eabc4862b4c52
46 --- /dev/null
47 +++ b/clang/test/CodeGenCXX/cfi-icall-noexcept.cpp
48 @@ -0,0 +1,11 @@
49 +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall -emit-llvm -std=c++17 -o - %s | FileCheck %s
51 +// Tests that exception specifiers are stripped when forming the
52 +// mangled CFI type name.
54 +void f() noexcept {}
56 +// CHECK: define{{.*}} void @_Z1fv({{.*}} !type [[TS1:![0-9]+]] !type [[TS2:![0-9]+]]
58 +// CHECK: [[TS1]] = !{i64 0, !"_ZTSFvvE"}
59 +// CHECK: [[TS2]] = !{i64 0, !"_ZTSFvvE.generalized"}