[clang] [Clang] Introduce OverflowBehaviorType for fine-grained overflow control (PR #148914)

Kees Cook via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 2 11:10:35 PDT 2025


================
@@ -199,6 +233,19 @@ static bool CanElideOverflowCheck(const ASTContext &Ctx, const BinOpInfo &Op) {
   if (!Op.mayHaveIntegerOverflow())
     return true;
 
+  const UnaryOperator *UO = dyn_cast<UnaryOperator>(Op.E);
+  if (UO && Ctx.isUnaryOverflowPatternExcluded(UO))
+    return true;
+
+  const auto *BO = dyn_cast<BinaryOperator>(Op.E);
+  if (BO && BO->hasExcludedOverflowPattern())
----------------
kees wrote:

I can see the inconsistency from the perspective of "command line options should be global", but my thinking on it is that the pattern exclusion heuristics are to help solve corner cases of the language globally that even OBT can't solve. So I want the heuristics taking precedence (and I should note I'm biased: we need this precedence in Linux or we won't get some of the core developers on board with using OBTs). Other command line options like `-fwrapv` apply to "legacy" types only, so those, for example, don't override OBTs.

And if someone shows up and says "I want OBTs to take precedence", then we can add some "strict" cmdline option for that case, but I think for now this is good as-is.

https://github.com/llvm/llvm-project/pull/148914


More information about the cfe-commits mailing list