This revision was automatically updated to reflect the committed changes. Closed by commit rGf6d6e33abc2e: [clang] Give better message for unsupported no_sanitize on globals (authored by abrachet). Herald added a project: clang. Herald added a subscriber: cfe-commits.
Changed prior to commit: https://reviews.llvm.org/D133117?vs=457284&id=457428#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D133117/new/ https://reviews.llvm.org/D133117 Files: clang/docs/ReleaseNotes.rst clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Sema/SemaDeclAttr.cpp clang/test/SemaCXX/attr-no-sanitize.cpp Index: clang/test/SemaCXX/attr-no-sanitize.cpp =================================================================== --- clang/test/SemaCXX/attr-no-sanitize.cpp +++ clang/test/SemaCXX/attr-no-sanitize.cpp @@ -6,6 +6,9 @@ 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: NoSanitizeAttr {{.*}} address // PRINT: int f3() __attribute__((no_sanitize("address"))) Index: clang/lib/Sema/SemaDeclAttr.cpp =================================================================== --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -7877,8 +7877,8 @@ SanitizerName != "coverage") S.Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << SanitizerName; else if (isGlobalVar(D) && !isSanitizerAttributeAllowedOnGlobals(SanitizerName)) - S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type) - << AL << ExpectedFunctionOrMethod; + S.Diag(D->getLocation(), diag::warn_attribute_type_not_supported_global) + << AL << SanitizerName; Sanitizers.push_back(SanitizerName); } Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -4052,6 +4052,9 @@ def warn_attribute_type_not_supported : Warning< "%0 attribute argument not supported: %1">, 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">, InGroup<IgnoredAttributes>; def warn_attribute_protected_visibility : Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -127,6 +127,9 @@ supports both c and c++ language. - When diagnosing multi-level pack expansions of mismatched lengths, Clang will 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 -------------------------------------------------
Index: clang/test/SemaCXX/attr-no-sanitize.cpp =================================================================== --- clang/test/SemaCXX/attr-no-sanitize.cpp +++ clang/test/SemaCXX/attr-no-sanitize.cpp @@ -6,6 +6,9 @@ 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: NoSanitizeAttr {{.*}} address // PRINT: int f3() __attribute__((no_sanitize("address"))) Index: clang/lib/Sema/SemaDeclAttr.cpp =================================================================== --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -7877,8 +7877,8 @@ SanitizerName != "coverage") S.Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << SanitizerName; else if (isGlobalVar(D) && !isSanitizerAttributeAllowedOnGlobals(SanitizerName)) - S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type) - << AL << ExpectedFunctionOrMethod; + S.Diag(D->getLocation(), diag::warn_attribute_type_not_supported_global) + << AL << SanitizerName; Sanitizers.push_back(SanitizerName); } Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -4052,6 +4052,9 @@ def warn_attribute_type_not_supported : Warning< "%0 attribute argument not supported: %1">, 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">, InGroup<IgnoredAttributes>; def warn_attribute_protected_visibility : Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -127,6 +127,9 @@ supports both c and c++ language. - When diagnosing multi-level pack expansions of mismatched lengths, Clang will 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 -------------------------------------------------
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits