]> granicus.if.org Git - clang/commitdiff
Add test case (from PR 8876) for suppressing 'indirection of non-volatile null pointe...
authorTed Kremenek <kremenek@apple.com>
Wed, 23 Feb 2011 02:15:19 +0000 (02:15 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 23 Feb 2011 02:15:19 +0000 (02:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126294 91177308-0d34-0410-b5e6-96231b3b80d8

test/Sema/exprs.c

index e88f7fc08bce2621e6b7ee3c3496d4b3ea505c8c..5917e085ea7c5a526b3b660b225da9606d59db51 100644 (file)
@@ -1,5 +1,23 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
 
+// PR 8876 - don't warn about trivially unreachable null derefs.  Note that
+// we put this here because the reachability analysis only kicks in for
+// suppressing false positives when code has no errors.
+#define PR8876(err_ptr) do {\
+    if (err_ptr) *(int*)(err_ptr) = 1;\
+  } while (0)
+
+#define PR8876_pos(err_ptr) do {\
+    if (!err_ptr) *(int*)(err_ptr) = 1;\
+  } while (0)
+
+
+int test_pr8876() {
+  PR8876(0); // no-warning
+  PR8876_pos(0); // expected-warning{{indirection of non-volatile null pointer will be deleted, not trap}} expected-note{{consider using __builtin_trap() or qualifying pointer with 'volatile'}}
+  return 0;
+}
+
 // PR1966
 _Complex double test1() {
   return __extension__ 1.0if;