]> granicus.if.org Git - clang/commitdiff
[analyzer] [PointerArithChecker] do not warn on indexes into vector types
authorGeorge Karpenkov <ekarpenkov@apple.com>
Wed, 7 Mar 2018 22:20:39 +0000 (22:20 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Wed, 7 Mar 2018 22:20:39 +0000 (22:20 +0000)
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

lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp
test/Analysis/ptr-arith.c

index 4c4a8e3f0d0d199a508fec9f893d997c8f5713d6..63f82b275ba2975bffca39b4c4b4fa260b306138 100644 (file)
@@ -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);
 }
 
index 93cb4ee9a66a1de91c613381ad1eee7100eea18e..804759a32db3472064c64d5704361a7febdb58da 100644 (file)
@@ -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
+}