[clang] [Clang] Add missing __ob_trap check for sign change (PR #188340)
Justin Stitt via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 1 16:50:51 PDT 2026
================
@@ -1663,6 +1667,20 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType,
llvm::Type *DstTy = ConvertType(DstType);
+ // Determine whether an overflow behavior of 'trap' has been specified for
+ // either the destination or the source types. If so, we can elide sanitizer
+ // capability checks as this overflow behavior kind is also capable of
+ // emitting traps without runtime sanitizer support.
+ // Also skip instrumentation if either source or destination has 'wrap'
+ // behavior - the user has explicitly indicated they accept wrapping
+ // semantics. Use non-canonical types to preserve OBT annotations.
+ const auto *DstOBT = NoncanonicalDstType->getAs<OverflowBehaviorType>();
+ const auto *SrcOBT = NoncanonicalSrcType->getAs<OverflowBehaviorType>();
----------------
JustinStitt wrote:
I decided to use these types
```c
QualType NoncanonicalSrcType = SrcType;
QualType NoncanonicalDstType = DstType;
```
as `SrcType` and `DstType` undergo various assignments and potential transformations in the function prologue I decided to use the types that I knew were OBTs.
Anyways, I'm sure using `SrcType` and `DstType` would have been fine but during development I debug-printed `Noncanonical...` and they had the right shape :)
https://github.com/llvm/llvm-project/pull/188340
More information about the cfe-commits
mailing list