diff options
author | Dmitry Chestnykh <dm.chestnykh@gmail.com> | 2024-12-23 20:02:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-23 20:02:28 +0300 |
commit | 99dddef340e566e9d303010f1219f7d7d6d37a11 (patch) | |
tree | 985ad04e1ea9b8b5bb22055567c38a296d9e4353 /clang/lib/Sema/SemaChecking.cpp | |
parent | b8952d4b1b0c73bf39d6440ad3166a088ced563f (diff) | |
download | llvm-99dddef340e566e9d303010f1219f7d7d6d37a11.zip llvm-99dddef340e566e9d303010f1219f7d7d6d37a11.tar.gz llvm-99dddef340e566e9d303010f1219f7d7d6d37a11.tar.bz2 |
[Clang][Sema] Process warnings conditionally (#120591)
There are a few functions that emit warnings related to positional
arguments in format strings. These functions use `getLocationOfByte()`
which has O(n) complexity and may lead to silent hang of compilation in
some cases. But such warnings is not widely used and actually don't emit
if user didn't pass the appropriate `-W...` flag, so if the flag is not
passed dont make the call to `EmitFormatDiagnostic` for such diags.
Fix #120462
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index e703a62..ce846ae 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -6591,27 +6591,33 @@ void CheckFormatHandler::HandleNonStandardConversionSpecifier( void CheckFormatHandler::HandlePosition(const char *startPos, unsigned posLen) { - EmitFormatDiagnostic(S.PDiag(diag::warn_format_non_standard_positional_arg), - getLocationOfByte(startPos), - /*IsStringLocation*/true, - getSpecifierRange(startPos, posLen)); + if (!S.getDiagnostics().isIgnored( + diag::warn_format_non_standard_positional_arg, SourceLocation())) + EmitFormatDiagnostic(S.PDiag(diag::warn_format_non_standard_positional_arg), + getLocationOfByte(startPos), + /*IsStringLocation*/ true, + getSpecifierRange(startPos, posLen)); } void CheckFormatHandler::HandleInvalidPosition( const char *startSpecifier, unsigned specifierLen, analyze_format_string::PositionContext p) { - EmitFormatDiagnostic( - S.PDiag(diag::warn_format_invalid_positional_specifier) << (unsigned)p, - getLocationOfByte(startSpecifier), /*IsStringLocation*/ true, - getSpecifierRange(startSpecifier, specifierLen)); + if (!S.getDiagnostics().isIgnored( + diag::warn_format_invalid_positional_specifier, SourceLocation())) + EmitFormatDiagnostic( + S.PDiag(diag::warn_format_invalid_positional_specifier) << (unsigned)p, + getLocationOfByte(startSpecifier), /*IsStringLocation*/ true, + getSpecifierRange(startSpecifier, specifierLen)); } void CheckFormatHandler::HandleZeroPosition(const char *startPos, unsigned posLen) { - EmitFormatDiagnostic(S.PDiag(diag::warn_format_zero_positional_specifier), - getLocationOfByte(startPos), - /*IsStringLocation*/true, - getSpecifierRange(startPos, posLen)); + if (!S.getDiagnostics().isIgnored(diag::warn_format_zero_positional_specifier, + SourceLocation())) + EmitFormatDiagnostic(S.PDiag(diag::warn_format_zero_positional_specifier), + getLocationOfByte(startPos), + /*IsStringLocation*/ true, + getSpecifierRange(startPos, posLen)); } void CheckFormatHandler::HandleNullChar(const char *nullCharacter) { |