Skip to content

Commit 85eb725

Browse files
committed
[clang] Fix use-after-scope when diagnosting __attribute__((format_matches))
I don't think this will ever crash, but asan complains about it. SUMMARY: AddressSanitizer: stack-use-after-scope clang/lib/Sema/SemaChecking.cpp:6925:43 in void (anonymous namespace)::CheckFormatHandler::EmitFormatDiagnostic<clang::CharSourceRange>(clang::PartialDiagnostic, clang::SourceLocation, bool, clang::CharSourceRange, llvm::ArrayRef<clang::FixItHint>) While there switch to stable_sort to not give a flipped error message half of the time.
1 parent 148111f commit 85eb725

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7390,10 +7390,11 @@ bool DecomposePrintfHandler::GetSpecifiers(
73907390
const char *Str = Data.data();
73917391
llvm::SmallBitVector BV;
73927392
UncoveredArgHandler UA;
7393+
const Expr *PrintfArgs[] = {FSL->getFormatString()};
73937394
DecomposePrintfHandler H(S, FSL, FSL->getFormatString(), Type, 0, 0, IsObjC,
7394-
Str, Sema::FAPK_Elsewhere, {FSL->getFormatString()},
7395-
0, InFunctionCall, Sema::VariadicDoesNotApply, BV,
7396-
UA, Args);
7395+
Str, Sema::FAPK_Elsewhere, PrintfArgs, 0,
7396+
InFunctionCall, Sema::VariadicDoesNotApply, BV, UA,
7397+
Args);
73977398

73987399
if (!analyze_format_string::ParsePrintfString(
73997400
H, Str, Str + Data.size(), S.getLangOpts(), S.Context.getTargetInfo(),
@@ -7402,7 +7403,7 @@ bool DecomposePrintfHandler::GetSpecifiers(
74027403
if (H.HadError)
74037404
return false;
74047405

7405-
std::sort(
7406+
std::stable_sort(
74067407
Args.begin(), Args.end(),
74077408
[](const EquatableFormatArgument &A, const EquatableFormatArgument &B) {
74087409
return A.getPosition() < B.getPosition();

0 commit comments

Comments
 (0)