diff options
author | Malavika Samak <malavika.samak@gmail.com> | 2024-08-14 10:45:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-14 10:45:43 -0700 |
commit | 6b652f6edaa84a9e4934885f6f12b973efb1b810 (patch) | |
tree | 099a2ab1d18da03cf4c6dc85670540c119418a14 /clang/lib/Sema/AnalysisBasedWarnings.cpp | |
parent | 715c3033af4d38e80c110f0de8e9ddecb5a22fc3 (diff) | |
download | llvm-6b652f6edaa84a9e4934885f6f12b973efb1b810.zip llvm-6b652f6edaa84a9e4934885f6f12b973efb1b810.tar.gz llvm-6b652f6edaa84a9e4934885f6f12b973efb1b810.tar.bz2 |
[attributes][-Wunsafe-buffer-usage] Support adding unsafe_buffer_usage attribute to struct fields (#101585)
Extend the unsafe_buffer_usage attribute, so they can also be added to
struct fields. This will cause the compiler to warn about the unsafe
field at their access sites.
Co-authored-by: MalavikaSamak <malavika2@apple.com>
Diffstat (limited to 'clang/lib/Sema/AnalysisBasedWarnings.cpp')
-rw-r--r-- | clang/lib/Sema/AnalysisBasedWarnings.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp index 0f604c6..e6ce89d 100644 --- a/clang/lib/Sema/AnalysisBasedWarnings.cpp +++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp @@ -2231,6 +2231,7 @@ public: SourceLocation Loc; SourceRange Range; unsigned MsgParam = 0; + NamedDecl *D = nullptr; if (const auto *ASE = dyn_cast<ArraySubscriptExpr>(Operation)) { Loc = ASE->getBase()->getExprLoc(); Range = ASE->getBase()->getSourceRange(); @@ -2261,6 +2262,12 @@ public: // note_unsafe_buffer_operation doesn't have this mode yet. assert(!IsRelatedToDecl && "Not implemented yet!"); MsgParam = 3; + } else if (isa<MemberExpr>(Operation)) { + // note_unsafe_buffer_operation doesn't have this mode yet. + assert(!IsRelatedToDecl && "Not implemented yet!"); + auto ME = dyn_cast<MemberExpr>(Operation); + D = ME->getMemberDecl(); + MsgParam = 5; } else if (const auto *ECE = dyn_cast<ExplicitCastExpr>(Operation)) { QualType destType = ECE->getType(); if (!isa<PointerType>(destType)) @@ -2285,7 +2292,12 @@ public: "Variables blamed for unsafe buffer usage without suggestions!"); S.Diag(Loc, diag::note_unsafe_buffer_operation) << MsgParam << Range; } else { - S.Diag(Loc, diag::warn_unsafe_buffer_operation) << MsgParam << Range; + if (D) { + S.Diag(Loc, diag::warn_unsafe_buffer_operation) + << MsgParam << D << Range; + } else { + S.Diag(Loc, diag::warn_unsafe_buffer_operation) << MsgParam << Range; + } if (SuggestSuggestions) { S.Diag(Loc, diag::note_safe_buffer_usage_suggestions_disabled); } |