This is an archive of the discontinued LLVM Phabricator instance.

[Clang][ICE] Corrected invalid invalid parameter index on some attributes with invalid indices applied to varargs functions
Needs ReviewPublic

Authored by samuelmaina on Mar 28 2023, 3:44 AM.

Diff Detail

Event Timeline

samuelmaina created this revision.Mar 28 2023, 3:44 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: arphaman. · View Herald Transcript
samuelmaina requested review of this revision.Mar 28 2023, 3:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2023, 3:44 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Thanks for working on this fix! A few things:

  • Please add a summary description to the patch, and be sure to include a reference to the github issue in the summary.
  • All functional changes (e.g., not typo fixes, fixes to comments, or other NFC changes) need test coverage that demonstrates the issue has been resolved.
  • All functional changes should have a release note in clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDeclAttr.cpp
3764–3767

Did you look into fixing this within checkFunctionOrMethodParameterIndex() instead? That way, all callers of the API get the correct behavior instead of having to find individual attributes to check the logic (I believe there are other attributes with the same underlying problem).

erichkeane added inline comments.Mar 28 2023, 12:51 PM
clang/lib/Sema/SemaDeclAttr.cpp
3764–3767

I would also expect any such issue to diagnose. Also, isn't there an off-by-one error here in the case of variadic args?

tbaeder added inline comments.
clang/lib/Sema/SemaDeclAttr.cpp
3764–3767

handleFormatAttr() has:

if (Idx < 1 || Idx > NumArgs) {
  S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
      << AL << 2 << IdxExpr->getSourceRange();
  return;
}

which is also what I'd expect to see here.

shafik added a subscriber: shafik.Mar 30 2023, 1:56 PM
shafik added inline comments.
clang/lib/Sema/SemaDeclAttr.cpp
3764–3767

I agree w/ @aaron.ballman here we should handle this in checkFunctionOrMethodParameterIndex it is used in many places and AFAICT they all have the same issue, none diagnose this case but paper it over.

There is definitely a bigger clean-up here but we can do a targeted fix now and remove a crash bug and leave the larger fixing for a follow-up.

For the benefit of those who have not seen the bug report: https://github.com/llvm/llvm-project/issues/61635