This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Emit diagnostic when comparing function pointers
ClosedPublic

Authored by tbaeder on Apr 25 2023, 6:48 AM.

Details

Summary
Function pointers can be compared for (in)equality but, but LE, GE, LT,
and GT opcodes should emit an error and abort.

Diff Detail

Event Timeline

tbaeder created this revision.Apr 25 2023, 6:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 6:48 AM
tbaeder requested review of this revision.Apr 25 2023, 6:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 6:48 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaron.ballman added inline comments.Apr 25 2023, 9:14 AM
clang/lib/AST/Interp/Interp.h
589–590

Can we pass in the result of getType() instead of doing this string conversion dance?

tbaeder added inline comments.Apr 25 2023, 10:33 AM
clang/lib/AST/Interp/Interp.h
589–590

Well the diagnostic doesn't print the result of the LHS/RHS:

./array.cpp:202:18: error: constexpr variable 'u13' must be initialized by a constant expression
  202 |   constexpr bool u13 = pf < pg; // ref-warning {{ordered comparison of function pointers}}
      |                  ^     ~~~~~~~
./array.cpp:202:27: note: comparison between '&f' and '&g' has unspecified value
  202 |   constexpr bool u13 = pf < pg; // ref-warning {{ordered comparison of function pointers}}
      |                           ^

I'm not exactly a fan of how the code looks though. I might add a helper function for this later.

aaron.ballman accepted this revision.Apr 25 2023, 12:21 PM

LGTM

clang/lib/AST/Interp/Interp.h
589–590

Ah of course, good point. And yeah, a helper function for this would probably not be a bad idea.

This revision is now accepted and ready to land.Apr 25 2023, 12:21 PM
tbaeder added inline comments.Apr 25 2023, 9:47 PM
clang/lib/AST/Interp/Interp.h
589–590

Do you like the toDiagnosticString() from https://reviews.llvm.org/D149172 better?

aaron.ballman added inline comments.Apr 26 2023, 4:42 AM
clang/lib/AST/Interp/Interp.h
589–590

I do, that's a nice helper. Feel free to either land those changes and use the function here, or land these changes and do a later NFC commit to the helper method.

This revision was landed with ongoing or failed builds.Apr 27 2023, 3:33 AM
This revision was automatically updated to reflect the committed changes.