Skip to content

Conversation

@tbaederr
Copy link
Contributor

We can't access the calling frame in that case.

Fixes #169032

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels Nov 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 21, 2025

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

We can't access the calling frame in that case.

Fixes #169032


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

3 Files Affected:

  • (modified) clang/lib/AST/ByteCode/Interp.cpp (+2-1)
  • (modified) clang/lib/AST/ByteCode/InterpFrame.h (+2)
  • (modified) clang/test/AST/ByteCode/new-delete.cpp (+12)
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 280911c324bb1..4222fd97a84fa 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1407,7 +1407,8 @@ bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T) {
   //   http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1677
   // Therefore, we use the C++1y behavior.
 
-  if (S.Current->getFunction() && S.Current->getFunction()->isConstructor() &&
+  if (!S.Current->isBottomFrame() &&
+      S.Current->getFunction()->isConstructor() &&
       S.Current->getThis().getDeclDesc()->asDecl() == S.EvaluatingDecl) {
     return true;
   }
diff --git a/clang/lib/AST/ByteCode/InterpFrame.h b/clang/lib/AST/ByteCode/InterpFrame.h
index fa9de2e1e7c6d..febef1097ea8a 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.h
+++ b/clang/lib/AST/ByteCode/InterpFrame.h
@@ -109,6 +109,7 @@ class InterpFrame final : public Frame {
   /// Returns the 'this' pointer.
   const Pointer &getThis() const {
     assert(hasThisPointer());
+    assert(!isBottomFrame());
     return stackRef<Pointer>(ThisPointerOffset);
   }
 
@@ -116,6 +117,7 @@ class InterpFrame final : public Frame {
   const Pointer &getRVOPtr() const {
     assert(Func);
     assert(Func->hasRVO());
+    assert(!isBottomFrame());
     return stackRef<Pointer>(0);
   }
 
diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp
index 9e0f33e212c18..43e1f6bfcc9a6 100644
--- a/clang/test/AST/ByteCode/new-delete.cpp
+++ b/clang/test/AST/ByteCode/new-delete.cpp
@@ -1114,6 +1114,18 @@ namespace ZeroSizeArray {
   static_assert(foo() == 0);
 }
 
+namespace NonLiteralType {
+  /// This used to crash.
+  constexpr void foo() {
+    struct O {};
+
+    struct S {
+      O *s;
+      constexpr S() : s{std::allocator<O>{}.allocate(1)} {}
+    };
+  }
+}
+
 #else
 /// Make sure we reject this prior to C++20
 constexpr int a() { // both-error {{never produces a constant expression}}

@github-actions
Copy link

github-actions bot commented Nov 21, 2025

🐧 Linux x64 Test Results

  • 91137 tests passed
  • 2416 tests skipped
  • 2 tests failed

Failed Tests

(click on a test name to see its output)

ORC-x86_64-linux

ORC-x86_64-linux.TestCases/Linux/x86-64/lljit-ehframe.cpp (Likely Already Failing) This test is already failing at the base commit.
Exit Code: -9
Timeout: Reached timeout of 1200 seconds

Command Output (stderr):
--
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/./bin/clang  --driver-mode=g++  -m64  -fPIC -emit-llvm -c -o /home/gha/actions-runner/_work/llvm-project/llvm-project/build/runtimes/runtimes-bins/compiler-rt/test/orc/X86_64LinuxConfig/TestCases/Linux/x86-64/Output/lljit-ehframe.cpp.tmp /home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/test/orc/TestCases/Linux/x86-64/lljit-ehframe.cpp # RUN: at line 1
+ /home/gha/actions-runner/_work/llvm-project/llvm-project/build/./bin/clang --driver-mode=g++ -m64 -fPIC -emit-llvm -c -o /home/gha/actions-runner/_work/llvm-project/llvm-project/build/runtimes/runtimes-bins/compiler-rt/test/orc/X86_64LinuxConfig/TestCases/Linux/x86-64/Output/lljit-ehframe.cpp.tmp /home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/test/orc/TestCases/Linux/x86-64/lljit-ehframe.cpp
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/./bin/lli -jit-kind=orc -jit-linker=jitlink -orc-runtime=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/./lib/../lib/clang/22/lib/x86_64-unknown-linux-gnu/liborc_rt.a -relocation-model=pic /home/gha/actions-runner/_work/llvm-project/llvm-project/build/runtimes/runtimes-bins/compiler-rt/test/orc/X86_64LinuxConfig/TestCases/Linux/x86-64/Output/lljit-ehframe.cpp.tmp | FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/test/orc/TestCases/Linux/x86-64/lljit-ehframe.cpp # RUN: at line 2
+ /home/gha/actions-runner/_work/llvm-project/llvm-project/build/./bin/lli -jit-kind=orc -jit-linker=jitlink -orc-runtime=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/./lib/../lib/clang/22/lib/x86_64-unknown-linux-gnu/liborc_rt.a -relocation-model=pic /home/gha/actions-runner/_work/llvm-project/llvm-project/build/runtimes/runtimes-bins/compiler-rt/test/orc/X86_64LinuxConfig/TestCases/Linux/x86-64/Output/lljit-ehframe.cpp.tmp
+ FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/test/orc/TestCases/Linux/x86-64/lljit-ehframe.cpp
JIT session error: Invalid arch in ELF object file: 0

--

ORC-x86_64-linux.TestCases/Linux/x86-64/lljit-initialize-deinitialize.ll (Likely Already Failing) This test is already failing at the base commit.
Exit Code: -9
Timeout: Reached timeout of 1200 seconds

Command Output (stderr):
--
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/./bin/lli -jit-kind=orc -jit-linker=jitlink -orc-runtime=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/./lib/../lib/clang/22/lib/x86_64-unknown-linux-gnu/liborc_rt.a /home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/test/orc/TestCases/Linux/x86-64/lljit-initialize-deinitialize.ll | FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/test/orc/TestCases/Linux/x86-64/lljit-initialize-deinitialize.ll # RUN: at line 1
+ /home/gha/actions-runner/_work/llvm-project/llvm-project/build/./bin/lli -jit-kind=orc -jit-linker=jitlink -orc-runtime=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/./lib/../lib/clang/22/lib/x86_64-unknown-linux-gnu/liborc_rt.a /home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/test/orc/TestCases/Linux/x86-64/lljit-initialize-deinitialize.ll
+ FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/test/orc/TestCases/Linux/x86-64/lljit-initialize-deinitialize.ll
JIT session error: Invalid arch in ELF object file: 0

--

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.

We can't access the calling frame in that case.

Fixes llvm#169032
@tbaederr tbaederr enabled auto-merge (squash) November 22, 2025 04:45
@tbaederr tbaederr merged commit 3841e7d into llvm:main Nov 22, 2025
7 of 9 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 22, 2025

LLVM Buildbot has detected a new failure on builder reverse-iteration running on hexagon-build-03 while building clang at step 6 "check_all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/110/builds/6439

Here is the relevant piece of the build log for the reference
Step 6 (check_all) failure: test (failure)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bytecode Issues for the clang bytecode constexpr interpreter 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.

[clang][bytecode] crash when non-literal type is used in a constant expression

3 participants