https://github.com/konstantinschwarz created
https://github.com/llvm/llvm-project/pull/115956
This attempts to fix
[#115521](https://github.com/llvm/llvm-project/issues/115521).
According to the Itanium C++ mangling rules, vendor extended builtin types are
considered substitution candidates.
However, enabling this behavior on AArch64 and ARM is an ABI breaking change,
and I'm not sure how problematic that is.
Note that gcc implements the same wrong behavior https://godbolt.org/z/1h4EcYrET
An alternative could be to detect the "u6__bf16" mangling in the demangler and
specifically disable the substitution for this type.
>From 40ca031c0fd1b3e9997b2a2e0ed455233f781a9c Mon Sep 17 00:00:00 2001
From: Konstantin Schwarz
Date: Tue, 12 Nov 2024 21:47:33 +
Subject: [PATCH 1/2] [AArch64][ARM] Pre-commit mangling test for wrong __bf16
substitution behavior
---
clang/test/CodeGen/arm-mangle-bf16.cpp | 14 +-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/clang/test/CodeGen/arm-mangle-bf16.cpp
b/clang/test/CodeGen/arm-mangle-bf16.cpp
index 1d85c7b2733ac8..267fc5270f9387 100644
--- a/clang/test/CodeGen/arm-mangle-bf16.cpp
+++ b/clang/test/CodeGen/arm-mangle-bf16.cpp
@@ -2,6 +2,18 @@
// RUN: %clang_cc1 -triple aarch64 -target-feature -bf16 -emit-llvm -o - %s |
FileCheck %s
// RUN: %clang_cc1 -triple arm-arm-none-eabi -target-feature +bf16 -mfloat-abi
hard -emit-llvm -o - %s | FileCheck %s
// RUN: %clang_cc1 -triple arm-arm-none-eabi -target-feature +bf16 -mfloat-abi
softfp -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64 -target-feature +bf16 -emit-llvm -o - %s |
llvm-cxxfilt -n | FileCheck %s --check-prefix=DEMANGLE
+// RUN: %clang_cc1 -triple aarch64 -target-feature -bf16 -emit-llvm -o - %s |
llvm-cxxfilt -n | FileCheck %s --check-prefix=DEMANGLE
+// RUN: %clang_cc1 -triple arm-arm-none-eabi -target-feature +bf16 -mfloat-abi
hard -emit-llvm -o - %s | llvm-cxxfilt -n | FileCheck %s --check-prefix=DEMANGLE
+// RUN: %clang_cc1 -triple arm-arm-none-eabi -target-feature +bf16 -mfloat-abi
softfp -emit-llvm -o - %s | llvm-cxxfilt -n | FileCheck %s
--check-prefix=DEMANGLE
-// CHECK: define {{.*}}void @_Z3foou6__bf16(bfloat noundef %b)
+// CHECK:define {{.*}}void @_Z3foou6__bf16(bfloat noundef %b)
+// DEMANGLE: define {{.*}}void @foo(__bf16)
void foo(__bf16 b) {}
+
+struct bar;
+
+// CHECK:define {{.*}}void @_Z10substituteu6__bf16R3barS0_
+// DEMANGLE: define {{.*}}void @substitute(__bf16, bar&, bar)
+void substitute(__bf16 a, bar &b, bar &c) {
+}
>From 68609247bcd3cce8521337ad6a69acc4aa5f1a3b Mon Sep 17 00:00:00 2001
From: Konstantin Schwarz
Date: Tue, 12 Nov 2024 22:29:49 +
Subject: [PATCH 2/2] [AArch64][ARM] Treat __bf16 as vendor extension type for
C++ name mangling substitution
On AArch64 and ARM targets, __bf16 is mangled as "u6__bf16", which makes the
type a vendor extended type.
According to the Itanium C++ mangling rules, such types are considered
substitution candidates:
>From https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-compression:
"There are two exceptions that appear to be substitution candidates from the
grammar, but are explicitly excluded:
- other than vendor extended types
- function and operator names other than extern "C" functions."
This attempts to fix #115521
---
clang/include/clang/Basic/TargetInfo.h | 4
clang/lib/AST/ItaniumMangle.cpp | 9 +
clang/lib/Basic/Targets/AArch64.h| 3 +++
clang/lib/Basic/Targets/ARM.h| 2 ++
.../AArch64/sve-intrinsics/acle_sve_dupq-bfloat.c| 2 +-
.../AArch64/sve2-intrinsics/acle_sve2_whilerw-bfloat.c | 2 +-
.../AArch64/sve2-intrinsics/acle_sve2_whilewr-bfloat.c | 2 +-
clang/test/CodeGen/arm-mangle-bf16.cpp | 4 ++--
8 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/clang/include/clang/Basic/TargetInfo.h
b/clang/include/clang/Basic/TargetInfo.h
index 25eda907d20a7b..d4456c83a0eefa 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -810,6 +810,10 @@ class TargetInfo : public TransferrableTargetInfo,
/// Return the mangled code of bfloat.
virtual const char *getBFloat16Mangling() const { return "DF16b"; }
+ /// Returns whether to treat bfloat as a vendor extension type for the
purpose
+ /// of Itanium C++ name mangling compression rules
+ virtual bool treatBFloat16AsVendorType() const { return false; }
+
/// Return the value for the C99 FLT_EVAL_METHOD macro.
virtual LangOptions::FPEvalMethodKind getFPEvalMethod() const {
return LangOptions::FPEvalMethodKind::FEM_Source;
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 14bc260d0245fb..30164ad5ebbd7f 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -2923,6 +2923,15 @@ static bool isTypeSubstitutable(Qualifiers Quals