Skip to content

Commit 9a0d5d4

Browse files
committed
[Clang][Sema] Process warnings conditionally
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
1 parent 7b23f41 commit 9a0d5d4

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(diag::warn_format_non_standard_positional_arg, SourceLocation())) {
6595+
EmitFormatDiagnostic(S.PDiag(diag::warn_format_non_standard_positional_arg),
6596+
getLocationOfByte(startPos),
6597+
/*IsStringLocation*/true,
6598+
getSpecifierRange(startPos, posLen));
6599+
}
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(diag::warn_format_invalid_positional_specifier, SourceLocation())) {
6606+
EmitFormatDiagnostic(
6607+
S.PDiag(diag::warn_format_invalid_positional_specifier) << (unsigned)p,
6608+
getLocationOfByte(startSpecifier), /*IsStringLocation*/ true,
6609+
getSpecifierRange(startSpecifier, specifierLen));
6610+
}
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, SourceLocation())) {
6616+
EmitFormatDiagnostic(S.PDiag(diag::warn_format_zero_positional_specifier),
6617+
getLocationOfByte(startPos),
6618+
/*IsStringLocation*/true,
6619+
getSpecifierRange(startPos, posLen));
6620+
}
66156621
}
66166622

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

0 commit comments

Comments
 (0)