This is an archive of the discontinued LLVM Phabricator instance.

[clang][Sema] Remove dead diagnostic for loss of __unaligned qualifier
ClosedPublic

Authored by hazohelet on Jun 24 2023, 12:19 AM.

Details

Summary

D120936 has made the loss of __unaligned qualifier NOT a bad-conversion.
Because of this, the bad-conversion note about the loss of this qualifier does not take effect.
e.g.

void foo(int *ptr);

void func(const __unaligned int *var) { foo(var); }

BEFORE this patch:

source.cpp:3:41: error: no matching function for call to 'foo'
    3 | void func(const __unaligned int *var) { foo(var); }
      |                                         ^~~
source.cpp:1:6: note: candidate function not viable: 1st argument ('const __unaligned int *') would lose __unaligned qualifier
    1 | void foo(int *ptr);
      |      ^
    2 |
    3 | void func(const __unaligned int *var) { foo(var); }
      |                                             ~~~

AFTER this patch:

source.cpp:3:41: error: no matching function for call to 'foo'
    3 | void func(const __unaligned int *var) { foo(var); }
      |                                         ^~~
source.cpp:1:6: note: candidate function not viable: 1st argument ('const __unaligned int *') would lose const qualifier
    1 | void foo(int *ptr);
      |      ^
    2 |
    3 | void func(const __unaligned int *var) { foo(var); }
      |                                             ~~~

Please note the different mentions of __unaligned and const in notes.

Diff Detail

Event Timeline

hazohelet created this revision.Jun 24 2023, 12:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2023, 12:19 AM
hazohelet requested review of this revision.Jun 24 2023, 12:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2023, 12:19 AM
rnk accepted this revision.Jun 26 2023, 8:51 AM

lgtm

This revision is now accepted and ready to land.Jun 26 2023, 8:51 AM
cjdb added a comment.EditedJun 26 2023, 11:05 AM

Can we get a snippet of code to demonstrate what isn't being diagnosed anymore in the commit message, please?

hazohelet edited the summary of this revision. (Show Details)Jun 27 2023, 4:46 AM
hazohelet edited the summary of this revision. (Show Details)Jun 27 2023, 5:19 AM

Ah looking at the code again, I noticed this change is not NFC. This suppresses inappropriate diagnostics (example added in summary).

hazohelet updated this revision to Diff 535010.Jun 27 2023, 9:06 AM

Added release note and test because this change is not NFC

cjdb accepted this revision.Jun 27 2023, 9:40 AM

Excellent, thanks! LGTM, do you need assistance with merging?

Excellent, thanks! LGTM, do you need assistance with merging?

Thanks for the review. I'll land this myself.

This revision was landed with ongoing or failed builds.Jun 29 2023, 7:02 AM
This revision was automatically updated to reflect the committed changes.

The removal of the early return in this patch causes a crash when parsing the following example:

struct S {
  bool operator==(int) const;
};

void func() {
  S __unaligned s;
  s == 42;
}

See this Compiler Explorer link with a stacktrace: https://godbolt.org/z/n9vscYoYa.

Maybe we want to avoid the call to DiagnoseBadConversion here? I think that we don't want OverloadCandidateSet::BestViableFunction (called in Sema::CreateOverloadedBinOp) to return OR_No_Viable_Function in this case?

The removal of the early return in this patch causes a crash when parsing the following example:

struct S {
  bool operator==(int) const;
};

void func() {
  S __unaligned s;
  s == 42;
}

See this Compiler Explorer link with a stacktrace: https://godbolt.org/z/n9vscYoYa.

Maybe we want to avoid the call to DiagnoseBadConversion here? I think that we don't want OverloadCandidateSet::BestViableFunction (called in Sema::CreateOverloadedBinOp) to return OR_No_Viable_Function in this case?

Thank you for the report and reproducer!
@rnk This reproducer code should be accepted for clang to be aligned with msvc's behavior, correct?

About the fix, there's probably some code that makes a candidate that loses const qualifier invalid, and the __unaligned is likely to be handled in the same place. (I haven't checked the code, so may be off base)

rnk added a comment.Aug 30 2023, 11:29 AM

@rnk This reproducer code should be accepted for clang to be aligned with msvc's behavior, correct?

Yes, I think so.