[clang] [clang] -fstrict-enums optimization for by-value parameters (PR #154807)

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 5 13:17:14 PDT 2025


================
@@ -1986,10 +2013,15 @@ bool CodeGenFunction::EmitScalarRangeCheck(llvm::Value *Value, QualType Ty,
       getContext().isTypeIgnoredBySanitizer(SanitizerKind::Enum, Ty))
     return false;
 
-  llvm::APInt Min, End;
-  if (!getRangeForType(*this, Ty, Min, End, /*StrictEnums=*/true, IsBool))
+  const std::optional<llvm::ConstantRange> Range = getRangeForType(
+      Ty, getContext().getTypeSize(Ty), /*ForceStrictEnums=*/true,
+      /*AssumeBooleanRepresentation*/ IsBool);
----------------
keinflue wrote:

Nevermind, I should have checked the blame for the line first:

https://github.com/llvm/llvm-project/commit/4593a46cd92ab88e9651ae75f6c623851c353964:
> On some Apple platforms, the ObjC BOOL type is defined as a signed char.
When performing instrumentation for -fsanitize=bool, we'd like to treat
the range of BOOL like it's always {0, 1}. While we can't change clang's
IRGen for char-backed BOOL's due to ABI compatibility concerns, we can
teach ubsan to catch potential abuses of this type.

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


More information about the cfe-commits mailing list