[clang] c012265 - [clang][bytecode] Reject functions with dependent return type (#194114)

via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 25 22:33:12 PDT 2026


Author: Timm Baeder
Date: 2026-04-26T07:33:06+02:00
New Revision: c01226500856d65145c37f9c44b82e6f7c60a806

URL: https://github.com/llvm/llvm-project/commit/c01226500856d65145c37f9c44b82e6f7c60a806
DIFF: https://github.com/llvm/llvm-project/commit/c01226500856d65145c37f9c44b82e6f7c60a806.diff

LOG: [clang][bytecode] Reject functions with dependent return type (#194114)

This unfortunately crashes the current interpreter as well.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Compiler.cpp
    clang/test/AST/ByteCode/functions.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 4de19e7fee7ed..d1878cbedae58 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6907,6 +6907,9 @@ bool Compiler<Emitter>::compileUnionAssignmentOperator(
 
 template <class Emitter>
 bool Compiler<Emitter>::visitFunc(const FunctionDecl *F) {
+  if (F->getReturnType()->isDependentType())
+    return false;
+
   // Classify the return type.
   ReturnType = this->classify(F->getReturnType());
 

diff  --git a/clang/test/AST/ByteCode/functions.cpp b/clang/test/AST/ByteCode/functions.cpp
index 5540ce0baf4bf..05dea564baec7 100644
--- a/clang/test/AST/ByteCode/functions.cpp
+++ b/clang/test/AST/ByteCode/functions.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1            -pedantic -verify=expected,both %s -fexperimental-new-constant-interpreter
-// RUN: %clang_cc1 -std=c++14 -pedantic -verify=expected,both %s -fexperimental-new-constant-interpreter
-// RUN: %clang_cc1 -std=c++20 -pedantic -verify=expected,both %s -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1            -pedantic -verify=expected,both %s -fexperimental-new-constant-interpreter -DINTERP
+// RUN: %clang_cc1 -std=c++14 -pedantic -verify=expected,both %s -fexperimental-new-constant-interpreter -DINTERP
+// RUN: %clang_cc1 -std=c++20 -pedantic -verify=expected,both %s -fexperimental-new-constant-interpreter -DINTERP
 // RUN: %clang_cc1            -pedantic -verify=ref,both      %s
 // RUN: %clang_cc1 -std=c++14 -pedantic -verify=ref,both      %s
 // RUN: %clang_cc1 -std=c++20 -pedantic -verify=ref,both      %s
@@ -765,3 +765,12 @@ namespace NestedDiags {
     return true;
   }
 }
+
+#ifdef INTERP
+namespace DependentReturnType {
+  template <typename T> struct S {
+    int a = [] { return [](auto t) noexcept((zomg(f))) { return 0; }(0); }(); // both-error {{use of undeclared identifier 'zomg'}}
+  };
+  S<float> x;
+}
+#endif


        


More information about the cfe-commits mailing list