[clang codegen] Fix MS ABI detection of user-provided constructors.#90151
Merged
efriedma-quic merged 2 commits intoApr 29, 2024
Conversation
In the context of determining whether a class counts as an "aggregate", a constructor template counts as a user-provided constructor. Fixes llvm#86384
Member
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen Author: Eli Friedman (efriedma-quic) ChangesIn the context of determining whether a class counts as an "aggregate", a constructor template counts as a user-provided constructor. Fixes #86384 Full diff: https://github.com/llvm/llvm-project/pull/90151.diff 2 Files Affected:
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index d38a26940a3cb6..d47927745759e1 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1131,9 +1131,15 @@ static bool isTrivialForMSVC(const CXXRecordDecl *RD, QualType Ty,
return false;
if (RD->hasNonTrivialCopyAssignment())
return false;
- for (const CXXConstructorDecl *Ctor : RD->ctors())
- if (Ctor->isUserProvided())
- return false;
+ for (const Decl *D : RD->decls()) {
+ if (auto *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
+ if (Ctor->isUserProvided())
+ return false;
+ } else if (auto *Template = dyn_cast<FunctionTemplateDecl>(D)) {
+ if (isa<CXXConstructorDecl>(Template->getTemplatedDecl()))
+ return false;
+ }
+ }
if (RD->hasNonTrivialDestructor())
return false;
return true;
diff --git a/clang/test/CodeGen/arm64-microsoft-arguments.cpp b/clang/test/CodeGen/arm64-microsoft-arguments.cpp
index e8309888dcfe21..89299277422a29 100644
--- a/clang/test/CodeGen/arm64-microsoft-arguments.cpp
+++ b/clang/test/CodeGen/arm64-microsoft-arguments.cpp
@@ -201,3 +201,17 @@ S11 f11() {
S11 x;
return func11(x);
}
+
+// Pass and return object with template constructor (pass directly,
+// return indirectly).
+// CHECK: define dso_local void @"?f12@@YA?AUS12@@XZ"(ptr dead_on_unwind inreg noalias writable sret(%struct.S12) align 4 {{.*}})
+// CHECK: call void @"?func12@@YA?AUS12@@U1@@Z"(ptr dead_on_unwind inreg writable sret(%struct.S12) align 4 {{.*}}, i64 {{.*}})
+struct S12 {
+ template<typename T> S12(T*) {}
+ int x;
+};
+S12 func12(S12 x);
+S12 f12() {
+ S12 x((int*)0);
+ return func12(x);
+}
|
cor3ntin
approved these changes
Apr 26, 2024
Contributor
cor3ntin
left a comment
There was a problem hiding this comment.
Can you add a changelog entry mentioning the fixed issue ?
Otherwise LGTM
Contributor
Author
|
Added release note. |
llvmbot
pushed a commit
to llvmbot/llvm-project
that referenced
this pull request
Apr 30, 2024
…lvm#90151) In the context of determining whether a class counts as an "aggregate", a constructor template counts as a user-provided constructor. Fixes llvm#86384 (cherry picked from commit 3ab4ae9)
tstellar
pushed a commit
to llvmbot/llvm-project
that referenced
this pull request
May 1, 2024
…lvm#90151) In the context of determining whether a class counts as an "aggregate", a constructor template counts as a user-provided constructor. Fixes llvm#86384 (cherry picked from commit 3ab4ae9)
Closed
xgupta
pushed a commit
to xgupta/llvm-project
that referenced
this pull request
Sep 9, 2024
…lvm#90151) In the context of determining whether a class counts as an "aggregate", a constructor template counts as a user-provided constructor. Fixes llvm#86384 (cherry picked from commit 3ab4ae9)
xgupta
pushed a commit
to xgupta/llvm-project
that referenced
this pull request
Oct 10, 2024
…lvm#90151) In the context of determining whether a class counts as an "aggregate", a constructor template counts as a user-provided constructor. Fixes llvm#86384 (cherry picked from commit 3ab4ae9)
Tedlion
pushed a commit
to Tedlion/llvm-project
that referenced
this pull request
Jun 15, 2025
…lvm#90151) In the context of determining whether a class counts as an "aggregate", a constructor template counts as a user-provided constructor. Fixes llvm#86384 (cherry picked from commit 3ab4ae9)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the context of determining whether a class counts as an "aggregate", a constructor template counts as a user-provided constructor.
Fixes #86384