https://github.com/tbaederr created
https://github.com/llvm/llvm-project/pull/201105
This broke libc++'s
std/ranges/range.adaptors/range.concat/iterator/arithmetic.pass.cpp.
The (reduced via cvise but not enough) function looks like this:
```c++
friend constexpr unsigned
operator-(const __iterator &__x, const __iterator &__y)
{
(void)-(__y - __x);
return 0;
}
```
When evaluating the binary operator for overflow, we will compile the operator-
(_this_ function) to bytecode. At that point, ::isThisDeclarationADefiniton()
will return true and ::getDefiniton() returns the function itself. However, all
this is happening while the function is being instantiated, which means the
function doesn't have a body yet and the bytecode ends up being just a NoRet
op. This will of course later fail.
Fix this by querying the body before trying to compile a function.
Unfortunately I wasn't able to create a reproducer of reasonable size.
>From 46ac953d11fa352b477bdccb4655fde5217baeda Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Tue, 2 Jun 2026 14:30:24 +0200
Subject: [PATCH] [clang][bytecode] Get the right definition before compiling
functions
This broke libc++'s
std/ranges/range.adaptors/range.concat/iterator/arithmetic.pass.cpp.
The (reduced via cvise but not enough) function looks like this:
```c++
friend constexpr unsigned
operator-(const __iterator &__x, const __iterator &__y)
{
(void)-(__y - __x);
return 0;
}
```
When evaluating the binary operator for overflow, we will compile the
operator- (_this_ function) to bytecode. At that point,
::isThisDeclarationADefiniton() will return true and ::getDefiniton()
returns the function itself. However, all this is happening while the
function is being instantiated, which means the function doesn't have a
body yet and the bytecode ends up being just a NoRet op. This will of
course later fail.
Fix this by querying the body before trying to compile a function.
Unfortunately I wasn't able to create a reproducer of reasonable size.
---
clang/lib/AST/ByteCode/Interp.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/clang/lib/AST/ByteCode/Interp.cpp
b/clang/lib/AST/ByteCode/Interp.cpp
index 6bcebf3ee892b..9d363191f8008 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1725,7 +1725,9 @@ bool CheckBitCast(InterpState &S, CodePtr OpPC, const
Type *TargetType,
}
static void compileFunction(InterpState &S, const Function *Func) {
- const FunctionDecl *Definition = Func->getDecl()->getDefinition();
+ const FunctionDecl *Definition;
+ if (!Func->getDecl()->getBody(Definition))
+ return;
if (!Definition)
return;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits