diff options
author | Vedant Kumar <vsk@apple.com> | 2017-02-25 00:43:39 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2017-02-25 00:43:39 +0000 |
commit | 42de38076517bc68a2b97c55dcbac7ea8d80b11b (patch) | |
tree | 5b01ee6385f4d8c7d38a64c8b04a87d46e75184b /clang/lib | |
parent | 82ee16beb8fe91b1f78416470faf71922e5efbeb (diff) | |
download | bcm5719-llvm-42de38076517bc68a2b97c55dcbac7ea8d80b11b.tar.gz bcm5719-llvm-42de38076517bc68a2b97c55dcbac7ea8d80b11b.zip |
[ubsan] Detect signed overflow UB in remainder operations
Teach ubsan to diagnose remainder operations which have undefined
behavior due to signed overflow (e.g INT_MIN % -1).
Differential Revision: https://reviews.llvm.org/D29437
llvm-svn: 296214
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CGExprScalar.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index c14e6d12da8..529642cb83e 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -2403,12 +2403,12 @@ Value *ScalarExprEmitter::EmitDiv(const BinOpInfo &Ops) { Value *ScalarExprEmitter::EmitRem(const BinOpInfo &Ops) { // Rem in C can't be a floating point type: C99 6.5.5p2. - if (CGF.SanOpts.has(SanitizerKind::IntegerDivideByZero)) { + if ((CGF.SanOpts.has(SanitizerKind::IntegerDivideByZero) || + CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow)) && + Ops.Ty->isIntegerType()) { CodeGenFunction::SanitizerScope SanScope(&CGF); llvm::Value *Zero = llvm::Constant::getNullValue(ConvertType(Ops.Ty)); - - if (Ops.Ty->isIntegerType()) - EmitUndefinedBehaviorIntegerDivAndRemCheck(Ops, Zero, false); + EmitUndefinedBehaviorIntegerDivAndRemCheck(Ops, Zero, false); } if (Ops.Ty->hasUnsignedIntegerRepresentation()) |