This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Avoid misleading 'conflicting types' diagnostic with no-prototype decls.
ClosedPublic

Authored by cishida on May 23 2022, 4:47 PM.

Details

Summary

Clang has recently started diagnosing prototype redeclaration errors like rG385e7df33046

This flagged legitimate issues in a codebase but was confusing to resolve because it actually conflicted with a function declaration from a system header and not from the one emitted with "note: ".

This patch updates the error handling to use the canonical declaration's source location instead to avoid misleading errors like the one described.

Diff Detail

Event Timeline

cishida created this revision.May 23 2022, 4:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2022, 4:47 PM
Herald added a subscriber: ributzka. · View Herald Transcript
cishida requested review of this revision.May 23 2022, 4:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2022, 4:47 PM
cishida updated this revision to Diff 431543.May 23 2022, 5:39 PM

Restrict using the canonical decl's source location to only when the prototype was inferred from previously seen decl.

aaron.ballman accepted this revision.May 24 2022, 5:00 AM

LGTM, thank you for catching this!

clang/lib/Sema/SemaDecl.cpp
3914–3918

I don't think it's safe to assign this new value to Old as that object is what we eventually merge the declaration with (so we'll get the decl chain order wrong, I believe).

This revision is now accepted and ready to land.May 24 2022, 5:00 AM
cishida added inline comments.May 24 2022, 6:08 AM
clang/lib/Sema/SemaDecl.cpp
3914–3918

Ah, I hadn't realized we still can merge decls together in a fatal error case.

aaron.ballman added inline comments.May 24 2022, 6:16 AM
clang/lib/Sema/SemaDecl.cpp
3914–3918

Oh shoot, good point, we early return here anyway, so the assignment won't matter. So the code LGTM as-is, thank you!