Bug 1750659 - Refresh D116020 patch with what landed upstream. r=firefox-build-system-reviewers,mhentges

Differential Revision: https://phabricator.services.mozilla.com/D136197
This commit is contained in:
Mike Hommey 2022-01-18 00:59:16 +00:00
parent 78aef3e33c
commit 168573ae42
3 changed files with 61 additions and 40 deletions

View File

@ -1,39 +0,0 @@
Index: clang/lib/AST/Mangle.cpp
===================================================================
--- a/clang/lib/AST/Mangle.cpp
+++ b/clang/lib/AST/Mangle.cpp
@@ -225,11 +225,17 @@
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD))
if (!MD->isStatic())
++ArgWords;
- for (const auto &AT : Proto->param_types())
+ for (const auto &AT : Proto->param_types()) {
+ // If an argument type is incomplete there is no way to get its size to
+ // correctly encode into the mangling scheme.
+ // Follow GCCs behaviour by simply breaking out of the loop.
+ if (AT->isIncompleteType())
+ break;
// Size should be aligned to pointer size.
ArgWords +=
llvm::alignTo(ASTContext.getTypeSize(AT), TI.getPointerWidth(0)) /
TI.getPointerWidth(0);
+ }
Out << ((TI.getPointerWidth(0) / 8) * ArgWords);
}
Index: clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
===================================================================
--- /dev/null
+++ b/clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple i686-w64-windows-gnu -o - -emit-llvm -debug-info-kind=constructor %s
+
+#define NS_IMETHOD_(type) type __stdcall
+
+enum nsresult {};
+
+class NotNull;
+
+class nsICanvasRenderingContextInternal {
+ NS_IMETHOD_(nsresult) InitializeWithDrawTarget(NotNull);
+} nsTBaseHashSet;

View File

@ -23,6 +23,6 @@
"llvmorg-14-init-11347-g93a20ecee4b6.patch",
"llvmorg-14-init-12719-gc4b45eeb44fd.patch",
"llvmorg-14-init-13305-g319181f76718.patch",
"D116020.patch"
"llvmorg-14-init-13854-g782791ee84d2.patch"
]
}

View File

@ -0,0 +1,60 @@
From 782791ee84d29db137f441c1e033582a7a78ad5e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Markus=20B=C3=B6ck?= <markus.boeck02@gmail.com>
Date: Fri, 24 Dec 2021 21:55:07 +0100
Subject: [PATCH] [clang][#52782] Bail on incomplete parameter type in stdcall
name mangling
stdcall name mangling requires a suffix with the number equal to the sum of the byte count of all parameter types. In the case of a function prototype that has a parameter type of an incomplete type it is impossible to get the size of the type. While such a function is not callable or able to be defined in the TU, it may still be mangled when generating debug info, which would previously lead to a crash.
This patch fixes that by simply bailing out of the loop and using the so far accumulated byte count. This matches GCCs behaviour as well: https://github.com/gcc-mirror/gcc/blob/bc8d6c60137f8bbf173b86ddf31b15d7ba2a33dd/gcc/config/i386/winnt.c#L203
Fixes https://github.com/llvm/llvm-project/issues/52782
Differential Revision: https://reviews.llvm.org/D116020
---
clang/lib/AST/Mangle.cpp | 8 +++++++-
clang/test/CodeGen/pr52782-stdcall-func-decl.cpp | 10 ++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
create mode 100644 clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
diff --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp
index 54dbf484f377..984da9909ce2 100644
--- a/clang/lib/AST/Mangle.cpp
+++ b/clang/lib/AST/Mangle.cpp
@@ -225,11 +225,17 @@ void MangleContext::mangleName(GlobalDecl GD, raw_ostream &Out) {
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD))
if (!MD->isStatic())
++ArgWords;
- for (const auto &AT : Proto->param_types())
+ for (const auto &AT : Proto->param_types()) {
+ // If an argument type is incomplete there is no way to get its size to
+ // correctly encode into the mangling scheme.
+ // Follow GCCs behaviour by simply breaking out of the loop.
+ if (AT->isIncompleteType())
+ break;
// Size should be aligned to pointer size.
ArgWords +=
llvm::alignTo(ASTContext.getTypeSize(AT), TI.getPointerWidth(0)) /
TI.getPointerWidth(0);
+ }
Out << ((TI.getPointerWidth(0) / 8) * ArgWords);
}
diff --git a/clang/test/CodeGen/pr52782-stdcall-func-decl.cpp b/clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
new file mode 100644
index 000000000000..c3c94ece24b2
--- /dev/null
+++ b/clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple i686-w64-windows-gnu -o - -emit-llvm -debug-info-kind=constructor %s | FileCheck %s
+
+enum nsresult {};
+
+class NotNull;
+
+class nsICanvasRenderingContextInternal {
+ // CHECK: !DISubprogram(name: "InitializeWithDrawTarget", linkageName: "\01__ZN33nsICanvasRenderingContextInternal24InitializeWithDrawTargetE7NotNull@4"
+ nsresult __stdcall InitializeWithDrawTarget(NotNull);
+} nsTBaseHashSet;
--
2.34.0.1.g4c8d2d0e3e