[PATCH] D115015: CodeGen: Strip exception specifications from function types in CFI type names.

2021-12-03 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

I patched this in and verified that it fixes the make_top_domain_list_variables 
issue in https://bugs.chromium.org/p/chromium/issues/detail?id=1273966 and went 
ahead and landed this. Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115015/new/

https://reviews.llvm.org/D115015

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115015: CodeGen: Strip exception specifications from function types in CFI type names.

2021-12-03 Thread Nico Weber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0a14674f276b: CodeGen: Strip exception specifications from 
function types in CFI type names. (authored by pcc, committed by thakis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115015/new/

https://reviews.llvm.org/D115015

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCXX/cfi-icall-noexcept.cpp


Index: clang/test/CodeGenCXX/cfi-icall-noexcept.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cfi-icall-noexcept.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall 
-emit-llvm -std=c++17 -o - %s | FileCheck %s
+
+// Tests that exception specifiers are stripped when forming the
+// mangled CFI type name.
+
+void f() noexcept {}
+
+// CHECK: define{{.*}} void @_Z1fv({{.*}} !type [[TS1:![0-9]+]] !type 
[[TS2:![0-9]+]]
+
+// CHECK: [[TS1]] = !{i64 0, !"_ZTSFvvE"}
+// CHECK: [[TS2]] = !{i64 0, !"_ZTSFvvE.generalized"}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -6398,6 +6398,11 @@
 llvm::Metadata *
 CodeGenModule::CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
 StringRef Suffix) {
+  if (auto *FnType = T->getAs())
+T = getContext().getFunctionType(
+FnType->getReturnType(), FnType->getParamTypes(),
+FnType->getExtProtoInfo().withExceptionSpec(EST_None));
+
   llvm::Metadata *&InternalId = Map[T.getCanonicalType()];
   if (InternalId)
 return InternalId;


Index: clang/test/CodeGenCXX/cfi-icall-noexcept.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cfi-icall-noexcept.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall -emit-llvm -std=c++17 -o - %s | FileCheck %s
+
+// Tests that exception specifiers are stripped when forming the
+// mangled CFI type name.
+
+void f() noexcept {}
+
+// CHECK: define{{.*}} void @_Z1fv({{.*}} !type [[TS1:![0-9]+]] !type [[TS2:![0-9]+]]
+
+// CHECK: [[TS1]] = !{i64 0, !"_ZTSFvvE"}
+// CHECK: [[TS2]] = !{i64 0, !"_ZTSFvvE.generalized"}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -6398,6 +6398,11 @@
 llvm::Metadata *
 CodeGenModule::CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
 StringRef Suffix) {
+  if (auto *FnType = T->getAs())
+T = getContext().getFunctionType(
+FnType->getReturnType(), FnType->getParamTypes(),
+FnType->getExtProtoInfo().withExceptionSpec(EST_None));
+
   llvm::Metadata *&InternalId = Map[T.getCanonicalType()];
   if (InternalId)
 return InternalId;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115015: CodeGen: Strip exception specifications from function types in CFI type names.

2021-12-03 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

lg


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115015/new/

https://reviews.llvm.org/D115015

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115015: CodeGen: Strip exception specifications from function types in CFI type names.

2021-12-02 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc created this revision.
pcc added a reviewer: eugenis.
pcc requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

With C++17 the exception specification has been made part of the
function type, and therefore part of mangled type names.

However, it's valid to convert function pointers with an exception
specification to function pointers with the same argument and return
types but without an exception specification, which means that e.g. a
function of type "void () noexcept" can be called through a pointer
of type "void ()". We must therefore consider the two types to be
compatible for CFI purposes.

We can do this by stripping the exception specification before mangling
the type name, which is what this patch does.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115015

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCXX/cfi-icall-noexcept.cpp


Index: clang/test/CodeGenCXX/cfi-icall-noexcept.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cfi-icall-noexcept.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall 
-emit-llvm -std=c++17 -o - %s | FileCheck %s
+
+// Tests that exception specifiers are stripped when forming the
+// mangled CFI type name.
+
+void f() noexcept {}
+
+// CHECK: define{{.*}} void @_Z1fv({{.*}} !type [[TS1:![0-9]+]] !type 
[[TS2:![0-9]+]]
+
+// CHECK: [[TS1]] = !{i64 0, !"_ZTSFvvE"}
+// CHECK: [[TS2]] = !{i64 0, !"_ZTSFvvE.generalized"}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -6398,6 +6398,11 @@
 llvm::Metadata *
 CodeGenModule::CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
 StringRef Suffix) {
+  if (auto *FnType = T->getAs())
+T = getContext().getFunctionType(
+FnType->getReturnType(), FnType->getParamTypes(),
+FnType->getExtProtoInfo().withExceptionSpec(EST_None));
+
   llvm::Metadata *&InternalId = Map[T.getCanonicalType()];
   if (InternalId)
 return InternalId;


Index: clang/test/CodeGenCXX/cfi-icall-noexcept.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cfi-icall-noexcept.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall -emit-llvm -std=c++17 -o - %s | FileCheck %s
+
+// Tests that exception specifiers are stripped when forming the
+// mangled CFI type name.
+
+void f() noexcept {}
+
+// CHECK: define{{.*}} void @_Z1fv({{.*}} !type [[TS1:![0-9]+]] !type [[TS2:![0-9]+]]
+
+// CHECK: [[TS1]] = !{i64 0, !"_ZTSFvvE"}
+// CHECK: [[TS2]] = !{i64 0, !"_ZTSFvvE.generalized"}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -6398,6 +6398,11 @@
 llvm::Metadata *
 CodeGenModule::CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
 StringRef Suffix) {
+  if (auto *FnType = T->getAs())
+T = getContext().getFunctionType(
+FnType->getReturnType(), FnType->getParamTypes(),
+FnType->getExtProtoInfo().withExceptionSpec(EST_None));
+
   llvm::Metadata *&InternalId = Map[T.getCanonicalType()];
   if (InternalId)
 return InternalId;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits