Skip to content

[Clang][CodeGen] Fix crash in EmitParmDecl for bodyless destructors with -fextend-variable-liveness - #218830

Merged
Sirraide merged 1 commit into
llvm:mainfrom
AZero13:weeee
Aug 26, 2026
Merged

Sirraide merged 1 commit into
llvm:mainfrom
AZero13:weeee

Conversation

@AZero13

@AZero13 AZero13 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

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.

@llvmorg-github-actions llvmorg-github-actions Bot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. labels Aug 26, 2026
@llvmorg-github-actions

llvmorg-github-actions Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: AZero13 (AZero13)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/218830.diff

2 Files Affected:

  • (modified) clang/lib/CodeGen/CGDecl.cpp (+1-1)
  • (added) clang/test/CodeGen/fake-use-msvc-dtor.cpp (+17)
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 cor3ntin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@AZero13

AZero13 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

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.
@AZero13

AZero13 commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Thank you. Can you please merge? I have no merge perms. @cor3ntin

@Sirraide
Sirraide merged commit 9b9d90c into llvm:main Aug 26, 2026
13 checks passed
@AZero13
AZero13 deleted the weeee branch August 26, 2026 19:10
@AZero13

AZero13 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

/cherry-pick 9b9d90c

@llvmbot

llvmbot commented Aug 27, 2026

Copy link
Copy Markdown
Member

/cherry-pick 9b9d90c

Error: Command failed due to missing milestone.

@AZero13

AZero13 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

@Sirraide could you please add a milestone

@efriedma-quic

Copy link
Copy Markdown
Contributor

/cherry-pick 9b9d90c

@llvmbot

llvmbot commented Aug 27, 2026

Copy link
Copy Markdown
Member

Failed to cherry-pick: 9b9d90c

https://github.com/llvm/llvm-project/actions/runs/33092696469

Please manually backport the fix and push it to your github fork. Once this is done, please create a pull request

wlemkows pushed a commit to wlemkows/llvm-project that referenced this pull request Sep 4, 2026
…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.
AZero13 added a commit to AZero13/llvm-project that referenced this pull request Sep 6, 2026
…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.
AZero13 added a commit to AZero13/llvm-project that referenced this pull request Sep 7, 2026
…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.
dyung pushed a commit to AZero13/llvm-project that referenced this pull request Sep 20, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category release:cherry-pick-failed

Projects

Development

Successfully merging this pull request may close these issues.

6 participants