From: George Karpenkov Date: Wed, 7 Mar 2018 22:20:39 +0000 (+0000) Subject: [analyzer] [PointerArithChecker] do not warn on indexes into vector types X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9062e07a82f72a8bf3f55701a6b1f26186eb74a0;p=clang [analyzer] [PointerArithChecker] do not warn on indexes into vector types rdar://35041502 Differential Revision: https://reviews.llvm.org/D44172 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326952 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp b/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp index 4c4a8e3f0d..63f82b275b 100644 --- a/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp @@ -308,6 +308,10 @@ void PointerArithChecker::checkPreStmt(const ArraySubscriptExpr *SubsExpr, // Indexing with 0 is OK. if (Idx.isZeroConstant()) return; + + // Indexing vector-type expressions is also OK. + if (SubsExpr->getBase()->getType()->isVectorType()) + return; reportPointerArithMisuse(SubsExpr->getBase(), C); } diff --git a/test/Analysis/ptr-arith.c b/test/Analysis/ptr-arith.c index 93cb4ee9a6..804759a32d 100644 --- a/test/Analysis/ptr-arith.c +++ b/test/Analysis/ptr-arith.c @@ -347,3 +347,9 @@ void test_no_crash_on_pointer_to_label() { a[0] = 0; label:; } + +typedef __attribute__((__ext_vector_type__(2))) float simd_float2; +float test_nowarning_on_vector_deref() { + simd_float2 x = {0, 1}; + return x[1]; // no-warning +}