Author: Timm Baeder
Date: 2026-10-10T07:22:18+02:00
New Revision: a2dc8b4436c8b00643c81e0efa54f16f8f5bedac

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

LOG: [clang][bytecode] Fix a crash with invalid function frames (#230524)

This happens with the fake frames we create for the `TrivialCopy`
opcode.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/InterpFrame.cpp
    clang/test/AST/ByteCode/cxx20.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/InterpFrame.cpp 
b/clang/lib/AST/ByteCode/InterpFrame.cpp
index 413f2b51713b5..c04a70cc49f7c 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.cpp
+++ b/clang/lib/AST/ByteCode/InterpFrame.cpp
@@ -279,6 +279,11 @@ SourceInfo InterpFrame::getSource(CodePtr PC) const {
   if (Func && !funcHasUsableBody(Func) && Caller)
     return Caller->getSource(getRetOpPC());
 
+  // If we have a frame for an invalid function, check the caller.
+  // This happens for the fake function frame we create in TrivialCopy.
+  if (Func && !Func->isValid())
+    return Caller->getSource(getRetOpPC());
+
   // Similarly, if the resulting source location is invalid anyway,
   // point to the caller instead.
   SourceInfo Result = Func->getSource(PC);

diff  --git a/clang/test/AST/ByteCode/cxx20.cpp 
b/clang/test/AST/ByteCode/cxx20.cpp
index c5ade52a66b40..47d2fad17f4dc 100644
--- a/clang/test/AST/ByteCode/cxx20.cpp
+++ b/clang/test/AST/ByteCode/cxx20.cpp
@@ -1544,3 +1544,23 @@ namespace InvalidVirtualCall {
                        // both-note {{declared here}}
   };
 }
+
+namespace FailInTrivialCopy {
+
+  struct S {
+    S &operator=(const S &) = default;
+    int val; // ref-note {{subobject declared here}}
+  };
+
+  constexpr bool foo() {
+    S s1; // expected-note {{declared here}}
+    S s2{42};
+    s2 = s1; // expected-note {{read of uninitialized object}} \
+             // ref-note {{subobject 'val' is not initialized}} \
+             // both-note {{in call to}}
+    return true;
+  }
+
+  static_assert(foo(), ""); // both-error {{not an integral constant 
expression}} \
+                            // both-note {{in call to}}
+}


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

Reply via email to