summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-02-01 15:41:32 +0000
committerSanjay Patel <spatel@rotateright.com>2017-02-01 15:41:32 +0000
commit25f6d710d90c632b8b1b994e6cf5cf0bfc67a9e4 (patch)
tree904b0e7713b7a50195394fc0078409224c7ec48c /llvm/lib/Analysis/ValueTracking.cpp
parent6433d5af6b3ad734532d8defe8064a89e91ebf11 (diff)
downloadbcm5719-llvm-25f6d710d90c632b8b1b994e6cf5cf0bfc67a9e4.tar.gz
bcm5719-llvm-25f6d710d90c632b8b1b994e6cf5cf0bfc67a9e4.zip
[ValueTracking] avoid crashing from bad assumptions (PR31809)
A program may contain llvm.assume info that disagrees with other analysis. This may be caused by UB in the program, so we must not crash because of that. As noted in the code comments: https://llvm.org/bugs/show_bug.cgi?id=31809 ...we can do better, but this at least avoids the assert/crash in the bug report. Differential Revision: https://reviews.llvm.org/D29395 llvm-svn: 293773
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 8ba8d6a5519..6c44b0da45a 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -788,6 +788,23 @@ static void computeKnownBitsFromAssume(const Value *V, APInt &KnownZero,
APInt::getHighBitsSet(BitWidth, RHSKnownZero.countLeadingOnes());
}
}
+
+ // If assumptions conflict with each other or previous known bits, then we
+ // have a logical fallacy. This should only happen when a program has
+ // undefined behavior. We can't assert/crash, so clear out the known bits and
+ // hope for the best.
+
+ // FIXME: Publish a warning/remark that we have encountered UB or the compiler
+ // is broken.
+
+ // FIXME: Implement a stronger version of "I give up" by invalidating/clearing
+ // the assumption cache. This should indicate that the cache is corrupted so
+ // future callers will not waste time repopulating it with faulty assumptions.
+
+ if ((KnownZero & KnownOne) != 0) {
+ KnownZero.clearAllBits();
+ KnownOne.clearAllBits();
+ }
}
// Compute known bits from a shift operator, including those with a
OpenPOWER on IntegriCloud