summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-08-02 21:44:23 +0000
committerChris Lattner <sabre@nondot.org>2011-08-02 21:44:23 +0000
commitf51dae0378eeeb328ef2d39e41df73054937949c (patch)
treeca80a95ac4c2455718b708af76c12b21b1743d35 /clang/lib/Sema
parent366bccefad05b369bb8ba004fd33a92a932a311b (diff)
downloadbcm5719-llvm-f51dae0378eeeb328ef2d39e41df73054937949c.tar.gz
bcm5719-llvm-f51dae0378eeeb328ef2d39e41df73054937949c.zip
disable array bounds overflow warning for cases where an array
has a single element. This disables the warning in cases where there is a clear bug, but this is really rare (who uses arrays with one element?) and it also silences a large class of false positive issues with C89 code that is using tail padding in structs. A better version of this patch would detect when an array is in a tail position in a struct, but at least patch fixes the huge false positives that are hitting postgres and other code. llvm-svn: 136724
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 28085ef6eab..81ae7b3afb0 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3491,7 +3491,9 @@ static void CheckArrayAccess_Check(Sema &S,
else if (size.getBitWidth() < index.getBitWidth())
size = size.sext(index.getBitWidth());
- if (index.slt(size))
+ // Don't warn for valid indexes, or arrays of size 1 (which are often
+ // tail-allocated arrays that are emulating flexible arrays in C89 code).
+ if (index.slt(size) || size == 1)
return;
S.DiagRuntimeBehavior(E->getBase()->getLocStart(), BaseExpr,
OpenPOWER on IntegriCloud