r326952 - [analyzer] [PointerArithChecker] do not warn on indexes into vector types

George Karpenkov via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 7 14:20:39 PST 2018


Author: george.karpenkov
Date: Wed Mar  7 14:20:39 2018
New Revision: 326952

URL: http://llvm.org/viewvc/llvm-project?rev=326952&view=rev
Log:
[analyzer] [PointerArithChecker] do not warn on indexes into vector types

rdar://35041502

Differential Revision: https://reviews.llvm.org/D44172

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp
    cfe/trunk/test/Analysis/ptr-arith.c

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp?rev=326952&r1=326951&r2=326952&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp Wed Mar  7 14:20:39 2018
@@ -308,6 +308,10 @@ void PointerArithChecker::checkPreStmt(c
   // 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);
 }
 

Modified: cfe/trunk/test/Analysis/ptr-arith.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/ptr-arith.c?rev=326952&r1=326951&r2=326952&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/ptr-arith.c (original)
+++ cfe/trunk/test/Analysis/ptr-arith.c Wed Mar  7 14:20:39 2018
@@ -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
+}




More information about the cfe-commits mailing list