This is an archive of the discontinued LLVM Phabricator instance.

[Clang] [Sema] Ignore invalid multiversion function redeclarations
ClosedPublic

Authored by Izaron on Sep 10 2022, 6:46 AM.

Details

Summary

If a redeclaration of a multiversion function is invalid,
it may be in a broken condition (for example, missing an important
attribute). We shouldn't analyze invalid redeclarations.

Fixes https://github.com/llvm/llvm-project/issues/57343

Diff Detail

Event Timeline

Izaron created this revision.Sep 10 2022, 6:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 10 2022, 6:46 AM
Izaron requested review of this revision.Sep 10 2022, 6:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 10 2022, 6:46 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

How the bug was working on this example:

void foo() {}
[[gnu::target("default")]] void foo() {}
[[gnu::target("avx2")]] void foo() {}
  1. Clang parses the definition of the foo function (line 1)
  2. When parsing the second definition (line 2), Clang will delete TargetAttr in this function
  3. Eventually Clang will mark both foos as invalid.
  4. When parsing the third definition (line 3), in the CheckMultiVersionAdditionalDecl method Clang is trying to compare TargetAttr of the 2nd and the 3rd foo: link.
  5. The CurTA variable is equal to nullptr (because we deleted the attribute in the second step), so there is undefined behaviour.

I suggest to stop looking to invalid declarations.

tahonermann accepted this revision.Sep 13 2022, 7:44 AM

Thank you, this looks good to me!

This revision is now accepted and ready to land.Sep 13 2022, 7:44 AM

makes sense to me, thanks!