Skip to content

Revert "[Clang] call HandleImmediateInvocation before checking for immediate escacalating expressions" #124646

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
Jan 27, 2025

Conversation

cor3ntin
Copy link
Contributor

Reverts #124414

Turns out to be an important compile time regression, I'll come up with a less disruptive approach

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jan 27, 2025
@cor3ntin cor3ntin merged commit 0e372c3 into main Jan 27, 2025
6 of 7 checks passed
@cor3ntin cor3ntin deleted the revert-124414-gh119046 branch January 27, 2025 22:51
@llvmbot
Copy link
Member

llvmbot commented Jan 27, 2025

@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)

Changes

Reverts llvm/llvm-project#124414

Turns out to be an important compile time regression, I'll come up with a less disruptive approach


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

6 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (-1)
  • (modified) clang/include/clang/Sema/Sema.h (+3-3)
  • (modified) clang/lib/Sema/SemaDecl.cpp (+1)
  • (modified) clang/lib/Sema/SemaExpr.cpp (-3)
  • (removed) clang/test/CodeGenCXX/gh119046.cpp (-32)
  • (modified) clang/test/SemaCXX/cxx2b-consteval-propagate.cpp (-17)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8b04f172946df1..af3632322b8453 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1003,7 +1003,6 @@ Bug Fixes to C++ Support
 - Fixed assertions or false compiler diagnostics in the case of C++ modules for
   lambda functions or inline friend functions defined inside templates (#GH122493).
 - Clang now rejects declaring an alias template with the same name as its template parameter. (#GH123423)
-- Fix that some dependent immediate expressions did not cause immediate escalation (#GH119046)
 - Fixed the rejection of valid code when referencing an enumerator of an unscoped enum member with a prior declaration. (#GH124405)
 - Fixed immediate escalation of non-dependent expressions. (#GH123405)
 - Fix type of expression when calling a template which returns an ``__array_rank`` querying a type depending on a
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f1d1e2e567193f..528304409b8092 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13139,10 +13139,10 @@ class Sema final : public SemaBase {
     ~SynthesizedFunctionScope() {
       if (PushedCodeSynthesisContext)
         S.popCodeSynthesisContext();
-
-      if (auto *FD = dyn_cast<FunctionDecl>(S.CurContext))
+      if (auto *FD = dyn_cast<FunctionDecl>(S.CurContext)) {
         FD->setWillHaveBody(false);
-
+        S.CheckImmediateEscalatingFunctionDefinition(FD, S.getCurFunction());
+      }
       S.PopExpressionEvaluationContext();
       S.PopFunctionScopeInfo();
     }
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index accef4c5d5d916..fe68eadc951b5f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16019,6 +16019,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
       if (!FD->isDeletedAsWritten())
         FD->setBody(Body);
       FD->setWillHaveBody(false);
+      CheckImmediateEscalatingFunctionDefinition(FD, FSI);
 
       if (getLangOpts().CPlusPlus14) {
         if (!FD->isInvalidDecl() && Body && !FD->isDependentContext() &&
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e098b21045f01d..176627c3df37c6 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -17881,9 +17881,6 @@ void Sema::PopExpressionEvaluationContext() {
   WarnOnPendingNoDerefs(Rec);
   HandleImmediateInvocations(*this, Rec);
 
-  if (auto *FD = dyn_cast<FunctionDecl>(CurContext); FD && getCurFunction())
-    CheckImmediateEscalatingFunctionDefinition(FD, getCurFunction());
-
   // Warn on any volatile-qualified simple-assignments that are not discarded-
   // value expressions nor unevaluated operands (those cases get removed from
   // this list by CheckUnusedVolatileAssignment).
diff --git a/clang/test/CodeGenCXX/gh119046.cpp b/clang/test/CodeGenCXX/gh119046.cpp
deleted file mode 100644
index cad76879f08624..00000000000000
--- a/clang/test/CodeGenCXX/gh119046.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-// RUN: %clang_cc1 -std=c++2a -triple x86_64-elf-gnu %s -emit-llvm -o - | FileCheck %s
-
-struct S {
-    consteval void operator()() {}
-};
-
-template <class Fn>
-constexpr void dispatch(Fn fn) {
-    fn();
-}
-
-template <class Visitor>
-struct value_visitor {
-    constexpr void operator()() { visitor(); }
-    Visitor&& visitor;
-};
-
-template <class Visitor>
-constexpr auto make_dispatch() {
-    return dispatch<value_visitor<S>>;
-}
-
-template <class Visitor>
-constexpr void visit(Visitor&&) {
-    make_dispatch<Visitor>();
-}
-
-void f() { visit(S{}); }
-
-// CHECK: define {{.*}} @_Z1fv
-// CHECK-NOT: define {{.*}} @_Z5visitI1SEvOT_
-// CHECK-NOT: define {{.*}} @_Z13make_dispatchI1SEDav
diff --git a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
index e83e03da54f788..05904d9ade067f 100644
--- a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
+++ b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -529,23 +529,6 @@ D d(0); // expected-note {{in implicit initialization for inherited constructor
 
 }
 
-namespace GH119046 {
-
-template <typename Cls> constexpr auto tfn(int) {
-  return (unsigned long long)(&Cls::sfn);
-  //expected-note@-1 {{'tfn<GH119046::S>' is an immediate function because its body evaluates the address of a consteval function 'sfn'}}
-};
-struct S { static consteval void sfn() {} };
-
-int f() {
-  int a = 0; // expected-note{{declared here}}
-  return tfn<S>(a);
-  //expected-error@-1 {{call to immediate function 'GH119046::tfn<GH119046::S>' is not a constant expression}}
-  //expected-note@-2 {{read of non-const variable 'a' is not allowed in a constant expression}}
-}
-
-}
-
 namespace GH123405 {
 
 consteval void fn() {}

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants