https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/175312
If the function decl is invalid, the `interp::Function` shouldn't ever be valid. Fixes https://github.com/llvm/llvm-project/issues/175280 >From cce5595f181e93d6da5e7643d1fe7531a8b9f564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Sat, 10 Jan 2026 16:02:23 +0100 Subject: [PATCH] [clang][bytecode] Check for invalid function decls If the function decl is invalid, the `interp::Function` shouldn't ever be valid. Fixes https://github.com/llvm/llvm-project/issues/175280 --- clang/lib/AST/ByteCode/ByteCodeEmitter.cpp | 3 ++- clang/lib/AST/ByteCode/Function.h | 5 +++-- clang/test/AST/ByteCode/invalid.cpp | 9 +++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) 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
