From 227fe4bc032cdd791f684a3a8f17826f42cb73a8 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 19 Jun 2015 23:17:55 +0000 Subject: [PATCH] Make -Wnullability-completeness work with -Wsystem-headers. rdar://problem/21134250 llvm-svn: 240187 --- clang/lib/Sema/SemaType.cpp | 7 +++++-- .../nullability-consistency-system.h | 8 ++++++++ clang/test/SemaObjCXX/nullability-consistency.mm | 4 +++- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 clang/test/SemaObjCXX/Inputs/nullability-consistency-system/nullability-consistency-system.h diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index d950d32..b7f5ca0 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -2791,9 +2791,12 @@ static FileID getNullabilityCompletenessCheckFileID(Sema &S, // We don't want to perform completeness checks on the main file or in // system headers. const SrcMgr::FileInfo &fileInfo = sloc.getFile(); - if (fileInfo.getIncludeLoc().isInvalid() || - fileInfo.getFileCharacteristic() != SrcMgr::C_User) + if (fileInfo.getIncludeLoc().isInvalid()) return FileID(); + if (fileInfo.getFileCharacteristic() != SrcMgr::C_User && + S.Diags.getSuppressSystemWarnings()) { + return FileID(); + } return file; } diff --git a/clang/test/SemaObjCXX/Inputs/nullability-consistency-system/nullability-consistency-system.h b/clang/test/SemaObjCXX/Inputs/nullability-consistency-system/nullability-consistency-system.h new file mode 100644 index 0000000..6dbca166 --- /dev/null +++ b/clang/test/SemaObjCXX/Inputs/nullability-consistency-system/nullability-consistency-system.h @@ -0,0 +1,8 @@ +// Simply marking this as "#pragma clang system_header" didn't tickle the bug, rdar://problem/21134250. + +void system1(int *ptr); +#if WARN_IN_SYSTEM_HEADERS +// expected-warning@-2{{pointer is missing a nullability type specifier}} +#endif + +void system2(int * __nonnull); diff --git a/clang/test/SemaObjCXX/nullability-consistency.mm b/clang/test/SemaObjCXX/nullability-consistency.mm index 7497e84..acb972d 100644 --- a/clang/test/SemaObjCXX/nullability-consistency.mm +++ b/clang/test/SemaObjCXX/nullability-consistency.mm @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs %s -verify +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -isystem %S/Inputs/nullability-consistency-system %s -verify +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -isystem %S/Inputs/nullability-consistency-system %s -Wsystem-headers -DWARN_IN_SYSTEM_HEADERS -verify #include "nullability-consistency-1.h" #include "nullability-consistency-3.h" @@ -8,6 +9,7 @@ #include "nullability-consistency-6.h" #include "nullability-consistency-7.h" #include "nullability-consistency-8.h" +#include "nullability-consistency-system.h" void h1(int *ptr) { } // don't warn -- 2.7.4