diff options
author | Leonard Chan <leonardchan@google.com> | 2018-12-06 01:05:54 +0000 |
---|---|---|
committer | Leonard Chan <leonardchan@google.com> | 2018-12-06 01:05:54 +0000 |
commit | ad7ac964e5cf166ff5bf5042b1393f39a6879b9a (patch) | |
tree | 0e92d91eacdd0b8ee9ebfb451daec605f3c9bdcc /clang/lib/Sema/SemaInit.cpp | |
parent | e13d0992dcd0649bee760d3d606b9353edfd1ebc (diff) | |
download | bcm5719-llvm-ad7ac964e5cf166ff5bf5042b1393f39a6879b9a.tar.gz bcm5719-llvm-ad7ac964e5cf166ff5bf5042b1393f39a6879b9a.zip |
[Sema/Attribute] Check for noderef attribute
This patch adds the noderef attribute in clang and checks for dereferences of
types that have this attribute. This attribute is currently used by sparse and
would like to be ported to clang.
Differential Revision: https://reviews.llvm.org/D49511
llvm-svn: 348442
Diffstat (limited to 'clang/lib/Sema/SemaInit.cpp')
-rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 12946060084..b5c387b169a 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -7687,6 +7687,18 @@ ExprResult InitializationSequence::Perform(Sema &S, case SK_ConversionSequence: case SK_ConversionSequenceNoNarrowing: { + if (const auto *FromPtrType = + CurInit.get()->getType()->getAs<PointerType>()) { + if (const auto *ToPtrType = Step->Type->getAs<PointerType>()) { + if (FromPtrType->getPointeeType()->hasAttr(attr::NoDeref) && + !ToPtrType->getPointeeType()->hasAttr(attr::NoDeref)) { + S.Diag(CurInit.get()->getExprLoc(), + diag::warn_noderef_to_dereferenceable_pointer) + << CurInit.get()->getSourceRange(); + } + } + } + Sema::CheckedConversionKind CCK = Kind.isCStyleCast()? Sema::CCK_CStyleCast : Kind.isFunctionalCast()? Sema::CCK_FunctionalCast @@ -7853,6 +7865,7 @@ ExprResult InitializationSequence::Perform(Sema &S, case SK_CAssignment: { QualType SourceType = CurInit.get()->getType(); + // Save off the initial CurInit in case we need to emit a diagnostic ExprResult InitialCurInit = CurInit; ExprResult Result = CurInit; |