Author: Timm Baeder
Date: 2026-01-22T12:42:28+01:00
New Revision: 9ec0eccf48e931224ab96454be93ba8e3a006cc5

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

LOG: [clang][bytecode] Fix a crash with explicit this parameters (#177154)

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/InterpFrame.cpp 
b/clang/lib/AST/ByteCode/InterpFrame.cpp
index 5d645feb5579d..a9f8823613b0a 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.cpp
+++ b/clang/lib/AST/ByteCode/InterpFrame.cpp
@@ -151,8 +151,9 @@ static bool shouldSkipInBacktrace(const Function *F) {
 }
 
 void InterpFrame::describe(llvm::raw_ostream &OS) const {
+  assert(Func);
   // For lambda static invokers, we would just print __invoke().
-  if (const auto *F = getFunction(); F && shouldSkipInBacktrace(F))
+  if (shouldSkipInBacktrace(Func))
     return;
 
   const Expr *CallExpr = Caller->getExpr(getRetPC());
@@ -189,13 +190,14 @@ void InterpFrame::describe(llvm::raw_ostream &OS) const {
   unsigned Off = 0;
 
   Off += Func->hasRVO() ? primSize(PT_Ptr) : 0;
-  Off += Func->hasThisPointer() ? primSize(PT_Ptr) : 0;
+  Off += (Func->hasThisPointer() && !Func->isThisPointerExplicit())
+             ? primSize(PT_Ptr)
+             : 0;
 
   llvm::ListSeparator Comma;
   for (unsigned I = 0, N = F->getNumParams(); I < N; ++I) {
     OS << Comma;
     QualType Ty = F->getParamDecl(I)->getType();
-
     PrimType PrimTy = S.Ctx.classify(Ty).value_or(PT_Ptr);
 
     TYPE_SWITCH(PrimTy, print(OS, stackRef<T>(Off), S.getASTContext(), Ty));

diff  --git a/clang/test/AST/ByteCode/cxx26.cpp 
b/clang/test/AST/ByteCode/cxx26.cpp
index 64461ee9e12cd..acab347963923 100644
--- a/clang/test/AST/ByteCode/cxx26.cpp
+++ b/clang/test/AST/ByteCode/cxx26.cpp
@@ -45,3 +45,20 @@ constexpr int a = 12;
 constexpr const int *b = &a;
 constexpr int *f = (int*)(void*)b;
 static_assert(*f == 12);
+
+namespace ExplicitThisInBacktrace {
+  struct S {
+    constexpr void foo(this const S& self) {
+      throw; // both-note {{not valid in a constant expression}}
+    }
+  };
+
+  constexpr bool test() {
+    S s;
+    s.foo(); // both-note {{in call to}}
+    return true;
+  }
+
+  static_assert(test()); // 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