Skip to content

Commit 99dddef

Browse files
authored
[Clang][Sema] Process warnings conditionally (llvm#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 llvm#120462
1 parent b8952d4 commit 99dddef

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6591,27 +6591,33 @@ void CheckFormatHandler::HandleNonStandardConversionSpecifier(
65916591

65926592
void CheckFormatHandler::HandlePosition(const char *startPos,
65936593
unsigned posLen) {
6594-
EmitFormatDiagnostic(S.PDiag(diag::warn_format_non_standard_positional_arg),
6595-
getLocationOfByte(startPos),
6596-
/*IsStringLocation*/true,
6597-
getSpecifierRange(startPos, posLen));
6594+
if (!S.getDiagnostics().isIgnored(
6595+
diag::warn_format_non_standard_positional_arg, SourceLocation()))
6596+
EmitFormatDiagnostic(S.PDiag(diag::warn_format_non_standard_positional_arg),
6597+
getLocationOfByte(startPos),
6598+
/*IsStringLocation*/ true,
6599+
getSpecifierRange(startPos, posLen));
65986600
}
65996601

66006602
void CheckFormatHandler::HandleInvalidPosition(
66016603
const char *startSpecifier, unsigned specifierLen,
66026604
analyze_format_string::PositionContext p) {
6603-
EmitFormatDiagnostic(
6604-
S.PDiag(diag::warn_format_invalid_positional_specifier) << (unsigned)p,
6605-
getLocationOfByte(startSpecifier), /*IsStringLocation*/ true,
6606-
getSpecifierRange(startSpecifier, specifierLen));
6605+
if (!S.getDiagnostics().isIgnored(
6606+
diag::warn_format_invalid_positional_specifier, SourceLocation()))
6607+
EmitFormatDiagnostic(
6608+
S.PDiag(diag::warn_format_invalid_positional_specifier) << (unsigned)p,
6609+
getLocationOfByte(startSpecifier), /*IsStringLocation*/ true,
6610+
getSpecifierRange(startSpecifier, specifierLen));
66076611
}
66086612

66096613
void CheckFormatHandler::HandleZeroPosition(const char *startPos,
66106614
unsigned posLen) {
6611-
EmitFormatDiagnostic(S.PDiag(diag::warn_format_zero_positional_specifier),
6612-
getLocationOfByte(startPos),
6613-
/*IsStringLocation*/true,
6614-
getSpecifierRange(startPos, posLen));
6615+
if (!S.getDiagnostics().isIgnored(diag::warn_format_zero_positional_specifier,
6616+
SourceLocation()))
6617+
EmitFormatDiagnostic(S.PDiag(diag::warn_format_zero_positional_specifier),
6618+
getLocationOfByte(startPos),
6619+
/*IsStringLocation*/ true,
6620+
getSpecifierRange(startPos, posLen));
66156621
}
66166622

66176623
void CheckFormatHandler::HandleNullChar(const char *nullCharacter) {

0 commit comments

Comments
 (0)