================
@@ -1140,6 +1142,53 @@ static bool ProcessFormatStringLiteral(const Expr
*FormatExpr,
return false;
}
+/// Returns true if:
+/// - The sanitizers are enabled.
+/// - `Decl` does not have attributes preventing sanitizer instrumentation.
+/// - `Decl` or its location is not included in the no-sanitize list.
+static bool isSanitizationEnabledForDecl(ASTContext &Context,
+ const NamedDecl *Decl,
+ SanitizerMask TheSanitizerMask) {
+ // Check that the sanitizer is enabled globally.
+ const SanitizerMask EnabledSanitizerMask =
+ Context.getLangOpts().Sanitize.Mask;
+ if (!(EnabledSanitizerMask & TheSanitizerMask))
+ return false;
+
+ // Check that the source file is not included in the no sanitize list.
+ const auto &NoSanitizeList = Context.getNoSanitizeList();
+ if (NoSanitizeList.containsLocation(TheSanitizerMask,
+ Decl->getSourceRange().getBegin()))
+ return false;
+
+ // Check that the declaration name is not included in the no sanitize list.
+ // NB no-sanitize lists use mangled names.
+ std::unique_ptr<MangleContext> MC(Context.createMangleContext());
+ std::string MangledName;
+ if (MC->shouldMangleDeclName(Decl)) {
+ llvm::raw_string_ostream S = llvm::raw_string_ostream(MangledName);
+ MC->mangleName(Decl, S);
----------------
ojhunt wrote:
I'm really not sure how we can really do anything about these APIs to make this
error prone, absent making the decl responsible for constructing the correct
globaldecl, but for the structor case I'm still not sure that's possible?
https://github.com/llvm/llvm-project/pull/166542
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits