Skip to content

Conversation

mizvekov
Copy link
Contributor

@mizvekov mizvekov commented Oct 3, 2025

This fixes a regression introduced in #147835

When parsing a lambda where the call operator has a late parsed attribute, we would try to build a 'this' type for the lambda, but in a lambda 'this' never refers to the lambda class itself.

This late parsed attribute can be added implicitly by the -ftrapping-math flag.

This patch patch makes it so CXXThisScopeRAII ignores lambdas.

This became observable in #147835 because that made clang lazily create tag types, and it removed a workaround for a lambda dependency bug where any previously created tag type for the lambda is discarded after its dependency is recalculated.

But the 'this' scope created above would defeat this laziness and create the lambda type too soon, before its dependency was updated.

Since this regression was never released, there are no release notes.

Fixes #161657

This fixes a regression introduced in #147835

When parsing a lambda where the call operator has a late parsed attribute,
we would try to build a 'this' type for the lambda, but in a lambda 'this'
never refers to the lambda class itself.

This late parsed attribute can be added implicitly by the -ftrapping-math flag.

This patch patch makes it so CXXThisScopeRAII ignores lambdas.

This became observable in #147835 because that made clang lazily create
tag types, and it removed a workaround for a lambda dependency bug
where any previously created tag type for the lambda is dicarded after
its dependency is recalculated.

But the 'this' scope created above would defeat this laziness and create
the lambda type too soon, before its dependency was updated.

Since this regression was never released, there are no release notes.

Fixes #161657
@mizvekov mizvekov self-assigned this Oct 3, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Oct 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 3, 2025

@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)

Changes

This fixes a regression introduced in #147835

When parsing a lambda where the call operator has a late parsed attribute, we would try to build a 'this' type for the lambda, but in a lambda 'this' never refers to the lambda class itself.

This late parsed attribute can be added implicitly by the -ftrapping-math flag.

This patch patch makes it so CXXThisScopeRAII ignores lambdas.

This became observable in #147835 because that made clang lazily create tag types, and it removed a workaround for a lambda dependency bug where any previously created tag type for the lambda is dicarded after its dependency is recalculated.

But the 'this' scope created above would defeat this laziness and create the lambda type too soon, before its dependency was updated.

Since this regression was never released, there are no release notes.

Fixes #161657


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

2 Files Affected:

  • (modified) clang/lib/Sema/SemaExprCXX.cpp (+4)
  • (added) clang/test/SemaTemplate/GH161657.cpp (+11)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 779ccf5f1e888..576eb326e6529 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1251,6 +1251,10 @@ Sema::CXXThisScopeRAII::CXXThisScopeRAII(Sema &S,
   else
     Record = cast<CXXRecordDecl>(ContextDecl);
 
+  // 'this' never refers to the lambda class itself.
+  if (Record->isLambda())
+    return;
+
   QualType T = S.Context.getCanonicalTagType(Record);
   T = S.getASTContext().getQualifiedType(T, CXXThisTypeQuals);
 
diff --git a/clang/test/SemaTemplate/GH161657.cpp b/clang/test/SemaTemplate/GH161657.cpp
new file mode 100644
index 0000000000000..6ec793115db12
--- /dev/null
+++ b/clang/test/SemaTemplate/GH161657.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -ffp-exception-behavior=strict -verify %s
+// expected-no-diagnostics
+
+template <class T> struct S {
+  template <class U> using type1 = decltype([] { return U{}; });
+};
+
+void foo() {
+  using T1 = S<int>::type1<int>;
+  int x = T1()();
+}

@mizvekov mizvekov merged commit c64d4ce into main Oct 3, 2025
12 checks passed
@mizvekov mizvekov deleted the users/mizvekov/GH161657 branch October 3, 2025 02:47
@mizvekov mizvekov added the skip-precommit-approval PR for CI feedback, not intended for review label Oct 3, 2025
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 3, 2025

LLVM Buildbot has detected a new failure on builder clang-armv8-quick running on linaro-clang-armv8-quick while building clang at step 5 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/154/builds/22270

Here is the relevant piece of the build log for the reference
Step 5 (ninja check 1) failure: stage 1 checked (failure)
******************** TEST 'Clang :: SemaTemplate/GH161657.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/22/include -nostdsysteminc -fsyntax-only -std=c++20 -ffp-exception-behavior=strict -verify /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/SemaTemplate/GH161657.cpp # RUN: at line 1
+ /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/22/include -nostdsysteminc -fsyntax-only -std=c++20 -ffp-exception-behavior=strict -verify /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/SemaTemplate/GH161657.cpp
error: 'expected-warning' diagnostics seen but not expected: 
  (frontend): overriding currently unsupported use of floating point exceptions on this target
1 error generated.

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 3, 2025

LLVM Buildbot has detected a new failure on builder clang-solaris11-sparcv9 running on solaris11-sparcv9 while building clang at step 5 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/13/builds/9848

Here is the relevant piece of the build log for the reference
Step 5 (ninja check 1) failure: stage 1 checked (failure)
******************** TEST 'Clang :: SemaTemplate/GH161657.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/bin/clang -cc1 -internal-isystem /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/lib/clang/22/include -nostdsysteminc -fsyntax-only -std=c++20 -ffp-exception-behavior=strict -verify /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/SemaTemplate/GH161657.cpp # RUN: at line 1
+ /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/bin/clang -cc1 -internal-isystem /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/lib/clang/22/include -nostdsysteminc -fsyntax-only -std=c++20 -ffp-exception-behavior=strict -verify /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/SemaTemplate/GH161657.cpp
error: 'expected-warning' diagnostics seen but not expected: 
  (frontend): overriding currently unsupported use of floating point exceptions on this target
1 error generated.

--

********************


mizvekov added a commit that referenced this pull request Oct 3, 2025
Fixes the new test introduced in #161765, so that it always uses a
triple which supports floating point exceptions.

Otherwise, some post-commit bots fail.
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 3, 2025

LLVM Buildbot has detected a new failure on builder clang-armv7-global-isel running on linaro-clang-armv7-global-isel while building clang at step 7 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/39/builds/8112

Here is the relevant piece of the build log for the reference
Step 7 (ninja check 1) failure: stage 1 checked (failure)
******************** TEST 'Clang :: SemaTemplate/GH161657.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/home/tcwg-buildbot/worker/clang-armv7-global-isel/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv7-global-isel/stage1/lib/clang/22/include -nostdsysteminc -fsyntax-only -std=c++20 -ffp-exception-behavior=strict -verify /home/tcwg-buildbot/worker/clang-armv7-global-isel/llvm/clang/test/SemaTemplate/GH161657.cpp # RUN: at line 1
+ /home/tcwg-buildbot/worker/clang-armv7-global-isel/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv7-global-isel/stage1/lib/clang/22/include -nostdsysteminc -fsyntax-only -std=c++20 -ffp-exception-behavior=strict -verify /home/tcwg-buildbot/worker/clang-armv7-global-isel/llvm/clang/test/SemaTemplate/GH161657.cpp
error: 'expected-warning' diagnostics seen but not expected: 
  (frontend): overriding currently unsupported use of floating point exceptions on this target
1 error generated.

--

********************


mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
…161765)

This fixes a regression introduced in llvm#147835

When parsing a lambda where the call operator has a late parsed
attribute, we would try to build a 'this' type for the lambda, but in a
lambda 'this' never refers to the lambda class itself.

This late parsed attribute can be added implicitly by the
-ftrapping-math flag.

This patch patch makes it so CXXThisScopeRAII ignores lambdas.

This became observable in llvm#147835 because that made clang lazily create
tag types, and it removed a workaround for a lambda dependency bug where
any previously created tag type for the lambda is discarded after its
dependency is recalculated.

But the 'this' scope created above would defeat this laziness and create
the lambda type too soon, before its dependency was updated.

Since this regression was never released, there are no release notes.

Fixes llvm#161657
mizvekov added a commit that referenced this pull request Oct 3, 2025
Fixes the new test introduced in #161765, so that it always uses a
triple which supports floating point exceptions.

Otherwise, some post-commit bots fail.
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 3, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-win-x-armv7l running on as-builder-1 while building clang at step 10 "test-check-clang".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/38/builds/5688

Here is the relevant piece of the build log for the reference
Step 10 (test-check-clang) failure: Test just built components: check-clang completed (failure)
******************** TEST 'Clang :: SemaTemplate/GH161657.cpp' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
c:\buildbot\as-builder-1\x-armv7l\build\bin\clang.exe -cc1 -internal-isystem C:\buildbot\as-builder-1\x-armv7l\build\lib\clang\22\include -nostdsysteminc -fsyntax-only -std=c++20 -ffp-exception-behavior=strict -verify C:\buildbot\as-builder-1\x-armv7l\llvm-project\clang\test\SemaTemplate\GH161657.cpp
# executed command: 'c:\buildbot\as-builder-1\x-armv7l\build\bin\clang.exe' -cc1 -internal-isystem 'C:\buildbot\as-builder-1\x-armv7l\build\lib\clang\22\include' -nostdsysteminc -fsyntax-only -std=c++20 -ffp-exception-behavior=strict -verify 'C:\buildbot\as-builder-1\x-armv7l\llvm-project\clang\test\SemaTemplate\GH161657.cpp'
# .---command stderr------------
# | error: 'expected-warning' diagnostics seen but not expected: 
# |   (frontend): overriding currently unsupported use of floating point exceptions on this target
# | 1 error generated.
# `-----------------------------
# error: command failed with exit status: 1

--

********************


MixedMatched pushed a commit to MixedMatched/llvm-project that referenced this pull request Oct 3, 2025
…161765)

This fixes a regression introduced in llvm#147835

When parsing a lambda where the call operator has a late parsed
attribute, we would try to build a 'this' type for the lambda, but in a
lambda 'this' never refers to the lambda class itself.

This late parsed attribute can be added implicitly by the
-ftrapping-math flag.

This patch patch makes it so CXXThisScopeRAII ignores lambdas.

This became observable in llvm#147835 because that made clang lazily create
tag types, and it removed a workaround for a lambda dependency bug where
any previously created tag type for the lambda is discarded after its
dependency is recalculated.

But the 'this' scope created above would defeat this laziness and create
the lambda type too soon, before its dependency was updated.

Since this regression was never released, there are no release notes.

Fixes llvm#161657
MixedMatched pushed a commit to MixedMatched/llvm-project that referenced this pull request Oct 3, 2025
Fixes the new test introduced in llvm#161765, so that it always uses a
triple which supports floating point exceptions.

Otherwise, some post-commit bots fail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category skip-precommit-approval PR for CI feedback, not intended for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[clang] Assertion `CanDeclareSpecialMemberFunction(RD) && "doing special member lookup into record that isn't fully complete"' failed.
3 participants