Repository navigation
[Clang][CodeGen] Fix crash in EmitParmDecl for bodyless destructors with -fextend-variable-liveness - #218830
Conversation
|
@llvm/pr-subscribers-clang-codegen @llvm/pr-subscribers-clang Author: AZero13 (AZero13) ChangesThe fake-use coroutine check in EmitParmDecl calls FnDecl->getBody()->getStmtClass() without guarding against a null getBody(). This crashes when processing implicit parameters (e.g. should_call_delete) of MSVC deleting destructors whose base destructor is only declared, not defined. 2 Files Affected:
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index b8fae352d41d7..1ed8989d3f627 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -2856,7 +2856,7 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg,
&D == CXXABIThisDecl)) {
// We don't emit fake uses for coroutine parameters, other than `this`.
if (auto *FnDecl = dyn_cast_or_null<FunctionDecl>(CurCodeDecl);
- &D == CXXABIThisDecl || !FnDecl ||
+ &D == CXXABIThisDecl || !FnDecl || !FnDecl->getBody() ||
FnDecl->getBody()->getStmtClass() != Stmt::CoroutineBodyStmtClass) {
if (shouldExtendLifetime(getContext(), CurCodeDecl, D, CXXABIThisDecl))
EHStack.pushCleanup<FakeUse>(NormalFakeUse, DeclPtr);
diff --git a/clang/test/CodeGen/fake-use-msvc-dtor.cpp b/clang/test/CodeGen/fake-use-msvc-dtor.cpp
new file mode 100644
index 0000000000000..3988b4b2242ec
--- /dev/null
+++ b/clang/test/CodeGen/fake-use-msvc-dtor.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -triple x86_64-pc-windows-msvc -emit-llvm -fextend-variable-liveness=all -O1 -mconstructor-aliases -o /dev/null
+// Verify that we do not crash when generating fake uses for parameters
+// of destructor declarations that have no body (the should_call_delete
+// implicit parameter in MSVC deleting destructors).
+
+struct A {
+ virtual ~A(void);
+};
+struct B {
+ virtual ~B(void);
+};
+
+struct C : A, B {};
+
+void foo() {
+ C c;
+}
|
cor3ntin
left a comment
There was a problem hiding this comment.
This change needs a release note.
Please add an entry to clang/docs/ReleaseNotes.md in the section the most adapted to the change, and referencing any Github issue this change fixes. Thanks!
|
No Github issue. |
…ith -fextend-variable-liveness The fake-use coroutine check in EmitParmDecl calls FnDecl->getBody()->getStmtClass() without guarding against a null getBody(). This crashes when processing implicit parameters (e.g. should_call_delete) of MSVC deleting destructors whose base destructor is only declared, not defined.
|
Thank you. Can you please merge? I have no merge perms. @cor3ntin |
|
/cherry-pick 9b9d90c |
Error: Command failed due to missing milestone. |
|
@Sirraide could you please add a milestone |
|
/cherry-pick 9b9d90c |
|
Failed to cherry-pick: 9b9d90c Please manually backport the fix and push it to your github fork. Once this is done, please create a pull request |
…ith -fextend-variable-liveness (llvm#218830) The fake-use coroutine check in EmitParmDecl calls FnDecl->getBody()->getStmtClass() without guarding against a null getBody(). This crashes when processing implicit parameters (e.g. should_call_delete) of MSVC deleting destructors whose base destructor is only declared, not defined.
…ith -fextend-variable-liveness (llvm#218830) The fake-use coroutine check in EmitParmDecl calls FnDecl->getBody()->getStmtClass() without guarding against a null getBody(). This crashes when processing implicit parameters (e.g. should_call_delete) of MSVC deleting destructors whose base destructor is only declared, not defined.
…ith -fextend-variable-liveness (llvm#218830) The fake-use coroutine check in EmitParmDecl calls FnDecl->getBody()->getStmtClass() without guarding against a null getBody(). This crashes when processing implicit parameters (e.g. should_call_delete) of MSVC deleting destructors whose base destructor is only declared, not defined.
…ith -fextend-variable-liveness (llvm#218830) The fake-use coroutine check in EmitParmDecl calls FnDecl->getBody()->getStmtClass() without guarding against a null getBody(). This crashes when processing implicit parameters (e.g. should_call_delete) of MSVC deleting destructors whose base destructor is only declared, not defined.
The fake-use coroutine check in EmitParmDecl calls FnDecl->getBody()->getStmtClass() without guarding against a null getBody(). This crashes when processing implicit parameters (e.g. should_call_delete) of MSVC deleting destructors whose base destructor is only declared, not defined.