[clang] [lldb] [Clang] Introduce OverflowBehaviorType for fine-grained overflow control (PR #148914)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 12 04:33:20 PST 2026
================
@@ -0,0 +1,178 @@
+// RUN: %clang_cc1 %s -Winteger-overflow -Wno-unused-value -fexperimental-overflow-behavior-types -Wconstant-conversion -Woverflow-behavior-conversion -verify -fsyntax-only
+
+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'}}
+typedef int __attribute__((overflow_behavior("not_real"))) bad_arg_spec_str; // expected-error {{'not_real' is not a valid argument to attribute 'overflow_behavior'}}
+typedef char* __attribute__((overflow_behavior("wrap"))) bad_type; // expected-error {{'overflow_behavior' attribute cannot be applied to non-integer type 'char *'}}
+
+typedef int __attribute__((overflow_behavior(wrap))) ok_wrap; // OK
+typedef long __attribute__((overflow_behavior(trap))) ok_nowrap; // OK
+typedef unsigned long __attribute__((overflow_behavior("wrap"))) str_ok_wrap; // OK
+typedef char __attribute__((overflow_behavior("trap"))) str_ok_nowrap; // OK
+
+#define __wrap __attribute__((overflow_behavior(wrap)))
+#define __trap __attribute__((overflow_behavior(trap)))
+
+struct struct_not_allowed {
+ int i;
+} __attribute__((overflow_behavior(wrap))); // expected-warning {{'overflow_behavior' attribute only applies to variables, typedefs, and non-static data members}}
----------------
AaronBallman wrote:
My comment was confusing, let me try again with a slightly more fresh brain. :-D
I'm surprised by "non-static data members" because I don't think there's anything about the storage duration that matters. e.g.,
```
struct S {
__ob_wrap int i; // Okay
static __ob_wrap int j; // Should also be okay
};
```
We have test coverage for the non-static case so we know that works, but we should be sure the static case works as well. I think the diagnostic text is just slightly wrong here.
https://github.com/llvm/llvm-project/pull/148914
More information about the cfe-commits
mailing list