[clang] Give better message for unsupported no_sanitize on globals
Previously if you specified no_sanitize("known_sanitizer") on a global you would yield a misleading error "'no_sanitize' attribute only applies to functions and methods", but no_sanitize("unknown") would simply be a warning, "unknown sanitizer 'unknown' ignored". This changes the former to a warning "'no_sanitize' attribute argument not supported for globals: known_sanitizer". Differential Revision: https://reviews.llvm.org/D133117
This commit is contained in:
parent
c911befaec
commit
f6d6e33abc
|
@ -127,6 +127,9 @@ Improvements to Clang's diagnostics
|
||||||
supports both c and c++ language.
|
supports both c and c++ language.
|
||||||
- When diagnosing multi-level pack expansions of mismatched lengths, Clang will
|
- When diagnosing multi-level pack expansions of mismatched lengths, Clang will
|
||||||
now, in most cases, be able to point to the relevant outer parameter.
|
now, in most cases, be able to point to the relevant outer parameter.
|
||||||
|
- no_sanitize("...") on a global variable for known but not relevant sanitizers
|
||||||
|
is now just a warning. It now says that this will be ignored instead of
|
||||||
|
incorrectly saying no_sanitize only applies to functions and methods.
|
||||||
|
|
||||||
Non-comprehensive list of changes in this release
|
Non-comprehensive list of changes in this release
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
|
|
|
@ -4052,6 +4052,9 @@ def warn_transparent_union_attribute_zero_fields : Warning<
|
||||||
def warn_attribute_type_not_supported : Warning<
|
def warn_attribute_type_not_supported : Warning<
|
||||||
"%0 attribute argument not supported: %1">,
|
"%0 attribute argument not supported: %1">,
|
||||||
InGroup<IgnoredAttributes>;
|
InGroup<IgnoredAttributes>;
|
||||||
|
def warn_attribute_type_not_supported_global : Warning<
|
||||||
|
"%0 attribute argument '%1' not supported on a global variable">,
|
||||||
|
InGroup<IgnoredAttributes>;
|
||||||
def warn_attribute_unknown_visibility : Warning<"unknown visibility %0">,
|
def warn_attribute_unknown_visibility : Warning<"unknown visibility %0">,
|
||||||
InGroup<IgnoredAttributes>;
|
InGroup<IgnoredAttributes>;
|
||||||
def warn_attribute_protected_visibility :
|
def warn_attribute_protected_visibility :
|
||||||
|
|
|
@ -7877,8 +7877,8 @@ static void handleNoSanitizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
|
||||||
SanitizerName != "coverage")
|
SanitizerName != "coverage")
|
||||||
S.Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << SanitizerName;
|
S.Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << SanitizerName;
|
||||||
else if (isGlobalVar(D) && !isSanitizerAttributeAllowedOnGlobals(SanitizerName))
|
else if (isGlobalVar(D) && !isSanitizerAttributeAllowedOnGlobals(SanitizerName))
|
||||||
S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)
|
S.Diag(D->getLocation(), diag::warn_attribute_type_not_supported_global)
|
||||||
<< AL << ExpectedFunctionOrMethod;
|
<< AL << SanitizerName;
|
||||||
Sanitizers.push_back(SanitizerName);
|
Sanitizers.push_back(SanitizerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,9 @@ int f1() __attribute__((no_sanitize)); // expected-error{{'no_sanitize' attribut
|
||||||
|
|
||||||
int f2() __attribute__((no_sanitize(1))); // expected-error{{'no_sanitize' attribute requires a string}}
|
int f2() __attribute__((no_sanitize(1))); // expected-error{{'no_sanitize' attribute requires a string}}
|
||||||
|
|
||||||
|
__attribute__((no_sanitize("all"))) int global; // expected-warning{{'no_sanitize' attribute argument 'all' not supported on a global variable}}
|
||||||
|
__attribute__((no_sanitize("unknown"))) int global2; // expected-warning{{unknown sanitizer 'unknown' ignored}}
|
||||||
|
|
||||||
// DUMP-LABEL: FunctionDecl {{.*}} f3
|
// DUMP-LABEL: FunctionDecl {{.*}} f3
|
||||||
// DUMP: NoSanitizeAttr {{.*}} address
|
// DUMP: NoSanitizeAttr {{.*}} address
|
||||||
// PRINT: int f3() __attribute__((no_sanitize("address")))
|
// PRINT: int f3() __attribute__((no_sanitize("address")))
|
||||||
|
|
Loading…
Reference in New Issue