https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/183761

>From 47f199261e296f90b4454ea29b9c8be0307f6af6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Fri, 27 Feb 2026 16:54:14 +0100
Subject: [PATCH] obt

---
 clang/lib/AST/ByteCode/Context.cpp                   |  3 +++
 clang/lib/AST/ByteCode/Interp.h                      | 10 ++++++++++
 clang/test/Sema/attr-overflow-behavior-constexpr.cpp |  1 +
 clang/test/Sema/attr-overflow-behavior-templates.cpp |  1 +
 clang/test/Sema/attr-overflow-behavior.c             |  1 +
 clang/test/Sema/attr-overflow-behavior.cpp           |  1 +
 6 files changed, 17 insertions(+)

diff --git a/clang/lib/AST/ByteCode/Context.cpp 
b/clang/lib/AST/ByteCode/Context.cpp
index 879d51e6a2c3e..c811fac384fd4 100644
--- a/clang/lib/AST/ByteCode/Context.cpp
+++ b/clang/lib/AST/ByteCode/Context.cpp
@@ -470,6 +470,9 @@ OptPrimType Context::classify(QualType T) const {
   if (const auto *DT = dyn_cast<DecltypeType>(T))
     return classify(DT->getUnderlyingType());
 
+  if (const auto *OBT = T.getCanonicalType()->getAs<OverflowBehaviorType>())
+    return classify(OBT->getUnderlyingType());
+
   if (T->isObjCObjectPointerType() || T->isBlockPointerType())
     return PT_Ptr;
 
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 7f30def20cc36..734d99e46b6f7 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -292,6 +292,11 @@ bool AddSubMulHelper(InterpState &S, CodePtr OpPC, 
unsigned Bits, const T &LHS,
   // If for some reason evaluation continues, use the truncated results.
   S.Stk.push<T>(Result);
 
+  // If wrapping is enabled, the new value is fine.
+  // FIXME: Pass this to the add/sub/mul op instead?
+  if (S.Current->getExpr(OpPC)->getType().isWrapType())
+    return true;
+
   // Short-circuit fixed-points here since the error handling is easier.
   if constexpr (std::is_same_v<T, FixedPoint>)
     return handleFixedPointOverflow(S, OpPC, Result);
@@ -776,6 +781,11 @@ bool IncDecHelper(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr,
   }
   assert(CanOverflow);
 
+  if (S.Current->getExpr(OpPC)->getType().isWrapType()) {
+    Ptr.deref<T>() = Result;
+    return true;
+  }
+
   // Something went wrong with the previous operation. Compute the
   // result with another bit of precision.
   unsigned Bits = Value.bitWidth() + 1;
diff --git a/clang/test/Sema/attr-overflow-behavior-constexpr.cpp 
b/clang/test/Sema/attr-overflow-behavior-constexpr.cpp
index 1d81d3a243c1e..5f2785f1a38cf 100644
--- a/clang/test/Sema/attr-overflow-behavior-constexpr.cpp
+++ b/clang/test/Sema/attr-overflow-behavior-constexpr.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu %s 
-fexperimental-overflow-behavior-types -verify -fsyntax-only -std=c++14
+// RUN: %clang_cc1 -triple x86_64-linux-gnu %s 
-fexperimental-overflow-behavior-types -verify -fsyntax-only -std=c++14 
-fexperimental-new-constant-interpreter
 
 #define __wrap __attribute__((overflow_behavior(wrap)))
 #define __no_trap __attribute__((overflow_behavior(trap)))
diff --git a/clang/test/Sema/attr-overflow-behavior-templates.cpp 
b/clang/test/Sema/attr-overflow-behavior-templates.cpp
index 09242f6f9ab3a..40c7310b78e53 100644
--- a/clang/test/Sema/attr-overflow-behavior-templates.cpp
+++ b/clang/test/Sema/attr-overflow-behavior-templates.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fexperimental-overflow-behavior-types -verify 
-fsyntax-only -Wimplicit-overflow-behavior-conversion
+// RUN: %clang_cc1 %s -fexperimental-overflow-behavior-types -verify 
-fsyntax-only -Wimplicit-overflow-behavior-conversion 
-fexperimental-new-constant-interpreter
 
 template<typename T>
 constexpr int template_overload_test(T) {
diff --git a/clang/test/Sema/attr-overflow-behavior.c 
b/clang/test/Sema/attr-overflow-behavior.c
index 6ce876f09d802..7f2312537516d 100644
--- a/clang/test/Sema/attr-overflow-behavior.c
+++ b/clang/test/Sema/attr-overflow-behavior.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -Winteger-overflow -Wno-unused-value 
-fexperimental-overflow-behavior-types -Woverflow-behavior-conversion 
-Wconstant-conversion -verify -fsyntax-only -std=c11 -Wno-pointer-sign
+// RUN: %clang_cc1 %s -Winteger-overflow -Wno-unused-value 
-fexperimental-overflow-behavior-types -Woverflow-behavior-conversion 
-Wconstant-conversion -verify -fsyntax-only -std=c11 -Wno-pointer-sign 
-fexperimental-new-constant-interpreter
 
 typedef int __attribute__((overflow_behavior)) bad_arg_count; // 
expected-error {{'overflow_behavior' attribute takes one argument}}
 typedef int __attribute__((overflow_behavior(not_real))) bad_arg_spec; // 
expected-error {{'not_real' is not a valid argument to attribute 
'overflow_behavior'}}
diff --git a/clang/test/Sema/attr-overflow-behavior.cpp 
b/clang/test/Sema/attr-overflow-behavior.cpp
index 1dfe00ab47ae2..a69eb83e591f5 100644
--- a/clang/test/Sema/attr-overflow-behavior.cpp
+++ b/clang/test/Sema/attr-overflow-behavior.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -Winteger-overflow -Wno-unused-value 
-fexperimental-overflow-behavior-types -Wconstant-conversion 
-Woverflow-behavior-conversion -verify -fsyntax-only
+// RUN: %clang_cc1 %s -Winteger-overflow -Wno-unused-value 
-fexperimental-overflow-behavior-types -Wconstant-conversion 
-Woverflow-behavior-conversion -verify -fsyntax-only 
-fexperimental-new-constant-interpreter
 
 typedef int __attribute__((overflow_behavior)) bad_arg_count; // 
expected-error {{'overflow_behavior' attribute takes one argument}}
 typedef int __attribute__((overflow_behavior(not_real))) bad_arg_spec; // 
expected-error {{'not_real' is not a valid argument to attribute 
'overflow_behavior'}}

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

Reply via email to