Author: Timm Baeder
Date: 2026-01-10T16:52:54+01:00
New Revision: 18d6d67067a31cc089daca4b3d686dff5d7c422a

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

LOG: [clang][bytecode] Check for invalid function decls (#175312)

If the function decl is invalid, the `interp::Function` shouldn't ever
be valid.

Fixes https://github.com/llvm/llvm-project/issues/175280

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
    clang/lib/AST/ByteCode/Function.h
    clang/test/AST/ByteCode/invalid.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp 
b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
index ed743768d077e..f430b2329a6f3 100644
--- a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
@@ -86,7 +86,8 @@ void ByteCodeEmitter::compileFunc(const FunctionDecl 
*FuncDecl,
 
   // Set the function's code.
   Func->setCode(FuncDecl, NextLocalOffset, std::move(Code), std::move(SrcMap),
-                std::move(Scopes), FuncDecl->hasBody());
+                std::move(Scopes), FuncDecl->hasBody(),
+                !FuncDecl->isInvalidDecl());
   Func->setIsFullyCompiled(true);
 }
 

diff  --git a/clang/lib/AST/ByteCode/Function.h 
b/clang/lib/AST/ByteCode/Function.h
index 80283afb6e987..a086682d4ce21 100644
--- a/clang/lib/AST/ByteCode/Function.h
+++ b/clang/lib/AST/ByteCode/Function.h
@@ -240,13 +240,14 @@ class Function final {
   /// Sets the code of a function.
   void setCode(FunctionDeclTy Source, unsigned NewFrameSize,
                llvm::SmallVector<std::byte> &&NewCode, SourceMap &&NewSrcMap,
-               llvm::SmallVector<Scope, 2> &&NewScopes, bool NewHasBody) {
+               llvm::SmallVector<Scope, 2> &&NewScopes, bool NewHasBody,
+               bool NewIsValid) {
     this->Source = Source;
     FrameSize = NewFrameSize;
     Code = std::move(NewCode);
     SrcMap = std::move(NewSrcMap);
     Scopes = std::move(NewScopes);
-    IsValid = true;
+    IsValid = NewIsValid;
     HasBody = NewHasBody;
   }
 

diff  --git a/clang/test/AST/ByteCode/invalid.cpp 
b/clang/test/AST/ByteCode/invalid.cpp
index 541aa634007e3..f7f2da2769d65 100644
--- a/clang/test/AST/ByteCode/invalid.cpp
+++ b/clang/test/AST/ByteCode/invalid.cpp
@@ -123,3 +123,12 @@ namespace InvalidIntPtrRecord {
   };
   Size_t foo() { return (Size_t)(&((struct S *)0)->a); }
 }
+
+namespace RetVoidInInvalidFunc {
+
+  constexpr bool foo() { return; } // both-error {{non-void constexpr function 
'foo' should return a value}}
+  template <int N> struct X {
+    int v = N;
+  };
+  X<foo()> x; // both-error {{non-type template argument is not a constant 
expression}}
+}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to