Skip to content

[Sema] Relax a failing assertion in TransformBlockExpr #6298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ Bug Fixes
`Issue 59100 <https://github.com/llvm/llvm-project/issues/59100>`_
- Fix issue using __attribute__((format)) on non-variadic functions that expect
more than one formatted argument.
- Fix assert that fails when the expression causing the this pointer to be
captured by a block is part of a constexpr if statement's branch and
instantiation of the enclosing method causes the branch to be discarded.

Improvements to Clang's diagnostics
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
7 changes: 6 additions & 1 deletion clang/lib/Sema/TreeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -14439,7 +14439,12 @@ TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
oldCapture));
assert(blockScope->CaptureMap.count(newCapture));
}
assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());

// The this pointer may not be captured by the instantiated block, even when
// it's captured by the original block, if the expression causing the
// capture is in the discarded branch of a constexpr if statement.
assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
"this pointer isn't captured in the old block");
}
#endif

Expand Down
19 changes: 18 additions & 1 deletion clang/test/CodeGenCXX/cxx1z-constexpr-if.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -std=c++1z %s -emit-llvm -o - | FileCheck %s --implicit-check-not=should_not_be_used
// RUN: %clang_cc1 -std=c++1z %s -emit-llvm -fblocks -triple x86_64-apple-darwin10 -o - | FileCheck %s --implicit-check-not=should_not_be_used

void should_be_used_1();
void should_be_used_2();
Expand Down Expand Up @@ -32,3 +32,20 @@ foo: should_not_be_used();
// CHECK: should_be_used_1
// CHECK: should_be_used_2
// CHECK: should_be_used_3

namespace BlockThisCapture {
void foo();
struct S {
template <bool b>
void m() {
^{ if constexpr(b) (void)this; else foo(); }();
}
};

void test() {
S().m<false>();
}
}

// CHECK-LABEL: define internal void @___ZN16BlockThisCapture1S1mILb0EEEvv_block_invoke(
// CHECK: call void @_ZN16BlockThisCapture3fooEv(